Patch to The Escapist Plug-In

Looks like The Escapist Magazine switched around their site a bit, and it broke the plugin for it. Since I can’t seem to find where the code is actually hosted, here’s a unified diff for it. Hope I didn’t screw things up terribly!



[codebox]— /Users/april/Library/Application Support/Plex Media Server/Plug-ins/The Escapist.bundle/Contents/Code/init.py 2009-04-13 22:10:37.000000000 -0500

+++ /tmp/init.py 2009-04-13 22:20:46.000000000 -0500

@@ -32,11 +32,11 @@



if count == 0:

dir = MenuContainer()

  • shows = XMLElementFromURL("%s/videos" % ES_URL, True, CACHE_INTERVAL).xpath("//div[@class=‘video_box_content’]")
  • 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/div[@class='gallery_title']/a")[0]<br />
    
  •  gallery_title = show.xpath(".//div[@class='gallery_title']/a")[0]<br />
     key = gallery_title.get('href').split('/')[5]<br />
    
  •  thumb = show.xpath(".//div/div[@class='gallery_title_card']/a/img/@src")[0]<br />
    
  •  thumb = show.xpath(".//div[@class='gallery_title_card']/a/img/@src")[0]<br />
     if not Plugin.Dict.has_key("%s-thumb" % key):<br />
       Plugin.Dict["%s-thumb" % key] = thumb<br />
     dir.AppendItem(DirectoryItem(key, gallery_title.text, thumb=thumb, summary=show.xpath(".//div[@class='gallery_description']/text()")[0]))<br />
    

[/codebox]

Nice to see someone from Minneapolis here, I lived there for seven (long, cold-in-the-winter) years :slight_smile:



I live just on the other side of the river in St. Paul! :)

As is my legal obligation as a Minneapolis resident, I have to say: Saint Paul... ewww! Otherwise, it's good to have local folks around. :)

And elan, if you do live in Maui now, I think you probably made the right choice in moving away. *jealous*

I lived in both St Paul (downtown) and Minneapolis (Uptown and St Louis Park).



The only reason I was in MN so long was for a woman, whom I eventually married, so I like to think of it as having been worthwhile :slight_smile:

Yep, it’s good to see some representation in here from the Cities.

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]

Awesome, thank you very much! Sorry, we’ve been heads down with the next release, but we’ll get this out ASAP.

Sounds great! No real rush for me… it’s working on my side just fine. :wink:

Pushed to the store, thanks again!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.