15 __title__ =
"pbsXSL_api - XPath and XSLT functions for the PBS 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 = [
'pbsTitleSeriesEpisodeLink',
'pbsDuration',
'pbsDownloadlink']
97 re.compile(
u'''^.+?Season\\ (?P<seasno>[0-9]+)\\:\\ Episode\\ (?P<epno>[0-9]+).*$''', re.UNICODE),
99 re.compile(
u'''^.+?Season\\ (?P<seasno>[0-9]+)\\,\\ Episode\\ (?P<epno>[0-9]+).*$''', re.UNICODE),
101 re.compile(
u'''^.+?Episode\\ (?P<epno>[0-9]+).*$''', re.UNICODE),
104 'media':
u"http://search.yahoo.com/mrss/",
105 'xhtml':
u"http://www.w3.org/1999/xhtml",
106 'mythtv':
"http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format",
107 'mediaad':
"http://PBS/dtd/mediaad/1.0",
119 '''Generate a link for the PBS site. 120 Call example: 'mnvXpath:pbsTitleSeriesEpisodeLink(normalize-space(./title),normalize-space(./link))/*' 121 return the title, link and season and episode number elements if any were in the title 127 tmpVideoCode = tmpLink.replace(
u'http://video.pbs.org/video/',
u'')[:-1]
128 self.
persistence[tmpLink] = common.linkWebPage(
'dummy',
'pbs')
137 (seasonNumber, episodeNumber) = match.groups()
140 episodeNumber = match.groups()[0]
144 index = tmpTitle.rfind(
'|')
146 tmpTitle = tmpTitle[index+1:].strip()
147 if seasonNumber
and episodeNumber:
148 tmpTitle =
u'S%02dE%02d: %s' % (int(seasonNumber), int(episodeNumber), tmpTitle)
150 index = tmpTitle.find(
':')
152 tmpTitle = tmpTitle[index+1:].strip()
153 tmpTitle =
u'Ep%02d: %s' % (int(episodeNumber), tmpTitle)
154 self.
persistence[tmpLink] = common.linkWebPage(
'dummy',
'pbs').replace(
u'TITLE', urllib.quote(tmpTitle)).replace(
u'VIDEOCODE', tmpVideoCode)
157 elementTmp = etree.XML(
'<xml></xml>')
158 etree.SubElement(elementTmp,
"title").text = tmpTitle
160 etree.SubElement(elementTmp,
"season").text =
u"%s" % int(seasonNumber)
162 etree.SubElement(elementTmp,
"episode").text =
u"%s" % int(episodeNumber)
163 etree.SubElement(elementTmp,
"link").text = self.
persistence[tmpLink]
168 '''Return the video duration in seconds 169 Call example: 'mnvXpath:pbsDuration(normalize-string(./dd/p[@class="info"]/span[@class="time"]))' 170 return the video duration 178 '''Return a previously created download link 179 Call example: 'mnvXpath:pbsDownloadlink(normalize-space(./link))'
def pbsDownloadlink(self, context, *arg)
def pbsTitleSeriesEpisodeLink(self, context, *arg)
Start of XPath extension functions.
def __init__(self, outstream, encoding=None)
def __getattr__(self, attr)
def pbsDuration(self, context, *arg)