15 __title__ =
"cinemarv_api - XPath and XSLT functions for the CinemaRV.com grabber"
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 = [
'cinemarvLinkGeneration',
'cinemarvIsCustomHTML',
'cinemarvCheckIfDBItem', ]
106 '''Generate a link for the CinemaRV.com site. A read of the item's web page is required to
107 extract the flash video id.
108 Call example: 'mnvXpath:cinemarvLinkGeneration(string(link))'
113 if self.
persistence.has_key(
'cinemarvLinkGeneration'):
114 if self.
persistence[
'cinemarvLinkGeneration']
is not None:
115 returnValue = self.
persistence[
'cinemarvLinkGeneration']
119 self.
persistence[
'cinemarvLinkGenerationVideoID'] = etree.XPath(
'//object[@id="flashObj"]//param[@name="flashVars"]/@value', namespaces=common.namespaces)
120 self.
persistence[
'cinemarvLinkGenerationParser'] = etree.HTMLParser()
123 webPageElement = etree.parse(webURL, self.
persistence[
'cinemarvLinkGenerationParser'])
124 except Exception, errmsg:
125 sys.stderr.write(
u'!Warning: The web page URL(%s) could not be read, error(%s)\n' % (webURL, errmsg))
127 if webPageElement
is None:
128 self.
persistence[
'cinemarvLinkGeneration'] = webURL
131 tmpVideoID = self.
persistence[
'cinemarvLinkGenerationVideoID'](webPageElement)
132 if not len(tmpVideoID):
133 self.
persistence[
'cinemarvLinkGeneration'] = webURL
135 index = tmpVideoID[0].
find(
'&')
137 self.
persistence[
'cinemarvLinkGeneration'] = webURL
139 videocode = tmpVideoID[0][:index].replace(
u'videoId=',
u'')
140 self.
persistence[
'cinemarvLinkGeneration'] = common.linkWebPage(
u'dummycontext',
'cinemarv')+videocode
145 '''Check if the link is for a custom HTML
146 Example call: mnvXpath:cinemarvIsCustomHTML(('dummy'))
147 return True if the link does not starts with "http://"
148 return False if the link starts with "http://"
150 if self.
persistence[
'cinemarvLinkGeneration']
is None:
153 if self.
persistence[
'cinemarvLinkGeneration'].startswith(
u'http://'):
160 '''Use a unique key value pairing to find out if the 'internetcontentarticles' table already
161 has a matching item. This is done to save accessing the Internet when not required.
162 Call example: 'mnvXpath:cinemarvCheckIfDBItem(.)'
163 return True if a match was found
164 return False if a match was not found
166 return common.checkIfDBItem(
'dummy', {
'feedtitle':
'Movie Trailers',
'title': arg[0].replace(
'Trailer',
u'').strip(),
'author': arg[1],
'description': arg[2]})