MythTV master
thewb.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: UTF-8 -*-
3# ----------------------
4# Name: thewb.py
5# Python Script
6# Author: R.D. Vaughan
7# Purpose:
8# This python script is intended to perform The WB video lookups for the MythTV Netvision plugin
9# based on information found on the http://www.thewb.com/ website. It
10# follows the MythTV Netvision grabber standards.
11#
12# Command example:
13# See help (-u and -h) options
14#
15# Design:
16# 1) Read the ".../emml/feConfig.xml"
17# 2) Check if the CGI Web server should be used or if the script is run locally
18# 3) Initialize the correct target functions for processing (local or remote)
19# 4) Process the search or treeview request and display to stdout
20#
21#
22# License:Creative Commons GNU GPL v2
23# (http://creativecommons.org/licenses/GPL/2.0/)
24#-------------------------------------
25__title__ ="The WB";
26__mashup_title__ = "thewb"
27__author__="R.D. Vaughan"
28__version__="0.13"
29# 0.1.0 Initial development
30# 0.11 Change to support xml version information display
31# 0.12 Added the "command" tag to the xml version information display
32# 0.13 Converted to new common_api.py library
33
34__usage_examples__ ='''
35(Option Help)
36> ./thewb.py -h
37Usage: ./thewb.py -hduvlST [parameters] <search text>
38Version: v0.11 Author: R.D.Vaughan
39
40For details on the MythTV Netvision plugin see the wiki page at:
41http://www.mythtv.org/wiki/MythNetvision
42
43Options:
44 -h, --help show this help message and exit
45 -d, --debug Show debugging info (URLs, raw XML ... etc, info
46 varies per grabber)
47 -u, --usage Display examples for executing the script
48 -v, --version Display grabber name and supported options
49 -l LANGUAGE, --language=LANGUAGE
50 Select data that matches the specified language fall
51 back to English if nothing found (e.g. 'es' EspaƱol,
52 'de' Deutsch ... etc). Not all sites or grabbers
53 support this option.
54 -p PAGE NUMBER, --pagenumber=PAGE NUMBER
55 Display specific page of the search results. Default
56 is page 1. Page number is ignored with the Tree View
57 option (-T).
58 -S, --search Search for videos
59 -T, --treeview Display a Tree View of a sites videos
60
61> ./thewb.py -v
62<grabber>
63 <name>The WB</name>
64 <author>R.D.Vaughan</author>
65 <thumbnail>thewb.png</thumbnail>
66 <type>video</type>
67 <description>Watch full episodes of your favorite shows on The WB.com, like Friends, The O.C., Veronica Mars, Pushing Daisies, Smallville, Buffy The Vampire Slayer, One Tree Hill and Gilmore Girls.</description>
68 <version>v0.11</version>
69 <search>true</search>
70 <tree>true</tree>
71</grabber>
72
73> ./thewb.py -S "Firefly"
74
75> ./thewb.py -T
76'''
77__search_max_page_items__ = 20
78__tree_max_page_items__ = 20
79
80import sys, os
81import io
82
83class OutStreamEncoder(object):
84 """Wraps a stream with an encoder"""
85 def __init__(self, outstream, encoding=None):
86 self.out = outstream
87 if not encoding:
88 self.encoding = sys.getfilesystemencoding()
89 else:
90 self.encoding = encoding
91
92 def write(self, obj):
93 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
94 if isinstance(obj, str):
95 obj = obj.encode(self.encoding)
96 self.out.buffer.write(obj)
97
98 def __getattr__(self, attr):
99 """Delegate everything but write to the stream"""
100 return getattr(self.out, attr)
101
102if isinstance(sys.stdout, io.TextIOWrapper):
103 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
104 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
105
106
107# Used for debugging
108#import nv_python_libs.common.common_api
109try:
110 '''Import the common python class
111 '''
112 import nv_python_libs.common.common_api as common_api
113except Exception as e:
114 sys.stderr.write('''
115The subdirectory "nv_python_libs/common" containing the modules common_api.py and
116common_exceptions.py (v0.1.3 or greater),
117They should have been included with the distribution of MythNetvision
118Error(%s)
119''' % e)
120 sys.exit(1)
121if common_api.__version__ < '0.1.3':
122 sys.stderr.write("\n! Error: Your current installed common_api.py version is (%s)\nYou must at least have version (0.1.3) or higher.\n" % target.__version__)
123 sys.exit(1)
124
125# Used for debugging
126#import nv_python_libs.thewb.thewb_api as target
127try:
128 '''Import the python thewb support classes
129 '''
130 import nv_python_libs.thewb.thewb_api as target
131except Exception as e:
132 sys.stderr.write('''
133The subdirectory "nv_python_libs/thewb" containing the modules thewb_api and
134thewb_exceptions.py (v0.1.0 or greater),
135They should have been included with the distribution of thewb.py.
136Error(%s)
137''' % e)
138 sys.exit(1)
139if target.__version__ < '0.1.0':
140 sys.stderr.write("\n! Error: Your current installed thewb_api.py version is (%s)\nYou must at least have version (0.1.0) or higher.\n" % target.__version__)
141 sys.exit(1)
142
143# Verify that the main process modules are installed and accessible
144try:
145 import nv_python_libs.mainProcess as process
146except Exception as e:
147 sys.stderr.write('''
148The python script "nv_python_libs/mainProcess.py" must be present.
149Error(%s)
150''' % e)
151 sys.exit(1)
152
153if process.__version__ < '0.2.0':
154 sys.stderr.write("\n! Error: Your current installed mainProcess.py version is (%s)\nYou must at least have version (0.2.0) or higher.\n" % process.__version__)
155 sys.exit(1)
156
157if __name__ == '__main__':
158 # No api key is required
159 apikey = ""
160 # Set the base processing directory that the grabber is installed
161 target.baseProcessingDir = os.path.dirname( os.path.realpath( __file__ ))
162 # Make sure the target functions have an instance of the common routines
163 target.common = common_api.Common()
164 main = process.mainProcess(target, apikey, )
165 main.grabberInfo = {}
166 main.grabberInfo['enabled'] = True
167 main.grabberInfo['title'] = __title__
168 main.grabberInfo['command'] = 'thewb.py'
169 main.grabberInfo['mashup_title'] = __mashup_title__
170 main.grabberInfo['author'] = __author__
171 main.grabberInfo['thumbnail'] = 'thewb.png'
172 main.grabberInfo['type'] = ['video', ]
173 main.grabberInfo['desc'] = "Watch full episodes of your favorite shows on The WB.com, like Friends, The O.C., Veronica Mars, Pushing Daisies, Smallville, Buffy The Vampire Slayer, One Tree Hill and Gilmore Girls."
174 main.grabberInfo['version'] = __version__
175 main.grabberInfo['search'] = True
176 main.grabberInfo['tree'] = True
177 main.grabberInfo['html'] = False
178 main.grabberInfo['usage'] = __usage_examples__
179 main.grabberInfo['SmaxPage'] = __search_max_page_items__
180 main.grabberInfo['TmaxPage'] = __tree_max_page_items__
181 main.main()
def __init__(self, outstream, encoding=None)
Definition: thewb.py:85
def __getattr__(self, attr)
Definition: thewb.py:98
def write(self, obj)
Definition: thewb.py:92