This repository was archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalpha.py
More file actions
197 lines (137 loc) · 7.25 KB
/
Copy pathalpha.py
File metadata and controls
197 lines (137 loc) · 7.25 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# plugin.video.eptv is in alpha so don't bite my head off just yet, and please contribute!
from bs4 import BeautifulSoup
import json
import re
import sys
import urllib
import urlparse
import xbmcgui
import xbmcplugin
BASE_URL = sys.argv[0]
ADDON_HANDLE = int(sys.argv[1])
ARGS = urlparse.parse_qs(sys.argv[2][1:])
SCHEDULE_URL = 'http://www.europarl.europa.eu/ep-live/'
EPTV_URL = 'https://www.europarltv.europa.eu'
xbmcplugin.setContent(handle=ADDON_HANDLE, content='movies')
def build_url(query):
return BASE_URL + '?' + urllib.urlencode(query)
def main_menu():
categories = ['Schedule', 'Live', 'Categories']
defunct_categories = ['Plenary on demand', 'Committees on demand', 'Other events on demand']
for category in categories:
url = build_url({'mode': category, 'foldername': category})
li = xbmcgui.ListItem(category, iconImage='DefaultFolder.png')
xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE, url=url, listitem=li, isFolder=True)
for category in defunct_categories:
url = build_url({'mode': category, 'foldername': category})
li = xbmcgui.ListItem('[COLOR grey]' + category + '[/COLOR]', iconImage='DefaultFolder.png')
xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE, url=url, listitem=li, isFolder=True)
xbmcplugin.endOfDirectory(ADDON_HANDLE)
def live_menu():
schedule_page = BeautifulSoup(urllib.urlopen(SCHEDULE_URL), 'html.parser')
live_broadcasts = [elem.parent for elem in schedule_page.find_all(class_='ep_live')]
for broadcast in live_broadcasts:
time = broadcast.find('span', class_='ep_time').text
title = broadcast.find('span', class_='ep_title').text
subtitle = broadcast.find('span', class_='ep_subtitle').text
url = build_url({'mode': 'play_live_video', 'vidurl': broadcast['href']})
li = xbmcgui.ListItem("[" + title + "] " + subtitle + " (" + time + ")", iconImage='DefaultFolder.png')
li.setProperty('IsPlayable', 'true')
xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE, url=url, listitem=li, isFolder=False)
xbmcplugin.endOfDirectory(ADDON_HANDLE)
def categories_menu():
"""Build the categories menu."""
categories = ['EU-affairs', 'Economy', 'Security', 'Society', 'World']
for category in categories:
url = build_url({'mode': 'Topic', 'foldername': category, 'page': 1})
li = xbmcgui.ListItem(category, iconImage='DefaultFolder.png')
xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE, url=url, listitem=li, isFolder=True)
xbmcplugin.endOfDirectory(ADDON_HANDLE)
def topics_menu(topic, pagenum):
topic_url = EPTV_URL + '/category/' + topic + '?page=' + pagenum
topic_page = BeautifulSoup(urllib.urlopen(topic_url), 'html.parser')
for videoItem in topic_page.find_all('article'):
url = build_url({'mode': 'Video', 'vidurl': videoItem.a['href']})
li = xbmcgui.ListItem(videoItem.a['title'], iconImage='DefaultFolder.png')
xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE, url=url, listitem=li, isFolder=False)
url = build_url({'mode': 'Topic', 'foldername': topic, 'page': int(pagenum) + 1})
li = xbmcgui.ListItem('Next page', iconImage='DefaultFolder.png')
xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE, url=url, listitem=li, isFolder=True)
xbmcplugin.endOfDirectory(ADDON_HANDLE)
def committees_menu():
recorded_url = SCHEDULE_URL + '/en/committees/search'
recorded_page = BeautifulSoup(urllib.urlopen(recorded_url), 'html.parser')
for recorded_committee in recorded_page.find_all('li', class_='ep_media'):
url = build_url({'mode': 'Committee', 'comitteeUrl': recorded_committee.a['href']})
li = xbmcgui.ListItem(recorded_committee.find('span', class_='ep_title').string, iconImage='DefaultFolder.png')
xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE, url=url, listitem=li, isFolder=False)
xbmcplugin.endOfDirectory(ADDON_HANDLE)
def agenda():
schedule_page = BeautifulSoup(urllib.urlopen(SCHEDULE_URL), 'html.parser')
scheduled_days = schedule_page.find_all('div', class_='ep_elementtime')
for day in scheduled_days:
events = day.ul.find_all('li')
day_string = '[B][COLOR = blue]{}:[/COLOR][/B]'.format(day.find('div', class_='ep_title').string.strip())
li = xbmcgui.ListItem(day_string)
li.setProperty('IsPlayable', 'false')
xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE, url='', listitem=li, isFolder=False)
for event in events:
li = xbmcgui.ListItem(' [' + event.find(class_='ep_time').text + '] ' + event.find(class_='ep_subtitle').text)
li.setProperty('IsPlayable', 'false')
xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE, url='', listitem=li, isFolder=False)
xbmcplugin.endOfDirectory(ADDON_HANDLE)
def play_topic_video(vidurl):
video_link = EPTV_URL + vidurl
first_vid_page = BeautifulSoup(urllib.urlopen(video_link), 'html.parser')
thumb_link = first_vid_page.find('meta', {'property': 'og:image'})['content']
'''Extract iframe number from 'thumb_link'.'''
iframe_num = thumb_link.split('/')[4]
'''Link to JSON object containing the "entry_id".'''
json_link = EPTV_URL + '/europarltv_services/services/getIframe/' + iframe_num
'''Get the "entry_id".'''
entry_id = json.load(urllib.urlopen(json_link))['data']['entry']
video_location_url = 'https://eurounprodkmc-a.akamaihd.net/p/102/sp/10200/raw/entry_id/' + \
entry_id + \
'?relocate = f.mov'
play_item = xbmcgui.ListItem(path=video_location_url)
xbmcplugin.setResolvedUrl(handle=ADDON_HANDLE, succeeded=True, listitem=play_item)
def play_live_video(vidurl):
url = SCHEDULE_URL.strip('/ep-live/') + vidurl.replace('/en/', '/en/json/', 1)
url = BeautifulSoup(json.loads(urllib.urlopen(url).readline())['event']['embedCode'], 'html.parser').iframe[
'src']
media_json = json.loads(re.search('var mediaSetup = ({.*?});', urllib.urlopen(url).read()).group(1))
media_server = media_json['server']
media_application = media_json['application']
# media_track = media_json['playlist'][0]['source']['languages']
# media_clientip = media_json['clientIp']
# TODO: Stream selection by user
media_stream = media_json['playlist'][0]['source']['qualities'].values()[0]['en']
url = '/'.join(['https:/', media_server, media_application, media_stream, 'playlist.m3u8'])
li = xbmcgui.ListItem(path=url)
xbmcplugin.setResolvedUrl(handle=ADDON_HANDLE, succeeded=True, listitem=li)
def defunct():
xbmcgui.Dialog().notification('EuroparlTV', 'Under construction.', xbmcgui.NOTIFICATION_ERROR, 5000)
mode = ARGS.get('mode', None)
if mode is None:
main_menu()
elif mode[0] == 'Categories':
categories_menu()
elif mode[0] == 'Topic':
topic = ARGS.get('foldername')[0]
pagenum = ARGS.get('page')[0]
topics_menu(topic, pagenum)
elif mode[0] == 'Video':
play_topic_video(ARGS.get('vidurl')[0])
elif mode[0] == 'Live':
live_menu()
elif mode[0] == 'Schedule':
agenda()
elif mode[0] == 'play_live_video':
play_live_video(ARGS.get('vidurl')[0])
elif mode[0] == 'Plenary on demand':
defunct()
elif mode[0] == 'Committees on demand':
defunct()
committees_menu()
elif mode[0] == 'Other events on demand':
defunct()