Skip to content

Commit

Permalink
Still learning to use git
Browse files Browse the repository at this point in the history
  • Loading branch information
Dagur committed Oct 8, 2014
1 parent 76e0dba commit 31a07cc
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 155 deletions.
4 changes: 2 additions & 2 deletions plugin.video.sarpur/addon.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.sarpur"
name="Sarpur"
version="3.1.3"
version="3.2.0"
provider-name="Dagur Páll Ammendrup">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
<import addon="script.module.html5lib" version="0.999"/>
<import addon="script.module.beautifulsoup4" version="4.3.2"/>
<import addon="script.module.simplejson" version="2.0.10"/>
<import addon="script.module.requests" version="2.3.0"/>
</requires>
Expand Down
5 changes: 5 additions & 0 deletions plugin.video.sarpur/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[B]Version 3.2.0[/B]
- Better cross platform support (switched to BeautifulSoup 4 from html5lib from lxml)
- Removed the show index (since RÚV removed the recordings). (Added groups instead)
- Last Frodo release. Added Gotham support.

[B]Version 3.1.3[/B]
- Added requests to imports

Expand Down
11 changes: 2 additions & 9 deletions plugin.video.sarpur/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@
try:
if action_key is None:
actions.index()
elif action_key == 'view_channel_index':
actions.channel_index(int(action_value))
elif action_key == 'view_channel_category':
channel, category = action_value.split(';')
actions.channel_category(int(channel), int(category))
elif action_key == 'view_channel_category_show':
actions.channel_category_show(action_value, name)
elif action_key == 'view_group':
actions.view_group(action_value)
elif action_key == 'play':
actions.play_video(action_value, name)
elif action_key == 'view_tab':
actions.tab_index(action_value)
elif action_key == 'view_podcast_index':
actions.podcast_index()
elif action_key == 'view_podcast_show':
Expand Down
3 changes: 2 additions & 1 deletion plugin.video.sarpur/sarpur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import xbmcaddon

ALWAYS_REFRESH = True
ALWAYS_REFRESH = False #True
LOGGING_ENABLED = True

BASE_URL = sys.argv[0]
Expand All @@ -18,3 +18,4 @@
'rondo': 'http://sip-live.hds.adaptive.level3.net/hls-live/ruv-ras3/_definst_/live.m3u8'
}

PODCAST_URL = 'http://www.ruv.is/hladvarp'
116 changes: 63 additions & 53 deletions plugin.video.sarpur/sarpur/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,99 @@
import sarpur
import sarpur.scraper as scraper
import util.player as player
from sarpur.cached import Categories
from util.gui import GUI


INTERFACE = GUI(sarpur.ADDON_HANDLE, sarpur.BASE_URL)
CATS = Categories()

def index():
"""
.. py:function:: index()
The front page (i.e. the first one the user sees when opening the plugin)
"""

for tab in CATS.tabs:
title = tab[0].encode('utf-8')
url = tab[1].encode('utf-8')
INTERFACE.addDir(title, 'view_tab', url)

for i, channel in enumerate(CATS.showtree):
title = '{0} Þættir'.format(channel['name'].encode('utf-8'))
INTERFACE.addDir(title, 'view_channel_index', i)

INTERFACE.addItem('Bein útsending RÚV', 'play_live', 'ruv')
INTERFACE.addItem('Bein útsending RÁS 1', 'play_live', 'ras1')
INTERFACE.addItem('Bein útsending RÁS 2', 'play_live', 'ras2')
INTERFACE.addItem('Bein útsending Rondó', 'play_live', 'rondo')
INTERFACE.addDir('Nýtt', 'view_group', '/')
INTERFACE.addDir('Fréttir', 'view_group', '/flokkar/frettir')
INTERFACE.addDir('Íþróttir', 'view_group', '/flokkar/ithrottir')
INTERFACE.addDir('Barnaefni', 'view_group', '/flokkar/born')
INTERFACE.addDir('Rás 1', 'view_group', '/ras1')
INTERFACE.addDir('Rás 2', 'view_group', '/ras2')
INTERFACE.addDir('Sjónvarpsefni', 'view_group', '/flokkar/1')
INTERFACE.addDir('Íþróttarás', 'view_group', '/flokkar/10')
INTERFACE.addDir('Hlaðvarp', 'view_podcast_index', '')
INTERFACE.addItem('Bein úttsending: RÚV', 'play_live', 'ruv')
INTERFACE.addItem('Bein úttsending: RÁS 1', 'play_live', 'ras1')
INTERFACE.addItem('Bein úttsending: RÁS 2', 'play_live', 'ras2')
INTERFACE.addItem('Bein úttsending: RONDÓ', 'play_live', 'rondo')

def channel_index(channel):
for i, category in enumerate(CATS.showtree[channel].get('categories')):
INTERFACE.addDir(category['name'].encode('utf-8'),
'view_channel_category',
"{0};{1}".format(channel, i))

def channel_category(channel, category):
for show in CATS.showtree[channel]['categories'][category]['shows']:
name, url = show
if url[0] == '/':
url = 'http://dagskra.ruv.is%s' % url
INTERFACE.addDir(name.encode('utf-8'),
'view_channel_category_show',
url.encode('utf-8'))

def channel_category_show(url, show_name):
episodes = scraper.get_episodes(url)
if not episodes:
INTERFACE.infobox("Engar upptökur", "Engin upptaka fannst")
else:
for episode in episodes:
episode_name, url = episode
name = "{0} - {1}".format(show_name, episode_name.encode('utf-8'))
INTERFACE.addItem(name, 'play', url)

def play_video(url, name):
"""
.. py:function:: play_video(url, name)
Plays videos (and audio) other than live streams and podcasts.
:param url: The page url
:param name: The name of the item to play
"""
(playpath, rtmp_url, swfplayer) = scraper.get_stream_info(url)
player.play_stream(playpath, swfplayer, rtmp_url, url, name)

def play_podcast(url):
"""
.. py:function:: play_podcast(url)
Plays podcast
:param url: The file url (this can be any file that xbmc can play)
"""

player.play(url)

def play_live_stream(name):
#url = scraper.get_live_url(name)
"""
.. py:function:: play_live_stream(name)
Play one of the live streams.
:param name: The name of the stream (defined in LIVE_URLS in __init__.py)
"""
url = sarpur.LIVE_URLS.get(name)
player.play(url)

def tab_index(url):
pageurl = 'http://www.ruv.is{0}'.format(url)
def view_group(rel_url):
"""
.. py:function:: view_group(rel_url)
episodes = scraper.get_tab_items(pageurl)
if not episodes:
INTERFACE.infobox("Engar upptökur", "Engin upptaka fannst")
else:
for episode in episodes:
episode_name, url = episode
INTERFACE.addItem(episode_name.encode('utf-8'),
'play',
url.encode('utf-8'))
List items on one of the groups (flokkur tab) on sarpurinn.
:param rel_url: Relative url to the flokkur
"""
full_url = 'http://www.ruv.is/sarpurinn{0}'.format(rel_url)
for video in scraper.get_videos(full_url):
name, url = video
INTERFACE.addItem(name.encode('utf-8'), 'play', url.encode('utf-8'))

def podcast_index():
for show in scraper.get_podcast_shows():
"""
.. py:function:: podcast_index()
List all the podcasts.
"""
for show in scraper.get_podcast_shows(sarpur.PODCAST_URL):
name, url = show
INTERFACE.addDir(name.encode('utf-8'), 'view_podcast_show', url)

def podcast_show(url, name):
"""
.. py:function:: podcast_show(url, name)
List all the recordings for a podcast show.
:param url: The podcast url (xml file)
:param name: The name of the show
"""
for recording in scraper.get_podcast_episodes(url):
date, url = recording
title = "{0} - {1}".format(name, date.encode('utf-8'))
Expand Down
7 changes: 7 additions & 0 deletions plugin.video.sarpur/sarpur/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@
import sarpur

def log(message):
"""
.. py:function:: log(message)
This is the preferred way to log things in XBMC (rahter than using print)
:param message to log
"""
if sarpur.LOGGING_ENABLED:
xbmc.log(message)
Loading

0 comments on commit 31a07cc

Please sign in to comment.