15__title__ =
"linuxAction_api - XPath and XSLT functions for the www.jupiterbroadcasting.com RSS/HTML"
16__author__=
"R.D. Vaughan"
18This python script is intended to perform a variety of utility functions
19for the conversion of data to the MNV standard RSS output format.
20See this link for the specifications:
21http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format
29__xpathClassList__ = [
'xpathFunctions', ]
33__xsltExtentionList__ = []
35import os, sys, re, time, datetime, shutil,
urllib.request, urllib.parse, urllib.error, string
36from 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)
61if isinstance(sys.stdout, io.TextIOWrapper):
66 from io
import StringIO
67 from lxml
import etree
69 sys.stderr.write(
'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
74 """Functions specific extending XPath
77 self.
functList = [
'linuxActionLinkGeneration',
'linuxActionTitleSeEp',
'linuxActioncheckIfDBItem', ]
80 re.compile(
'''^.+?[Ss](?P<seasno>[0-9]+)\\e(?P<epno>[0-9]+).*$''', re.UNICODE),
82 re.compile(
'''^.+?Season\\ (?P<seasno>[0-9]+)\\ Episode\\ (?P<epno>[0-9]+).*$''', re.UNICODE),
85 'atom':
"http://www.w3.org/2005/Atom",
86 'atom10':
"http://www.w3.org/2005/Atom",
87 'media':
"http://search.yahoo.com/mrss/",
88 'itunes':
"http://www.itunes.com/dtds/podcast-1.0.dtd",
89 'xhtml':
"http://www.w3.org/1999/xhtml",
90 'mythtv':
"http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format",
91 'feedburner':
"http://rssnamespace.org/feedburner/ext/1.0",
92 'fb':
"http://www.facebook.com/2008/fbml",
95 [etree.XPath(
'//object/@id', namespaces=self.
namespaces ),
None],
97 self.
FullScreen =
'http://linuxAction.com/show/popupPlayer?video_id=%s&quality=high&offset=0'
108 '''Generate a link for the video.
109 Call example: 'mnvXpath:linuxActionLinkGeneration(string(link))'
114 tmpHandle = urllib.request.urlopen(webURL)
115 tmpHTML = str(tmpHandle.read(),
'utf-8')
117 except Exception
as errmsg:
118 sys.stderr.write(
"Error reading url(%s) error(%s)\n" % (webURL, errmsg))
121 findText =
"<embed src="
122 lenText = len(findText)
123 posText = tmpHTML.find(findText)
126 tmpHTML = tmpHTML[posText+lenText+1:]
128 tmpLink = tmpHTML[:tmpHTML.find(
'"')]
129 if tmpLink.find(
'www.youtube.com') != -1:
130 return '%s&autoplay=1' % tmpLink
132 return '%s?autostart=1' % tmpLink
136 '''Parse the download link and extract an episode number
137 Call example: 'mnvXpath:linuxActionTitleSeEp(title)'
138 return the a massaged title element
and an episode element
in an array
141 index = title.find('|')
143 title = title[:index].strip()
144 index = title.find(
'The Linux Action Show')
146 title = title[:index].strip()
147 index = title.find(
'! Season')
149 title = title[:index-1].strip()
150 title = common.htmlToString(
'dummy', title)
156 match = self.
s_e_Regex[index].match(arg[0])
158 (seasonNumber, episodeNumber) = match.groups()
159 seasonNumber =
'%s' % int(seasonNumber)
160 episodeNumber =
'%s' % int(episodeNumber)
161 elementArray.append(etree.XML(
"<title>%s</title>" % (
'S%02dE%02d: %s' % (int(seasonNumber), int(episodeNumber), title))))
164 elementArray.append(etree.XML(
"<title>%s</title>" % title ))
166 tmpElement = etree.Element(
'{http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format}season')
167 tmpElement.text = seasonNumber
168 elementArray.append(tmpElement)
170 tmpElement = etree.Element(
'{http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format}episode')
171 tmpElement.text = episodeNumber
172 elementArray.append(tmpElement)
177 '''Use a unique key value pairing to find out if the 'internetcontentarticles' table already
178 has a matching item. This is done to save accessing the Internet when
not required.
179 Call example:
'mnvXpath:linuxActioncheckIfDBItem(title, author)'
180 return True if a match was found
181 return False if a match was
not found
184 return common.checkIfDBItem(
'dummy', {
'feedtitle':
'Technology',
'title': titleElement.text,
'author': arg[1]})
def __init__(self, outstream, encoding=None)
def __getattr__(self, attr)
def linuxActionTitleSeEp(self, context, *arg)
def linuxActioncheckIfDBItem(self, context, *arg)
def linuxActionLinkGeneration(self, context, *arg)
Start of XPath extension functions.
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size=0)
Copies src file to dst file.