Okay, okay! I got a little bit too eager and rewrote the video playing section of the plugin. Instead of using WebVideoItem with its lovely croppiness and un-killable pop-up ad, it now does the fancy behind the scenes thing and pulls down the .flv file directly. Everything loads much smoother and cleaner now. To save ourselves from patch-on-patch action, here is the entire init.py file:
[codebox]from PMS import Plugin, Log, XML, HTTP
from PMS.MediaXML import *
from PMS.Shorthand import _L, _R, _E, _D
from FrameworkAdditions import *
import md5, urllib, urllib2
################################################################################
####################
PLUGIN_PREFIX = “/video/escapist”
ES_URL = “http://www.escapistmagazine.com”
ES_THUMB_URL = “http://static.escapistmagazine.com/media/global/images/castfire/mini/%s.jpg”
CACHE_INTERVAL = 3600
USER_AGENT = ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8’
################################################################################
####################
class MenuContainer(MediaContainer):
def init(self, art=“art-default.png”, viewGroup=“Menu”, title1=None, title2=None, noHistory=False, replaceParent=False):
if title1 is None:
title1 = _L(“theescapist”)
MediaContainer.init(self, art, viewGroup, title1, title2, noHistory, replaceParent)
################################################################################
####################
def Start():
Plugin.AddRequestHandler(PLUGIN_PREFIX, HandleRequest, _L(“theescapist”), “icon-default.png”, “art-default.png”)
Plugin.AddViewGroup(“Menu”, viewMode=“InfoList”, contentType=“items”)
################################################################################
####################
def HandleRequest(pathNouns, count):
if count == 0:
dir = MenuContainer()
shows = XMLElementFromURL("%s/videos" % ES_URL, True, CACHE_INTERVAL).xpath("//div[@class=‘gallery_latest site_panel’]")
for show in shows:
gallery_title = show.xpath(".//div[@class=‘gallery_title’]/a")[0]
key = gallery_title.get(‘href’).split(’/’)[5]
thumb = show.xpath(".//div[@class=‘gallery_title_card’]/a/img/@src")[0]
if not Plugin.Dict.has_key("%s-thumb" % key):
Plugin.Dict["%s-thumb" % key] = thumb
dir.AppendItem(DirectoryItem(key, gallery_title.text, thumb=thumb, summary=show.xpath(".//div[@class=‘gallery_description’]/text()")[0]))
return dir.ToXML()
elif count == 1:
page = XMLElementFromURL("%s/videos/view/%s" % (ES_URL, pathNouns[0].replace("$", “?”)), True, CACHE_INTERVAL)
dir = MenuContainer(title2=page.xpath("//title")[0].text.replace(“The Escapist : Video Galleries : “, “”))
for episode in page.xpath(”//div[@class=‘video_box_content’]/div[@class=‘filmstrip_video’]”):
url = “%s%s” % (ES_URL, episode.xpath(".//a/@href")[0])
item = WebVideoItem(_E(url), episode.xpath(".//div[@class=‘title’]/text()")[0], “”, “”, )
item = DirectoryItem(_E(url), episode.xpath(".//div[@class='title']/text()")[0], thumb=ES_THUMB_URL % url.split('/')[6].split('-')[0])<br />
item.SetAttr("subtitle", episode.xpath(".//div[@class='date']/text()")[0].replace("Date: ", ""))<br />
dir.AppendItem(item)<br />
next = page.xpath("//a[@class='next_page']")<br />
if len(next) > 0:<br />
thumb = ""<br />
if Plugin.Dict.has_key("%s-thumb" % pathNouns[0].split("$")[0]):<br />
thumb = Plugin.Dict["%s-thumb" % pathNouns[0].split("$")[0]]<br />
Log.Add(thumb)<br />
dir.AppendItem(DirectoryItem("%s/%s" % (PLUGIN_PREFIX, next[0].get("href")[13:].replace("?", "$")), _L("nextpage"), thumb=thumb))<br />
return dir.ToXML()<br />
elif count == 2:
page = XMLElementFromURL(_D(pathNouns[1]), True, CACHE_INTERVAL)
# Get the video key number (like 624)
key = _D(pathNouns[1]).split('/')[-1].split('-')[0]
# Connect to Themis Media and get the flv url
THEMIS_POST = {
'version': 'ThemisMedia1.2',
'format': md5.md5("Video %s Hash" % key).hexdigest() }
req = urllib2.Request('http://www.themis-group.com/global/castfire/m4v/%s' % key, urllib.urlencode(THEMIS_POST))
req.add_header('User-Agent', USER_AGENT)
FLV_URL = urllib.unquote(urllib2.urlopen(req).read()).split('=')[-1]
Log.Add("Opening video file: " + FLV_URL)
title = page.xpath("//div[@class='headline']")[0].text
subtitle = "By %s" % page.xpath("//div[@class='byline']/a")[0].text
summary = page.xpath("//div[@id='video_details']/p")[0].text
item = VideoItem(FLV_URL, title, summary, "", "")
item.SetAttr("subtitle", subtitle)
dir = MenuContainer(title2=title[:title.find(":")-1])
dir.AppendItem(item)
return dir.ToXML()
################################################################################
####################
[/codebox]