-
Notifications
You must be signed in to change notification settings - Fork 1
/
addon.py
130 lines (105 loc) · 4.11 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#
# Copyright (C) 2014 Tommy Winther
# http://tommy.winther.nu
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this Program; see the file LICENSE.txt. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# http://www.gnu.org/copyleft/gpl.html
#
import os
import sys
import urllib2
import urlparse
import xml.etree.ElementTree
import buggalo
import xbmcgui
import xbmcaddon
import xbmcplugin
DATA_URL = 'http://vms.api.qbrick.com/rest/v3/getplayer/D5D17F48C5C03FBE?statusCode=xml'
# TODO improve xpath expressions once script.module.elementtree is 1.3+
def showCategories():
doc = loadXml()
for category in doc.findall('categories/category'):
if category.attrib.get('type') != 'standard':
continue
id = category.attrib.get('id')
name = category.attrib.get('name')
item = xbmcgui.ListItem(name, iconImage=ICON)
item.setProperty('Fanart_Image', FANART)
xbmcplugin.addDirectoryItem(HANDLE, PATH + '?category=' + id, item, isFolder=True)
xbmcplugin.endOfDirectory(HANDLE)
def showMedia(categoryId):
doc = loadXml()
for media in doc.findall('media/item'):
correctCategory = False
categories = media.findall('categories/category')
for category in categories:
if category.text == categoryId:
correctCategory = True
break
if not correctCategory:
continue
title = media.findtext('title')
image = media.findtext('images/image')
smilUrl = media.findtext('playlist/stream/format/substream')
infoLabels = dict()
infoLabels['studio'] = ADDON.getAddonInfo('name')
infoLabels['plot'] = media.findtext('description')
infoLabels['title'] = title
#infoLabels['date'] = date.strftime('%d.%m.%Y')
infoLabels['aired'] = media.findtext('publishdate')[0:10]
infoLabels['year'] = int(media.findtext('publishdate')[0:4])
item = xbmcgui.ListItem(title, iconImage=image, thumbnailImage=image)
item.setInfo('video', infoLabels)
item.setProperty('Fanart_Image', image)
item.setProperty('IsPlayable', 'true')
xbmcplugin.addDirectoryItem(HANDLE, PATH + '?smil=' + smilUrl.replace('&', '%26'), item)
xbmcplugin.endOfDirectory(HANDLE)
def playMedia(smilUrl):
doc = loadXml(smilUrl)
if doc is not None:
base = doc.find('head/meta').attrib.get('base')
videos = doc.findall('body/switch/video')
video = videos[len(videos) - 1].attrib.get('src')
# todo quality
item = xbmcgui.ListItem(path=base)
item.setProperty('PlayPath', video)
xbmcplugin.setResolvedUrl(HANDLE, True, item)
else:
xbmcplugin.setResolvedUrl(HANDLE, False, xbmcgui.ListItem())
def loadXml(url=DATA_URL):
try:
u = urllib2.urlopen(url)
response = u.read()
u.close()
return xml.etree.ElementTree.fromstring(response)
except Exception:
return None
if __name__ == '__main__':
ADDON = xbmcaddon.Addon()
PATH = sys.argv[0]
HANDLE = int(sys.argv[1])
PARAMS = urlparse.parse_qs(sys.argv[2][1:])
ICON = os.path.join(ADDON.getAddonInfo('path'), 'icon.png')
FANART = os.path.join(ADDON.getAddonInfo('path'), 'fanart.jpg')
buggalo.SUBMIT_URL = 'http://tommy.winther.nu/exception/submit.php'
try:
if 'category' in PARAMS:
showMedia(PARAMS['category'][0])
elif 'smil' in PARAMS:
playMedia(PARAMS['smil'][0])
else:
showCategories()
except Exception:
buggalo.onExceptionRaised()