15 __title__ =
"linuxAction_api - XPath and XSLT functions for the www.jupiterbroadcasting.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, 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, unicode):
62 """Delegate everything but write to the stream""" 63 return getattr(self.
out, attr)
68 from StringIO
import StringIO
69 from lxml
import etree
71 sys.stderr.write(
u'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
79 for digit
in etree.LIBXML_VERSION:
80 version+=str(digit)+
'.' 81 version = version[:-1]
84 ! Error - The installed version of the "lxml" python library "libxml" version is too old. 85 At least "libxml" version 2.7.2 must be installed. Your version is (%s). 91 """Functions specific extending XPath 94 self.
functList = [
'linuxActionLinkGeneration',
'linuxActionTitleSeEp',
'linuxActioncheckIfDBItem', ]
97 re.compile(
u'''^.+?[Ss](?P<seasno>[0-9]+)\\e(?P<epno>[0-9]+).*$''', re.UNICODE),
99 re.compile(
u'''^.+?Season\\ (?P<seasno>[0-9]+)\\ Episode\\ (?P<epno>[0-9]+).*$''', re.UNICODE),
102 'atom':
"http://www.w3.org/2005/Atom",
103 'atom10':
"http://www.w3.org/2005/Atom",
104 'media':
"http://search.yahoo.com/mrss/",
105 'itunes':
"http://www.itunes.com/dtds/podcast-1.0.dtd",
106 'xhtml':
"http://www.w3.org/1999/xhtml",
107 'mythtv':
"http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format",
108 'feedburner':
"http://rssnamespace.org/feedburner/ext/1.0",
109 'fb':
"http://www.facebook.com/2008/fbml",
112 [etree.XPath(
'//object/@id', namespaces=self.
namespaces ),
None],
114 self.
FullScreen =
u'http://linuxAction.com/show/popupPlayer?video_id=%s&quality=high&offset=0' 125 '''Generate a link for the video. 126 Call example: 'mnvXpath:linuxActionLinkGeneration(string(link))' 131 tmpHandle = urllib.urlopen(webURL)
132 tmpHTML =
unicode(tmpHandle.read(),
'utf-8')
134 except Exception, errmsg:
135 sys.stderr.write(
u"Error reading url(%s) error(%s)\n" % (webURL, errmsg))
138 findText =
u"<embed src=" 139 lenText = len(findText)
140 posText = tmpHTML.find(findText)
143 tmpHTML = tmpHTML[posText+lenText+1:]
145 tmpLink = tmpHTML[:tmpHTML.find(
'"')]
146 if tmpLink.find(
'www.youtube.com') != -1:
147 return u'%s&autoplay=1' % tmpLink
149 return u'%s?autostart=1' % tmpLink
153 '''Parse the download link and extract an episode number 154 Call example: 'mnvXpath:linuxActionTitleSeEp(title)' 155 return the a massaged title element and an episode element in an array 158 index = title.find(
'|')
160 title = title[:index].strip()
161 index = title.find(
'The Linux Action Show')
163 title = title[:index].strip()
164 index = title.find(
'! Season')
166 title = title[:index-1].strip()
167 title = common.htmlToString(
'dummy', title)
173 match = self.
s_e_Regex[index].match(arg[0])
175 (seasonNumber, episodeNumber) = match.groups()
176 seasonNumber =
u'%s' % int(seasonNumber)
177 episodeNumber =
u'%s' % int(episodeNumber)
178 elementArray.append(etree.XML(
u"<title>%s</title>" % (
u'S%02dE%02d: %s' % (int(seasonNumber), int(episodeNumber), title))))
181 elementArray.append(etree.XML(
u"<title>%s</title>" % title ))
183 tmpElement = etree.Element(
'{http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format}season')
184 tmpElement.text = seasonNumber
185 elementArray.append(tmpElement)
187 tmpElement = etree.Element(
'{http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format}episode')
188 tmpElement.text = episodeNumber
189 elementArray.append(tmpElement)
194 '''Use a unique key value pairing to find out if the 'internetcontentarticles' table already 195 has a matching item. This is done to save accessing the Internet when not required. 196 Call example: 'mnvXpath:linuxActioncheckIfDBItem(title, author)' 197 return True if a match was found 198 return False if a match was not found 201 return common.checkIfDBItem(
'dummy', {
'feedtitle':
'Technology',
'title': titleElement.text,
'author': arg[1]})
def linuxActioncheckIfDBItem(self, context, *arg)
long long copy(QFile &dst, QFile &src, uint block_size)
Copies src file to dst file.
def linuxActionTitleSeEp(self, context, *arg)
def __init__(self, outstream, encoding=None)
def __getattr__(self, attr)
def linuxActionLinkGeneration(self, context, *arg)
Start of XPath extension functions.