-
Notifications
You must be signed in to change notification settings - Fork 0
/
addon.py
130 lines (107 loc) · 3.36 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Tristan Fischer
#
# 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
#
from xbmcswift2 import Plugin, xbmc
from resources.lib import scraper
plugin = Plugin()
STRINGS = {
'current': 30000,
'archive': 30002,
'search': 30003,
'network_error': 30020
}
@plugin.route('/')
def show_root():
items = [
{'label': _('current'),
'path': plugin.url_for('show_current')},
{'label': _('archive'),
'path': plugin.url_for('show_archive')},
{'label': _('search'),
'path': plugin.url_for('search')}
]
return plugin.finish(items)
@plugin.route('/current/')
def show_current():
videos = scraper.get_current_videos()
return __add_videos(videos)
@plugin.route('/watch/<video_id>')
def watch_video(video_id):
video_url = scraper.get_video_url(video_id)
return plugin.set_resolved_url(video_url)
@plugin.route('/archive/')
def show_archive():
archive_dates = scraper.get_archive_dates()
items = [{
'label': archive_date['title'],
'path': plugin.url_for(
'show_archived_videos',
archive_id=archive_date['archive_id'],
),
} for archive_date in archive_dates]
items.reverse()
return plugin.finish(items)
@plugin.route('/archive/<archive_id>/')
def show_archived_videos(archive_id):
videos = scraper.get_archived_videos(
archive_id=archive_id
)
return __add_videos(videos)
@plugin.route('/search/')
def search():
search_string = plugin.keyboard(heading=_('search'))
if search_string:
url = plugin.url_for(
'search_result',
search_string=search_string
)
plugin.redirect(url)
@plugin.route('/search/<search_string>/')
def search_result(search_string):
videos = scraper.get_search_result(search_string)
return __add_videos(videos)
def __add_videos(videos):
items = [{
'label': video['title'],
'thumbnail': video['thumb'],
'path': plugin.url_for(
'watch_video',
video_id=video['video_id']
),
'info': {
'date': video['date']
},
'is_playable': True,
} for video in videos]
finish_kwargs = {
'sort_methods': ('DATE', )
}
if plugin.get_setting('force_viewmode', bool):
finish_kwargs['view_mode'] = 'thumbnail'
return plugin.finish(items, **finish_kwargs)
def _(string_id):
if string_id in STRINGS:
return plugin.get_string(STRINGS[string_id])
else:
plugin.log.warning('String is missing: %s' % string_id)
return string_id
if __name__ == '__main__':
try:
plugin.run()
except scraper.NetworkError:
plugin.notify(msg=_('network_error'))