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.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 = [
'linuxActionLinkGeneration',
'linuxActionTitleSeEp',
'linuxActioncheckIfDBItem', ]
95 re.compile(
'''^.+?[Ss](?P<seasno>[0-9]+)\\e(?P<epno>[0-9]+).*$''', re.UNICODE),
97 re.compile(
'''^.+?Season\\ (?P<seasno>[0-9]+)\\ Episode\\ (?P<epno>[0-9]+).*$''', re.UNICODE),
100 'atom':
"http://www.w3.org/2005/Atom",
101 'atom10':
"http://www.w3.org/2005/Atom",
102 'media':
"http://search.yahoo.com/mrss/",
103 'itunes':
"http://www.itunes.com/dtds/podcast-1.0.dtd",
104 'xhtml':
"http://www.w3.org/1999/xhtml",
105 'mythtv':
"http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format",
106 'feedburner':
"http://rssnamespace.org/feedburner/ext/1.0",
107 'fb':
"http://www.facebook.com/2008/fbml",
110 [etree.XPath(
'//object/@id', namespaces=self.
namespaces ),
None],
112 self.
FullScreen =
'http://linuxAction.com/show/popupPlayer?video_id=%s&quality=high&offset=0'
123 '''Generate a link for the video.
124 Call example: 'mnvXpath:linuxActionLinkGeneration(string(link))'
129 tmpHandle = urllib.request.urlopen(webURL)
130 tmpHTML = str(tmpHandle.read(),
'utf-8')
132 except Exception
as errmsg:
133 sys.stderr.write(
"Error reading url(%s) error(%s)\n" % (webURL, errmsg))
136 findText =
"<embed src="
137 lenText = len(findText)
138 posText = tmpHTML.find(findText)
141 tmpHTML = tmpHTML[posText+lenText+1:]
143 tmpLink = tmpHTML[:tmpHTML.find(
'"')]
144 if tmpLink.find(
'www.youtube.com') != -1:
145 return '%s&autoplay=1' % tmpLink
147 return '%s?autostart=1' % tmpLink
151 '''Parse the download link and extract an episode number
152 Call example: 'mnvXpath:linuxActionTitleSeEp(title)'
153 return the a massaged title element and an episode element in an array
156 index = title.find(
'|')
158 title = title[:index].strip()
159 index = title.find(
'The Linux Action Show')
161 title = title[:index].strip()
162 index = title.find(
'! Season')
164 title = title[:index-1].strip()
165 title = common.htmlToString(
'dummy', title)
171 match = self.
s_e_Regex[index].match(arg[0])
173 (seasonNumber, episodeNumber) = match.groups()
174 seasonNumber =
'%s' % int(seasonNumber)
175 episodeNumber =
'%s' % int(episodeNumber)
176 elementArray.append(etree.XML(
"<title>%s</title>" % (
'S%02dE%02d: %s' % (int(seasonNumber), int(episodeNumber), title))))
179 elementArray.append(etree.XML(
"<title>%s</title>" % title ))
181 tmpElement = etree.Element(
'{http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format}season')
182 tmpElement.text = seasonNumber
183 elementArray.append(tmpElement)
185 tmpElement = etree.Element(
'{http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format}episode')
186 tmpElement.text = episodeNumber
187 elementArray.append(tmpElement)
192 '''Use a unique key value pairing to find out if the 'internetcontentarticles' table already
193 has a matching item. This is done to save accessing the Internet when not required.
194 Call example: 'mnvXpath:linuxActioncheckIfDBItem(title, author)'
195 return True if a match was found
196 return False if a match was not found
199 return common.checkIfDBItem(
'dummy', {
'feedtitle':
'Technology',
'title': titleElement.text,
'author': arg[1]})