MythTV master
tmdb3.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: UTF-8 -*-
3# ----------------------
4# Name: tmdb3.py
5# Python Script
6# Author: Peter Bennett
7# Purpose:
8# Frontend for the tmdb3 lookup.py script that now supports both Movies and
9# TV shows. This frontend supports Movies
10# Command example:
11# See help (-h) options
12#
13# Code that was originally here is now in tmdb3/lookup.py
14#
15# License:Creative Commons GNU GPL v2
16# (http://creativecommons.org/licenses/GPL/2.0/)
17# -------------------------------------
18#
19__title__ = "TheMovieDB.org for TV V3"
20__author__ = "Peter Bennett"
21
22from optparse import OptionParser
23import sys
24import signal
25
27 err = 0
28 try:
29 import MythTV
30 except:
31 err = 1
32 print ("Failed to import MythTV bindings. Check your `configure` output "
33 "to make sure installation was not disabled due to external "
34 "dependencies")
35 try:
36 import MythTV.tmdb3
37 except:
38 err = 1
39 print ("Failed to import PyTMDB3 library. This should have been included "
40 "with the python MythTV bindings.")
41 try:
42 import lxml
43 except:
44 err = 1
45 print ("Failed to import python lxml library.")
46
47 if not err:
48 print ("Everything appears in order.")
49 return err
50
51def main(showType, command):
52
53 parser = OptionParser()
54
55 parser.add_option('-v', "--version", action="store_true", default=False,
56 dest="version", help="Display version and author")
57 parser.add_option('-t', "--test", action="store_true", default=False,
58 dest="test", help="Perform self-test for dependencies.")
59 parser.add_option('-M', "--movielist", "--list", action="store_true", default=False,
60 dest="movielist",
61 help="Get Movies. Needs search key.")
62 parser.add_option('-D', "--moviedata", "--data", action="store_true", default=False,
63 dest="moviedata", help="Get Movie data. " \
64 "Needs inetref. ")
65 parser.add_option('-C', "--collection", action="store_true", default=False,
66 dest="collectiondata", help="Get Collection data.")
67 parser.add_option('-l', "--language", metavar="LANGUAGE", default='en',
68 dest="language", help="Specify language for filtering.")
69 parser.add_option('-a', "--area", metavar="COUNTRY", default=None,
70 dest="country", help="Specify country for custom data.")
71 parser.add_option('--debug', action="store_true", default=False,
72 dest="debug", help=("Disable caching and enable raw "
73 "data output."))
74
75 opts, args = parser.parse_args()
76
77 from MythTV.tmdb3.lookup import timeouthandler
78 signal.signal(signal.SIGALRM, timeouthandler)
79 signal.alarm(180)
80
81 if opts.test:
82 return performSelfTest()
83
84 from MythTV.tmdb3 import set_key, set_cache, set_locale
85 set_key('c27cb71cff5bd76e1a7a009380562c62')
86
87 if opts.debug:
88 import MythTV.tmdb3
89 MythTV.tmdb3.request.DEBUG = True
90 set_cache(engine='null')
91 else:
92 import os
93 confdir = os.environ.get('MYTHCONFDIR', '')
94 if (not confdir) or (confdir == '/'):
95 confdir = os.environ.get('HOME', '')
96 if (not confdir) or (confdir == '/'):
97 print ("Unable to find MythTV directory for metadata cache.")
98 return 1
99 confdir = os.path.join(confdir, '.mythtv')
100 cachedir = os.path.join(confdir, 'cache')
101 if not os.path.exists(cachedir):
102 os.makedirs(cachedir)
103 cachepath = os.path.join(cachedir, 'pytmdb3.cache')
104 set_cache(engine='file', filename=cachepath)
105
106 if opts.language:
107 set_locale(language=opts.language, fallthrough=True)
108 if opts.country:
109 set_locale(country=opts.country, fallthrough=True)
110
111 if (not opts.version):
112 if (len(args) < 1) or (args[0] == ''):
113 sys.stdout.write('ERROR: tmdb3.py requires at least one non-empty argument.\n')
114 return 1
115
116 from MythTV.tmdb3.lookup import buildVersion, buildMovieList, \
117 buildSingle, buildCollection, print_etree
118 try:
119 xml = None
120 if opts.version:
121 xml = buildVersion(showType, command)
122
123 elif opts.movielist:
124 xml = buildMovieList(args[0], opts)
125
126 elif opts.moviedata:
127 xml = buildSingle(args[0], opts)
128
129 elif opts.collectiondata:
130 xml = buildCollection(args[0], opts)
131
132 # if a number is returned, it is an error code return
133 if isinstance(xml,int):
134 return xml
135
136 if xml:
137 print_etree(xml)
138 else:
139 return 1
140
141 except RuntimeError as exc:
142 sys.stdout.write('ERROR: ' + str(exc) + ' exception')
143 import traceback
144 traceback.print_exc()
145 return 1
146
147 return 0
148
149if __name__ == '__main__':
150 sys.exit(main("movie",'tmdb3.py'))
def buildVersion()
Definition: culrcwrap.py:101
def main(showType, command)
Definition: tmdb3.py:51
def performSelfTest()
Definition: tmdb3.py:26
def print_etree(etostr)
Definition: ttvdb4.py:25
def buildCollection(tvinetref, opts)
Definition: tvmaze.py:522
def buildSingle(args, opts, tvmaze_episode_id=None)
Definition: tvmaze.py:365