Ticket #3585: get_cast.py

File get_cast.py, 1.7 KB (added by maverik044, 19 years ago)

Script to fill cast info for existing videos. Need to have python and python-imdbpy installed. See imdbpw.py script for more info.

Line 
1#!/usr/bin/python
2# -*- coding: utf8 -*-
3"""
4This Python script is intended to fill the cast in the database
5This script is intended to be used by people that have an existing
6big video collection already in the database and want to fill
7in the cast field. Perform movie data lookups using the
8imdbpy.py script.
9
10Written by William Stewart 2007
11Based on find_meta.py by Pekka JÀÀskelÀinen
12
13"""
14
15import sys
16import optparse
17import re
18import os
19import glob
20import fileinput
21import shlex
22import socket
23import urllib
24import distutils.file_util
25import imdbpy
26
27try:
28 from MythTV import MythDB, MythVideo
29 mythdb = MythDB()
30 mythvideo = MythVideo()
31except:
32 mythdb = None
33 mythvideo = None
34
35from stat import *
36
37verbose=False
38
39def print_verbose(string):
40 global verbose
41 if verbose:
42 print string
43 return
44
45def 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
84if __name__ == '__main__':
85 main()