17 __title__ =
"TheMovieDB.org for TV V3"
18 __author__ =
"Peter Bennett"
20 from optparse
import OptionParser
30 print (
"Failed to import MythTV bindings. Check your `configure` output "
31 "to make sure installation was not disabled due to external "
37 print (
"Failed to import PyTMDB3 library. This should have been included "
38 "with the python MythTV bindings.")
43 print (
"Failed to import python lxml library.")
46 print (
"Everything appears in order.")
49 def main(showType, command):
51 parser = OptionParser()
53 parser.add_option(
'-v',
"--version", action=
"store_true", default=
False,
54 dest=
"version", help=
"Display version and author")
55 parser.add_option(
'-t',
"--test", action=
"store_true", default=
False,
56 dest=
"test", help=
"Perform self-test for dependencies.")
57 parser.add_option(
'-M',
"--movielist",
"--list", action=
"store_true", default=
False,
59 help=
"Get Television Series List. Needs search key.")
60 parser.add_option(
'-D',
"--moviedata",
"--data", action=
"store_true", default=
False,
61 dest=
"moviedata", help=
"Get TV Episode data. " \
62 "Needs inetref, season and episode. ")
63 parser.add_option(
'-C',
"--collection", action=
"store_true", default=
False,
64 dest=
"collectiondata",
65 help=
'Get a television Series (collection) "series" level information')
66 parser.add_option(
"-N",
"--numbers", action=
"store_true", default=
False, dest=
"numbers",
67 help=
"Get television Season and Episode numbers. " \
68 "Needs title and subtitle or inetref and subtitle.")
69 parser.add_option(
'-l',
"--language", metavar=
"LANGUAGE", default=
u'en',
70 dest=
"language", help=
"Specify language for filtering.")
71 parser.add_option(
'-a',
"--area", metavar=
"COUNTRY", default=
None,
72 dest=
"country", help=
"Specify country for custom data.")
73 parser.add_option(
'--debug', action=
"store_true", default=
False,
74 dest=
"debug", help=(
"Disable caching and enable raw "
77 opts, args = parser.parse_args()
79 from MythTV.tmdb3.lookup
import timeouthandler
80 signal.signal(signal.SIGALRM, timeouthandler)
86 from MythTV.tmdb3
import set_key, set_cache, set_locale
87 set_key(
'c27cb71cff5bd76e1a7a009380562c62')
91 MythTV.tmdb3.request.DEBUG =
True
92 set_cache(engine=
'null')
95 confdir = os.environ.get(
'MYTHCONFDIR',
'')
96 if (
not confdir)
or (confdir ==
'/'):
97 confdir = os.environ.get(
'HOME',
'')
98 if (
not confdir)
or (confdir ==
'/'):
99 print (
"Unable to find MythTV directory for metadata cache.")
101 confdir = os.path.join(confdir,
'.mythtv')
102 cachedir = os.path.join(confdir,
'cache')
103 if not os.path.exists(cachedir):
104 os.makedirs(cachedir)
105 cachepath = os.path.join(cachedir,
'pytmdb3.cache')
106 set_cache(engine=
'file', filename=cachepath)
109 set_locale(language=opts.language, fallthrough=
True)
111 set_locale(country=opts.country, fallthrough=
True)
113 if (
not opts.version):
114 if (len(args) < 1)
or (args[0] ==
''):
115 sys.stdout.write(
'ERROR: tmdb3.py requires at least one non-empty argument.\n')
118 if opts.moviedata
and len(args) < 3:
119 sys.stdout.write(
'ERROR: tmdb3.py -D requires three non-empty arguments.\n')
122 from MythTV.tmdb3.lookup
import buildVersion, buildTVList, \
123 buildEpisode, buildTVSeries, print_etree
130 xml = buildTVList(args[0], opts)
133 xml = buildEpisode(args[0:2], opts)
136 xml = buildEpisode(args[0:3], opts)
138 elif opts.collectiondata:
139 xml = buildTVSeries(args[0], opts)
142 if isinstance(xml,int):
150 except RuntimeError
as exc:
151 sys.stdout.write(
'ERROR: ' + str(exc) +
' exception')
153 traceback.print_exc()
158 if __name__ ==
'__main__':
159 sys.exit(
main(
"television",
'tmdb3tv.py'))