15__title__ =
"bliptvXSL_api - XPath and XSLT functions for the Blip.tv 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
31__xpathClassList__ = [
'xpathFunctions', ]
35__xsltExtentionList__ = []
37import os, sys, re, time, datetime, shutil,
urllib.request, urllib.parse, urllib.error, string
38from copy
import deepcopy
42 """Wraps a stream with an encoder"""
51 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
52 if isinstance(obj, str):
55 self.
out.buffer.write(obj)
61 """Delegate everything but write to the stream"""
62 return getattr(self.
out, attr)
64if isinstance(sys.stdout, io.TextIOWrapper):
69 from io
import StringIO
70 from lxml
import etree
72 sys.stderr.write(
'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
77 """Functions specific extending XPath
80 self.
functList = [
'bliptvFlvLinkGeneration',
'bliptvDownloadLinkGeneration',
'bliptvEpisode',
'bliptvIsCustomHTML', ]
82 re.compile(
'''TERRA\\ (?P<episodeno>[0-9]+).*$''', re.UNICODE),
85 'xsi':
"http://www.w3.org/2001/XMLSchema-instance",
86 'media':
"http://search.yahoo.com/mrss/",
87 'xhtml':
"http://www.w3.org/1999/xhtml",
88 'atm':
"http://www.w3.org/2005/Atom",
89 'mythtv':
"http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format",
90 'itunes':
"http://www.itunes.com/dtds/podcast-1.0.dtd",
91 'creativeCommons':
"http://backend.userland.com/creativeCommonsRssModule",
92 'geo':
"http://www.w3.org/2003/01/geo/wgs84_pos#",
93 'blip':
"http://blip.tv/dtd/blip/1.0",
94 'wfw':
"http://wellformedweb.org/CommentAPI/",
95 'amp':
"http://www.adobe.com/amp/1.0",
96 'dcterms':
"http://purl.org/dc/terms",
97 'gm':
"http://www.google.com/schemas/gm/1.1",
98 'mediaad':
"http://blip.tv/dtd/mediaad/1.0",
101 self.
m4vFilter = etree.XPath(
".//media:content[@type='video/mp4' or @type='video/quicktime' or @type='video/x-m4v']", namespaces=self.
namespaces)
114 '''Generate a link for the Blip.tv site.
115 Call example: 'mnvXpath:bliptvFlvLinkGeneration(.)'
120 flvFileLink = flvFile[0].attrib[
'url']
121 return '%s%s' % (common.linkWebPage(
'dummy',
'bliptv'), flvFileLink.replace(
'.flv',
'').replace(
'http://blip.tv/file/get/',
''))
127 '''Generate a download link for the Blip.tv site.
128 Call example: 'mnvXpath:bliptvDownloadLinkGeneration(.)'
129 return an array of one download link element
131 downloadLink = etree.XML('<link></link>')
135 downloadLink.attrib[
'url'] = m4vFile[0].attrib[
'url']
136 if m4vFile[0].attrib.get(
'width'):
137 downloadLink.attrib[
'width'] = m4vFile[0].attrib[
'width']
138 if m4vFile[0].attrib.get(
'height'):
139 downloadLink.attrib[
'height'] = m4vFile[0].attrib[
'height']
140 if m4vFile[0].attrib.get(
'fileSize'):
141 downloadLink.attrib[
'length'] = m4vFile[0].attrib[
'fileSize']
145 return [downloadLink]
147 downloadLink.attrib[
'url'] = flvFile[0].attrib[
'url']
148 if flvFile[0].attrib.get(
'width'):
149 downloadLink.attrib[
'width'] = flvFile[0].attrib[
'width']
150 if flvFile[0].attrib.get(
'height'):
151 downloadLink.attrib[
'height'] = flvFile[0].attrib[
'height']
152 if flvFile[0].attrib.get(
'fileSize'):
153 downloadLink.attrib[
'length'] = flvFile[0].attrib[
'fileSize']
157 return [downloadLink]
159 downloadLink.attrib[
'url'] = self.
linkFilter(arg[0])[0]
163 return [downloadLink]
167 '''Parse the title string and extract an episode number
168 Call example: 'mnvXpath:bliptvEpisode(./title/text())'
175 episodeNumber = match.groups()
177 return etree.XML(
'<episode>%s</episode>' % episodeNumber)
181 '''Parse the item element and deternmine if there is a flv file
182 Call example: 'mnvXpath:bliptvIsCustomHTML(.)'
183 return True is there
is a
'.flv' file
184 return False if there
is no .flv
' file
def __getattr__(self, attr)
def __init__(self, outstream, encoding=None)
def bliptvEpisode(self, context, arg)
def bliptvIsCustomHTML(self, context, arg)
def bliptvFlvLinkGeneration(self, context, arg)
Start of XPath extension functions.
def bliptvDownloadLinkGeneration(self, context, arg)