15 __title__ =
"bliptvXSL_api - XPath and XSLT functions for the Blip.tv 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
31 __xpathClassList__ = [
'xpathFunctions', ]
35 __xsltExtentionList__ = []
37 import os, sys, re, time, datetime, shutil, urllib.request, urllib.parse, urllib.error, string
38 from 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)
64 if isinstance(sys.stdout, io.TextIOWrapper):
69 from io
import StringIO
70 from lxml
import etree
71 except Exception
as e:
72 sys.stderr.write(
'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
80 for digit
in etree.LIBXML_VERSION:
81 version+=str(digit)+
'.'
82 version = version[:-1]
85 ! Error - The installed version of the "lxml" python library "libxml" version is too old.
86 At least "libxml" version 2.7.2 must be installed. Your version is (%s).
92 """Functions specific extending XPath
95 self.
functList = [
'bliptvFlvLinkGeneration',
'bliptvDownloadLinkGeneration',
'bliptvEpisode',
'bliptvIsCustomHTML', ]
97 re.compile(
'''TERRA\\ (?P<episodeno>[0-9]+).*$''', re.UNICODE),
100 'xsi':
"http://www.w3.org/2001/XMLSchema-instance",
101 'media':
"http://search.yahoo.com/mrss/",
102 'xhtml':
"http://www.w3.org/1999/xhtml",
103 'atm':
"http://www.w3.org/2005/Atom",
104 'mythtv':
"http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format",
105 'itunes':
"http://www.itunes.com/dtds/podcast-1.0.dtd",
106 'creativeCommons':
"http://backend.userland.com/creativeCommonsRssModule",
107 'geo':
"http://www.w3.org/2003/01/geo/wgs84_pos#",
108 'blip':
"http://blip.tv/dtd/blip/1.0",
109 'wfw':
"http://wellformedweb.org/CommentAPI/",
110 'amp':
"http://www.adobe.com/amp/1.0",
111 'dcterms':
"http://purl.org/dc/terms",
112 'gm':
"http://www.google.com/schemas/gm/1.1",
113 'mediaad':
"http://blip.tv/dtd/mediaad/1.0",
116 self.
m4vFilter = etree.XPath(
".//media:content[@type='video/mp4' or @type='video/quicktime' or @type='video/x-m4v']", namespaces=self.
namespaces)
129 '''Generate a link for the Blip.tv site.
130 Call example: 'mnvXpath:bliptvFlvLinkGeneration(.)'
135 flvFileLink = flvFile[0].attrib[
'url']
136 return '%s%s' % (common.linkWebPage(
'dummy',
'bliptv'), flvFileLink.replace(
'.flv',
'').replace(
'http://blip.tv/file/get/',
''))
142 '''Generate a download link for the Blip.tv site.
143 Call example: 'mnvXpath:bliptvDownloadLinkGeneration(.)'
144 return an array of one download link element
146 downloadLink = etree.XML(
'<link></link>')
150 downloadLink.attrib[
'url'] = m4vFile[0].attrib[
'url']
151 if m4vFile[0].attrib.get(
'width'):
152 downloadLink.attrib[
'width'] = m4vFile[0].attrib[
'width']
153 if m4vFile[0].attrib.get(
'height'):
154 downloadLink.attrib[
'height'] = m4vFile[0].attrib[
'height']
155 if m4vFile[0].attrib.get(
'fileSize'):
156 downloadLink.attrib[
'length'] = m4vFile[0].attrib[
'fileSize']
160 return [downloadLink]
162 downloadLink.attrib[
'url'] = flvFile[0].attrib[
'url']
163 if flvFile[0].attrib.get(
'width'):
164 downloadLink.attrib[
'width'] = flvFile[0].attrib[
'width']
165 if flvFile[0].attrib.get(
'height'):
166 downloadLink.attrib[
'height'] = flvFile[0].attrib[
'height']
167 if flvFile[0].attrib.get(
'fileSize'):
168 downloadLink.attrib[
'length'] = flvFile[0].attrib[
'fileSize']
172 return [downloadLink]
174 downloadLink.attrib[
'url'] = self.
linkFilter(arg[0])[0]
178 return [downloadLink]
182 '''Parse the title string and extract an episode number
183 Call example: 'mnvXpath:bliptvEpisode(./title/text())'
190 episodeNumber = match.groups()
192 return etree.XML(
'<episode>%s</episode>' % episodeNumber)
196 '''Parse the item element and deternmine if there is a flv file
197 Call example: 'mnvXpath:bliptvIsCustomHTML(.)'
198 return True is there is a '.flv' file
199 return False if there is no .flv' file