15 __title__ =
"revision3XSL_api - XPath and XSLT functions for the www.revision3L.com RSS/HTML"
16 __author__=
"R.D. Vaughan"
18 This python script is intended to perform a variety of utility functions
19 for the conversion of data to the MNV standard RSS output format.
20 See this link for the specifications:
21 http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format
29 __xpathClassList__ = [
'xpathFunctions', ]
33 __xsltExtentionList__ = []
35 import os, sys, re, time, datetime, shutil, urllib.request, urllib.parse, urllib.error, string
36 from copy
import deepcopy
40 """Wraps a stream with an encoder"""
49 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
50 if isinstance(obj, str):
53 self.
out.buffer.write(obj)
58 """Delegate everything but write to the stream"""
59 return getattr(self.
out, attr)
61 if isinstance(sys.stdout, io.TextIOWrapper):
66 from io
import StringIO
67 from lxml
import etree
68 except Exception
as e:
69 sys.stderr.write(
'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
77 for digit
in etree.LIBXML_VERSION:
78 version+=str(digit)+
'.'
79 version = version[:-1]
82 ! Error - The installed version of the "lxml" python library "libxml" version is too old.
83 At least "libxml" version 2.7.2 must be installed. Your version is (%s).
89 """Functions specific extending XPath
92 self.
functList = [
'revision3LinkGeneration',
'revision3Episode',
'revision3checkIfDBItem', ]
94 re.compile(
'''^.+?\\-\\-(?P<episodeno>[0-9]+)\\-\\-.*$''', re.UNICODE),
97 'atom':
"http://www.w3.org/2005/Atom",
98 'media':
"http://search.yahoo.com/mrss/",
99 'itunes':
"http://www.itunes.com/dtds/podcast-1.0.dtd",
100 'xhtml':
"http://www.w3.org/1999/xhtml",
101 'mythtv':
"http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format",
102 'cnettv':
"http://cnettv.com/mrss/",
103 'creativeCommons':
"http://backend.userland.com/creativeCommonsRssModule",
104 'amp':
"http://www.adobe.com/amp/1.0",
105 'content':
"http://purl.org/rss/1.0/modules/content/",
108 [etree.XPath(
'//object/@id', namespaces=self.
namespaces ),
None],
110 self.
FullScreen =
'http://revision3.com/show/popupPlayer?video_id=%s&quality=high&offset=0'
121 '''Generate a link for the video.
122 Call example: 'mnvXpath:revision3LinkGeneration(string(link))'
128 except Exception
as errmsg:
129 sys.stderr.write(
"Error reading url(%s) error(%s)\n" % (webURL, errmsg))
139 videocode = match.groups()
142 return self.
FullScreen % (mediaId[0].strip().replace(
'player-',
''))
148 '''Parse the download link and extract an episode number
149 Call example: 'mnvXpath:revision3Episode(.)'
150 return the a massaged title element and an episode element in an array
152 title = arg[0][0].
find(
'title').text
153 link = arg[0][0].
find(
'enclosure').attrib[
'url']
159 episodeNumber = int(match.groups()[0])
161 titleElement = etree.XML(
"<xml></xml>")
162 etree.SubElement(titleElement,
"title").text =
'Ep%03d: %s' % (episodeNumber, title)
164 etree.SubElement(titleElement,
"episode").text =
'%s' % episodeNumber
165 return [titleElement]
169 '''Use a unique key value pairing to find out if the 'internetcontentarticles' table already
170 has a matching item. This is done to save accessing the Internet when not required.
171 Call example: 'mnvXpath:revision3checkIfDBItem(.)'
172 return True if a match was found
173 return False if a match was not found
175 return common.checkIfDBItem(
'dummy', {
'title': self.
revision3Episode(context, arg)[0].
find(
'title').text, })