forked from jbeluch/xbmc-vimcasts
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplugin.py
More file actions
90 lines (68 loc) · 2.08 KB
/
plugin.py
File metadata and controls
90 lines (68 loc) · 2.08 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'''
VimCasts KODI Addon
-------------------
Watch screencasts from http://vimcasts.org in KODI.
:copyright: (c) 2012 by Jonathan Beluch
:license: GPLv3, see LICENSE.txt for more details.
'''
import re
import sys
import json
from xbmcswift2 import Plugin
import html
from html.parser import HTMLParser
from urllib.request import urlopen
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()
def unescape_html(inp):
'''Replaces named instances of html entities with the corresponding
unescaped character.
>>> unescape_html('apples & oranges')
apples & oranges
'''
try:
return html.unescape(inp)
except:
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'],
'fanart': plugin.fanart,
'info': {
'plot': clean(epi['abstract']),
'duration': int(epi['quicktime']['seconds'])
},
'is_playable': True,
} for epi in get_json_feed()['episodes'] if epi['quicktime']['url']]
finish_kwargs = {
'sort_methods': [
('UNSORTED', '%X'),
('TITLE', '%X'),
'DURATION',
],
}
return plugin.finish(items, **finish_kwargs)
def run():
plugin.run()