[xbmc-addons] r2273 committed - Fixed the way datafiles are handled

3 views
Skip to first unread message

xbmc-...@googlecode.com

unread,
Feb 6, 2012, 6:57:08 PM2/6/12
to xbmc-addo...@googlegroups.com
Revision: 2273
Author: dagurp
Date: Mon Feb 6 15:56:56 2012
Log: Fixed the way datafiles are handled

http://code.google.com/p/xbmc-addons/source/detail?r=2273

Added:
/addons/plugin.video.sarpur/changelog.txt
Modified:
/addons/plugin.video.sarpur/addon.xml
/addons/plugin.video.sarpur/default.py
/addons/plugin.video.sarpur/scraper.py

=======================================
--- /dev/null
+++ /addons/plugin.video.sarpur/changelog.txt Mon Feb 6 15:56:56 2012
@@ -0,0 +1,3 @@
+[B]Version 1.0.1[/B]
+Bugfixes:
+- Fixed the way data files are being created and dealt with them becoming
corrupt
=======================================
--- /addons/plugin.video.sarpur/addon.xml Thu Jan 26 13:23:52 2012
+++ /addons/plugin.video.sarpur/addon.xml Mon Feb 6 15:56:56 2012
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.sarpur"
name="Sarpur"
- version="1.0"
+ version="1.0.1"
provider-name="dagur">
<requires>
<import addon="xbmc.python" version="1.0"/>
@@ -14,7 +14,7 @@
</extension>
<extension point="xbmc.addon.metadata">
<summary lang="en">Play videos and radio recordings from the Icelandic
National Radio's website</summary>
- <description lang="en">An Iceland IP-Address is required to use this
because ruv.is locks all other out</description>
+ <description lang="en">An Iceland IP-Address is required to use this
because of geoblocking</description>
<platform>all</platform>
</extension>
</addon>
=======================================
--- /addons/plugin.video.sarpur/default.py Thu Jan 26 13:23:52 2012
+++ /addons/plugin.video.sarpur/default.py Mon Feb 6 15:56:56 2012
@@ -14,7 +14,7 @@
for tab in tabs:
title, url = tab
addDir(title.encode('utf-8'), 'nytt', url)
- for i,stod in enumerate(showtree[:-1]):
+ for i,stod in enumerate(showtree):
title = u'%s \xfe\xe6ttir' % stod['name']
addDir(title.encode('utf-8'), 'stod', i)
# addDir(u'V\xf6ktun K\xf6tlu'.encode('utf-8'), 'eldfjall', 'katla')
=======================================
--- /addons/plugin.video.sarpur/scraper.py Thu Jan 26 13:23:52 2012
+++ /addons/plugin.video.sarpur/scraper.py Mon Feb 6 15:56:56 2012
@@ -1,12 +1,13 @@
#!/usr/bin/env python
-import urllib2, re, os, time
+import urllib2, re, os
from BeautifulSoup import BeautifulSoup
from datetime import datetime
import simplejson as json

user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3)
Gecko/2008092417 Firefox/3.0.3'
-showtreefile_location =
os.path.join(os.getcwd(), 'resources','data','showtree.dat')
-tabfile_location = os.path.join(os.getcwd(), 'resources','data','tabs.dat')
+data_path = os.path.join(os.getcwd(), 'resources','data')
+showtreefile_location = os.path.join(data_path,'showtree.dat')
+tabfile_location = os.path.join(data_path,'tabs.dat')
showtree = [] #All the shows under the thaettir menu
tabs = [] #Tabs in the Sarpur main page

@@ -27,13 +28,15 @@
div = soup.find("div",
attrs={"class": "menu-block-ctools-menu-sarpsmynd-1
menu-name-menu-sarpsmynd parent-mlid-_active:0 menu-level-2"})
for li in div.findAll("li"):
tabs.append((li.a.contents[0], li.a['href']))
-
+

def parse_show_index(html):
"Take the html from the show index and create a data structure"
+ global showtree
+ showtree = []
soup = BeautifulSoup(html)
stodvar = soup.findAll("div",
attrs={"style":re.compile("width:280px;float:left;.*")}) #0: Stod 1 #1: Ras
1 #2: Ras 2
-
+
for i,stod in enumerate(stodvar):
showtree.append({"name":stod.h1.contents[0], "categories":[]})
for flokkur in stod.div:
@@ -43,7 +46,10 @@
elif flokkur.name == 'div':
for show in flokkur.findAll("div"):

showtree[i]["categories"][-1]['shows'].append((show.a.contents[0],
show.a['href']))
-
+
+
+
+
def get_episodes(url):
"Find playable files on a shows page"
episodes = []
@@ -71,31 +77,33 @@
"Find playable files on the 'recent' pages"
html = fetch_page(url)
soup = BeautifulSoup(html)
-
+
spilari = soup.find("div", attrs={'class':'kubbur sarpefst'})
dags = re.search(r'\d{1,2}\. \w{3} \d{4} \|
\d\d:\d\d',repr(spilari)).group()
featured = "%s %s" % (spilari.h1.contents[0], dags)
-
+
episodes = [(featured, url)]
-
+
for li in soup.find("ul", attrs={'class':'sarplisti'}).findAll("li"):
title = "%s %s" % (li.h4.a.contents[0], li.em.contents[0])
pageurl = u"http://www.ruv.is%s" % li.h4.a['href']
episodes.append((title , pageurl))
-
+
return episodes

+
+
def get_stream_info(page_url):
"Get a page url and finds the url of the rtmp stream"
html = fetch_page(page_url)

- access_point_hyperlink = re.search('"http://load.cache.is.*?"',
html).group()[1:-1]
+ access_point_hyperlink = re.search('"http://load.cache.is.*?"',
html).group()[1:-1]
javascript = fetch_page(access_point_hyperlink)
access_point = re.search('"(.*?)"', javascript).group(1)
path = re.search('ruv(vod)?\?key=\d+', html).group()
rtmp_url = "rtmp://%s/%s" % (access_point, path)
playpath = re.findall("\'file\': \'(.*?)\'", html)[-1] #.group(1)
-
+
return {'playpath': playpath, 'rtmp_url': rtmp_url}

def update_index():
@@ -103,32 +111,45 @@
print "Update Sarpur data files."
html = fetch_page('http://dagskra.ruv.is/thaettir/')
parse_show_index(html)
- showtree.append(time.time())
+
+ #showtree.append(time.time())
json.dump(showtree, file(showtreefile_location,'wb'))
get_tabs()
json.dump(tabs, file(tabfile_location,'wb'))

## init
try:
- tabs = json.load(file(tabfile_location,'rb'))
- showtree = json.load(file(showtreefile_location,'rb'))
- delta = datetime.now() - datetime.fromtimestamp(showtree[-1])
+ delta = datetime.now() -
datetime.fromtimestamp(os.path.getmtime(showtreefile_location))
if delta.days > 0:
update_index()
+ else:
+ tabs = json.load(file(tabfile_location,'rb'))
+ showtree = json.load(file(showtreefile_location,'rb'))
+except OSError:
+ if not os.path.exists(data_path):
+ os.makedirs(data_path)
+ update_index()
except IOError:
+ os.unlink(showtreefile_location)
+ os.unlink(tabfile_location)
update_index()


if __name__ == '__main__':
- None
#showtree = []; update_index()
#print showtree[0]['categories']

-
- #for stod in showtree[:-1]:
- # print stod['name'].encode('utf-8')
+ #get_tabs()
+ #os.unlink(showtreefile_location)
+ #os.unlink(tabfile_location)
+ #update_index()
+ #print showtree
+
+ for stod in showtree:
+ #print stod
+ print stod['name'].encode('utf-8')

#for flokkur in showtree[0]['categories']:
# print flokkur
@@ -138,8 +159,12 @@

#print get_episodes("http://dagskra.ruv.is/opus")

- #print get_stream_info("http://www.ruv.is/sarpurinn/nytt")
- #print get_latest_episodes("http://www.ruv.is/sarpurinn/nytt")
+ #print get_stream_info("http://www.ruv.is/ruv")
+ #print get_stream_info("http://www.ruv.is/ras1")
+ #print
get_stream_info("http://www.ruv.is/sarpurinn/regina-osk/19012012")
+ #print get_latest_episodes("http://www.ruv.is/sarpurinn/ras1")

#get_tabs()
#print tabs
+
+

Reply all
Reply to author
Forward
0 new messages