Diff of /plugin.video.nos/modules/laatste_journaals.py [52c928] .. [add7ca]  Maximize  Restore

  Switch to side-by-side view

--- a/plugin.video.nos/modules/laatste_journaals.py
+++ b/plugin.video.nos/modules/laatste_journaals.py
@@ -1,5 +1,5 @@
 #/*
-# *      Copyright (C) 2011 Erwin Junge
+# *      Copyright (C) 2012 Erwin Junge
 # *
 # *
 # *  This Program is free software; you can redistribute it and/or modify
@@ -21,57 +21,31 @@
 
 import xbmcplugin
 import xbmcgui
-import urllib
 import urllib2
 import re
-from BeautifulSoup import BeautifulSoup, SoupStrainer
 import sys
+
+link_re = re.compile(r'<a.*?</a>', re.S)
+video_re = re.compile(r'http://.*\.mp4')
+title_re = re.compile(r'<h3>(.*?)</h3>')
+meta_re = re.compile(r'<p class="video-meta">(.*?)</p>')
+img_re = re.compile(r'<img src="(.*?)"')
 
 def addLink(title, url, thumb):
   liz=xbmcgui.ListItem(title, thumbnailImage=thumb)
-  liz.setProperty("IsPlayable","true")
   xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=liz, isFolder=False)
 
-def stringfilter(s):
-  return isinstance(s, basestring)
-
 def scan(params):
-  module = params['module']
-
   URL='http://tv.nos.nl'
-  links = SoupStrainer('a')
-  for tag in BeautifulSoup(urllib2.urlopen(URL).read(), parseOnlyThese=links):
-    # Get url
-    url_suffix = tag['href']
-    url = URL+"/browser/"+url_suffix
-    url = urllib.quote_plus(url)
-    url = sys.argv[0]+"?module="+module+"&url="+url
-    # Get thumbnail image
-    thumb_suffix = tag.div.img['src']
-    thumb = URL+"/browser/"+thumb_suffix
-    # Get title
-    title = tag.div.h3.contents[0]
-    meta = ', '.join([substring.strip('\n ') for substring in filter(stringfilter, tag.div.p.contents)])
+  html=urllib2.urlopen(URL).read()
+  for (a, video_url) in zip(link_re.findall(html), video_re.findall(html)):
+    a = a.replace('\n', '')
+    title = title_re.search(a).group(1).strip()
+    meta = ', '.join([meta_part.strip() for meta_part in re.sub(r'\s+', ' ', meta_re.search(a).group(1)).split('<br />')])
+    img = URL + '/browser/' + img_re.search(a).group(1).strip()
     title = title + ' - ' + meta
-    addLink(title, url, thumb)
+    addLink(title, video_url, img)
   xbmcplugin.endOfDirectory(int(sys.argv[1]))
 
-def find_video(url):
-  page=urllib2.urlopen(url).read()
-  xml=re.search(r'http://content.nos.nl/.*?\.xml',page).group(0)
-  xml=urllib2.urlopen(xml).read()
-  video_link=re.search(r'http://.*?\.(flv|mp4)',xml).group(0)
-  return video_link
-
-def play(url):
-  url = urllib.unquote_plus(url)
-  resolved_url = find_video(url)
-  li=xbmcgui.ListItem(path = resolved_url)
-  xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, li)
-
 def run(params): # This is the entrypoint
-  if 'url' in params: # url set, so play the url
-    url = params['url']
-    play(url)
-  else: # no url set, scan for urls
-    scan(params)
+  scan(params)

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks