-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.py
executable file
·100 lines (80 loc) · 3.43 KB
/
main.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import xbmcgui
import xbmcplugin
import xbmcaddon
import datetime
import simplejson as json
import urllib.request, urllib.error, urllib.parse
import urlutil
from urllib.parse import urljoin
from consts import *
addon_handle = int(sys.argv[1])
settings = xbmcaddon.Addon('plugin.video.epgstation')
# dateadded で並び替えできるように設定
xbmcplugin.addSortMethod(addon_handle, xbmcplugin.SORT_METHOD_DATEADDED)
xbmcplugin.setContent(addon_handle, 'movies')
def addList(video, server_url):
li = xbmcgui.ListItem(video['name'])
if video['thumbnails']:
thumbnail_url = urljoin(server_url, 'api/thumbnails/' + str(video['thumbnails'][0]))
li.setArt({
'poster': thumbnail_url,
'fanart': thumbnail_url,
'landscape': thumbnail_url,
'thumb': thumbnail_url
})
startdate = datetime.datetime.fromtimestamp(video['startAt'] / 1000)
info = {
'originaltitle': video['name'],
'title': video['name'],
'sorttitle': video['name'],
'tvshowtitle': video['name'],
'album': video['name'],
'year': startdate.strftime('%Y'),
'date': startdate.strftime('%d.%m.%Y'),
'aired': startdate.strftime('%Y-%m-%d'),
'dateadded': startdate.strftime('%Y-%m-%d %H:%M:%S'),
'duration': (video['endAt'] - video['startAt']) / 1000,
}
try:
# ジャンル
if 'genre1' in video and video['genre1'] in GENRE1:
# ジャンル1
info['genre'] = GENRE1[video['genre1']]
# サブジャンル
if 'subGenre1' in video and video['genre1'] in GENRE2 and video['subGenre1'] in GENRE2[video['genre1']]:
info['genre'] += ' / ' + GENRE2[video['genre1']][video['subGenre1']]
# 詳細
if 'description' in video and not 'extended' in video:
info['plot'] = video['description']
info['plotoutline'] = video['description']
elif 'description' in video and 'extended' in video:
info['plot'] = video['description'] + '\n\n' + video['extended']
info['plotoutline'] = video['description']
except:
print('error')
li.setInfo('video', info)
li.addContextMenuItems([
('更新', 'Container.Refresh'),
('削除', 'RunScript(%s/delete.py, %d, %s)' % (settings.getAddonInfo('path'), video['id'], video['name']))
])
video_url = urljoin(server_url, 'api/videos/' + str(video['videoFiles'][0]['id']))
# if video['original'] == False and 'encoded' in video and len(video['encoded']) > 0:
# video_url += '?encodedId=' + str(video['encoded'][0]['encodedId'])
xbmcplugin.addDirectoryItem(handle=addon_handle, url=video_url, listitem=li)
if __name__ == '__main__':
server_url = settings.getSetting('server_url')
recorded_length = settings.getSetting('recorded_length')
if not server_url:
settings.openSettings()
server_url = settings.getSetting('server_url')
urlInfo = urlutil.getUrlInfo(server_url)
request = urllib.request.Request(url=urljoin(urlInfo["url"], 'api/recorded?isHalfWidth=true&limit=' + str(recorded_length) + '&offset=0'), headers=urlInfo["headers"])
response = urllib.request.urlopen(request)
strjson = response.read()
videos = json.loads(strjson)['records']
for video in videos:
addList(video, server_url)
xbmcplugin.endOfDirectory(addon_handle)