-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathServiceCode.pys
More file actions
71 lines (61 loc) · 2.29 KB
/
ServiceCode.pys
File metadata and controls
71 lines (61 loc) · 2.29 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
TITLE = 'DR TV'
PREFIX_VIDEO = '/video/drdk'
PREFIX_AUDIO = '/audio/drdk'
API_URL = 'http://www.dr.dk/mu-online/api/'
ART = 'art-default.jpg'
ICON = 'icon-default.png'
WebsiteURL = 'http://www.dr.dk'
WebsiteTVURL = 'http://www.dr.dk/tv'
API_VERSION = "1.1"
def MetadataObjectForURL(url):
vc = VideoClipObject()
# Get slug from URL
slug = url.rsplit('/',1)[1]
# Request JSON for channel
json = JSON.ObjectFromURL(API_URL + API_VERSION + '/page/tv/live/' + slug)
drNow = json['NowNext']['Now']
vc.title = unicode(drNow['Title'])
vc.summary = unicode(drNow['Description'])
vc.art= drNow['ProgramCard']['PrimaryImageUri']
vc.thumb = drNow['ProgramCard']['PrimaryImageUri']
return vc
def MediaObjectsForURL(url):
# Get slug from URL
slug = url.rsplit('/',1)[1]
return [MediaObject(protocol = 'hls',
video_codec = VideoCodec.H264,
audio_codec = AudioCodec.AAC,
audio_channels = 2,
optimized_for_streaming = True,
parts = [PartObject(key = HTTPLiveStreamURL(url = Callback(PlayMedia, slug = slug) ))])]
@indirect
def PlayMedia(slug):
# get JSON for channel
json = JSON.ObjectFromURL(API_URL + API_VERSION + '/page/tv/live/' + slug)
# Loop all StreamingServers
for StreamingServers in json['Channel']['StreamingServers']:
# Find HLS streams
if StreamingServers['LinkType'] == "HLS":
uri = StreamingServers['Server'] + '/' + StreamingServers['Qualities'][0]['Streams'][0]['Stream']
# Call Gemius to increase DR Most Viewed
gemius(json['NowNext']['Now']['ProgramCard']['Slug'])
return IndirectResponse(VideoClipObject, key = HTTPLiveStreamURL(url = uri))
def gemius(id):
# construct JSON for DR most viewed HTTP POST
# Sometimes Product is None:
product = Client.Product
if product is None:
product = 'unknown'
json = JSON.ObjectFromString('{"id":"' + id + '","Client":"Plex.' + product + '.' + Client.Version + '"}')
# POST to increase DR most viewed list
HTTP.Request(API_URL + API_VERSION + '/reporting/viewed', values = json, method = 'POST')
return None
def NormalizeURL(url):
# remove pause url tag
return url.rsplit('#!',1)[0]
def TestURLs():
test_urls = []
json= JSON.ObjectFromURL('http://www.dr.dk/mu-online/api/1.1/page/tv/front')
for channels in json['Live']:
test_urls.append(WebsiteTVURL + '/live/' + channels['ChannelSlug'])
return test_urls