-
Notifications
You must be signed in to change notification settings - Fork 6
/
addon.py
executable file
·75 lines (57 loc) · 1.76 KB
/
addon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'''
VimCasts XBMC Addon
-------------------
Watch screencasts from http://vimcasts.org in XBMC.
:copyright: (c) 2012 by Jonathan Beluch
:license: GPLv3, see LICENSE.txt for more details.
'''
import re
import HTMLParser
from urllib2 import urlopen
try:
import json
except ImportError:
import simplejson as json
from xbmcswift2 import Plugin
PLUGIN_NAME = 'VimCasts'
PLUGIN_ID = 'plugin.video.vimcasts'
plugin = Plugin(PLUGIN_NAME, PLUGIN_ID, __file__)
def get_json_feed():
'''Loads the JSON feed for vimcasts.org.'''
json_url = 'http://vimcasts.org/episodes.json?referrer=xbmc'
conn = urlopen(json_url)
_json = json.load(conn)
conn.close()
return _json
def strip_tags(inp):
'''Naively strips instances of <tag> from the given inp'''
return re.sub('(<.+?>)', '', inp)
_parser = HTMLParser.HTMLParser()
def unescape_html(inp):
'''Replaces named instances of html entities with the corresponding
unescaped character.
>>> unescape_html('apples & oranges')
apples & oranges
'''
return _parser.unescape(inp)
def clean(inp):
'''Strips HTML tags and unescapes named HTML entities for the given input.
>>> clean('<strong>apples & oranges</strong>')
apples & oranges
'''
return unescape_html(strip_tags(inp))
@plugin.route('/')
def index():
'''The main menu and only view for this plugin. Lists available episodes'''
items = [{
'label': '#%s %s' % (epi['episode_number'], epi['title']),
'path': epi['quicktime']['url'],
'thumbnail': epi['poster'],
'info': {
'plot': clean(epi['abstract'])
},
'is_playable': True,
} for epi in get_json_feed()['episodes']]
return items
if __name__ == '__main__':
plugin.run()