15__title__ =
"skyAtNight_api - XPath and XSLT functions for the BBC Sky at Night magazine 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
29__xpathClassList__ = [
'xpathFunctions', ]
33__xsltExtentionList__ = []
35import os, sys, re, time, datetime, shutil,
urllib.request, urllib.parse, urllib.error, string
36from 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)
61if isinstance(sys.stdout, io.TextIOWrapper):
66 from io
import StringIO
67 from lxml
import etree
69 sys.stderr.write(
'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
74 """Functions specific extending XPath
87 '''Parse the guid element and extract an episode number
88 Call example: 'mnvXpath:skyAtNightTitleEp(string(guid))'
89 return the a massaged title element
and an episode element
in an array
91 searchText = 'BBC_SAN'
93 episodeNumber = title.replace(searchText,
'').strip()
95 episodeNumber = int(episodeNumber)
99 mythtvNamespace =
"http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format"
100 mythtv =
"{%s}" % mythtvNamespace
101 NSMAP = {
'mythtv' : mythtvNamespace}
102 elementTmp = etree.Element(mythtv +
"mythtv", nsmap=NSMAP)
103 if not episodeNumber
is None:
104 etree.SubElement(elementTmp,
"title").text =
"EP%02d" % episodeNumber
105 etree.SubElement(elementTmp, mythtv +
"episode").text =
"%s" % episodeNumber
107 etree.SubElement(elementTmp,
"title").text = title
def __getattr__(self, attr)
def __init__(self, outstream, encoding=None)
def skyAtNightTitleEp(self, context, *arg)
Start of XPath extension functions.