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