| 1 | #!/usr/bin/python
|
|---|
| 2 | # -*- coding: utf8 -*-
|
|---|
| 3 | """
|
|---|
| 4 | This Python script is intended to fill the cast in the database
|
|---|
| 5 | This script is intended to be used by people that have an existing
|
|---|
| 6 | big video collection already in the database and want to fill
|
|---|
| 7 | in the cast field. Perform movie data lookups using the
|
|---|
| 8 | imdbpy.py script.
|
|---|
| 9 |
|
|---|
| 10 | Written by William Stewart 2007
|
|---|
| 11 | Based on find_meta.py by Pekka JÀÀskelÀinen
|
|---|
| 12 |
|
|---|
| 13 | """
|
|---|
| 14 |
|
|---|
| 15 | import sys
|
|---|
| 16 | import optparse
|
|---|
| 17 | import re
|
|---|
| 18 | import os
|
|---|
| 19 | import glob
|
|---|
| 20 | import fileinput
|
|---|
| 21 | import shlex
|
|---|
| 22 | import socket
|
|---|
| 23 | import urllib
|
|---|
| 24 | import distutils.file_util
|
|---|
| 25 | import imdbpy
|
|---|
| 26 |
|
|---|
| 27 | try:
|
|---|
| 28 | from MythTV import MythDB, MythVideo
|
|---|
| 29 | mythdb = MythDB()
|
|---|
| 30 | mythvideo = MythVideo()
|
|---|
| 31 | except:
|
|---|
| 32 | mythdb = None
|
|---|
| 33 | mythvideo = None
|
|---|
| 34 |
|
|---|
| 35 | from stat import *
|
|---|
| 36 |
|
|---|
| 37 | verbose=False
|
|---|
| 38 |
|
|---|
| 39 | def print_verbose(string):
|
|---|
| 40 | global verbose
|
|---|
| 41 | if verbose:
|
|---|
| 42 | print string
|
|---|
| 43 | return
|
|---|
| 44 |
|
|---|
| 45 | def main():
|
|---|
| 46 | global verbose
|
|---|
| 47 |
|
|---|
| 48 | usage = "usage: %prog [options]"
|
|---|
| 49 |
|
|---|
| 50 | p = optparse.OptionParser(usage=usage)
|
|---|
| 51 | p.add_option('--version', '-v', action="store_true", default=False,
|
|---|
| 52 | help="Display 1-line describing name, version, author etc.")
|
|---|
| 53 |
|
|---|
| 54 | options, arguments = p.parse_args()
|
|---|
| 55 |
|
|---|
| 56 | if options.version:
|
|---|
| 57 | print "MythVideo Cast Metadata Finder - William Stewart 2007"
|
|---|
| 58 | sys.exit(0)
|
|---|
| 59 |
|
|---|
| 60 | if not mythdb:
|
|---|
| 61 | print "Error can not access the mythtv database"
|
|---|
| 62 | sys.exit(1)
|
|---|
| 63 |
|
|---|
| 64 | c = mythdb.cursor()
|
|---|
| 65 | c.execute("""
|
|---|
| 66 | SELECT intid, filename, inetref
|
|---|
| 67 | FROM videometadata""")
|
|---|
| 68 |
|
|---|
| 69 | row = c.fetchone()
|
|---|
| 70 | while row is not None:
|
|---|
| 71 | intid = row[0]
|
|---|
| 72 | filename = row[1]
|
|---|
| 73 | imdb_id = row[2]
|
|---|
| 74 | if imdb_id != '00000000':
|
|---|
| 75 | meta = imdbpy.fetch_metadata(imdb_id)
|
|---|
| 76 | cast = meta.cast
|
|---|
| 77 | print "Found cast data for %s (%s)" % (filename, imdb_id)
|
|---|
| 78 | mythvideo.setMetadata({'cast': cast}, intid)
|
|---|
| 79 | row = c.fetchone()
|
|---|
| 80 | c.close()
|
|---|
| 81 |
|
|---|
| 82 | sys.exit(0)
|
|---|
| 83 |
|
|---|
| 84 | if __name__ == '__main__':
|
|---|
| 85 | main()
|
|---|