15 __title__ =
"hubbleCast_api - XPath and XSLT functions for the HubbleCast 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):
52 self.out.write(obj.encode(self.
encoding))
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
96 'atom':
"http://www.w3.org/2005/Atom",
97 'atom10':
"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 'feedburner':
"http://rssnamespace.org/feedburner/ext/1.0",
103 'amp':
"http://www.adobe.com/amp/1.0",
114 '''Generate a link for the video.
115 Call example: 'mnvXpath:hubbleCastLinkGeneration(string(guid))'
119 index = guidURL.find(
'.m4v')
121 index2 = guidURL.rfind(
'/')
122 return u'%s%s' % (common.linkWebPage(
'dummy',
'hubble'), guidURL[index2+1:index])
123 elif guidURL[len(guidURL)-1] ==
'/':
124 index2 = guidURL[:-1].rfind(
'/')
125 return u'%s%s' % (common.linkWebPage(
'dummy',
'hubble'), guidURL[index2+1:-1])