-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaddon.py
347 lines (270 loc) · 12.7 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# -*- coding: utf-8 -*-
# Kodi Addon: Youtube Library
# Description: Makes it possible to add youtube channels / playlists as tv shows in your library
# Copyright 2015 Sleuteltje
#
# This file is part of plugin.video.youtubelibrary
# Description: Determines which route the addon is currently in and starts the appropiate function to handle that request
#
# 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/>.
import os
import xbmc, xbmcgui, xbmcplugin, xbmcaddon, xbmcvfs
#import Functions
from resources.lib import bookmarks
from resources.lib import vars
from resources.lib import dev
from resources.lib import ytube
from resources.lib import m_xml
from resources.lib import generators
from resources.lib import routes
from resources.lib import play
from resources.lib import playlists
from resources.lib import m_imdb
xbmcplugin.setContent(vars.addon_handle, 'episodes')
#Check if this is the first run of the addon
if xbmcvfs.exists(os.path.join(vars.settingsPath,"settings.xml")) == False: #If the settings.xml file can't be found, this is the first addon run
xbmcgui.Dialog().ok(dev.lang(31101), dev.lang(31102))
#Create the Streams/TV directory
xbmcvfs.mkdir(vars.addondataPath) #Create the settings dir if it does not exist already
#xbmcvfs.mkdir(vars.settingsPath) #Create the settings dir if it does not exist already
#open(os.path.join(vars.settingsPath, "settings.xml"), 'a').close() #Write the settings.xml file
xbmcvfs.mkdir(vars.streamsPath) #Create the streams dir if it does not exist already
xbmcvfs.mkdir(vars.streamsPath+'TV') #Create the streams TV dir if it does not exist already
m_xml.create_xml()
if xbmcvfs.exists(os.path.join(vars.settingsPath,"settings_musicvideo.xml")) == False:
xbmcgui.Dialog().ok(dev.lang(31103), dev.lang(31104))
xbmcvfs.mkdir(vars.streamsPath+'MusicVideos') #Create the streams musicvideos dir if it does not exist already
m_xml.create_xml('settings_musicvideo.xml')
if xbmcvfs.exists(os.path.join(vars.settingsPath,"settings_movies.xml")) == False:
xbmcgui.Dialog().ok(dev.lang(31103), dev.lang(31106))
xbmcvfs.mkdir(vars.streamsPath+'Movies') #Create the streams musicvideos dir if it does not exist already
m_xml.create_xml('settings_movies.xml')
########## ROUTES ##############
#Grab which mode the plugin is in
mode = vars.args.get('mode', None)
type = vars.args.get('type', '')
#Convert type[0] to just type
if type != '':
type = type[0]
##Index
if mode is None:
dev.log('Mode is Index', True)
routes.index()
else:
dev.log('Mode is '+mode[0])
## SERVICE
if mode[0] == "service":
routes.run_service()
#Folder
elif mode[0] == 'folder':
foldername = vars.args['foldername'][0]
#Which folder should be loaded?
## managePlaylists
if foldername == 'managePlaylists':
routes.manage_playlists(type=type)
## Search Channel
elif foldername == 'searchchannel':
routes.search_channel(type=type)
## Search Playlist
elif foldername == 'searchplaylist':
routes.search_playlist(type=type)
## Searched Playlist (pagination)
elif foldername == 'searchedplaylist':
routes.search_playlist(result=vars.args['search'][0], type=type, pagetoken=vars.args['pagetoken'][0])
###### Manage Playlists subroutes
## RemovePlaylist
elif mode[0] == "deletePlaylist":
dev.log('Mode is deletePlaylist '+type)
#Remove this playlist
routes.deletePlaylist(type)
## RefreshPlaylist
elif mode[0] == "refreshPlaylist":
dev.log('Mode is refreshPlaylist '+type)
#Refresh this playlist
routes.refreshPlaylist(type=type)
## RefreshArtwork
elif mode[0] == "refreshArtwork":
dev.log('Mode is refreshArtwork '+type)
#Refresh the artwork of this playlist
routes.refreshArtwork(type=type)
## editPlaylist
elif mode[0] == "editPlaylist":
dev.log('Mode is editPlaylist '+type)
id = vars.args['id'][0]
set = vars.args.get('set', None)
routes.edit_playlist(id, set, type=type)
##### Search Channel subroutes
## pickedChannel
elif mode[0] == "pickedChannel":
dev.log('Picked a channel')
#Display the videos by their channel ID
id = vars.args['id'][0]
pagetoken = vars.args['pagetoken'][0]
routes.show_playlists_by_channel(id, type=type, pagetoken=pagetoken)
elif mode[0] == "pickedmusicvideoChannel":
dev.log('Picked a MusicVideo channel')
#Display the videos by their channel ID
id = vars.args['id'][0]
routes.show_playlists_by_channel(id, 'musicvideo')
## AddPlaylist
elif mode[0] == "addPlaylist":
dev.log('Mode is addPlaylist')
#Display the videos of this playlistID
id = vars.args['id'][0]
routes.add_playlist(id, type=type)
## Update all playlists
elif mode[0] == 'updateplaylists':
dev.log('Mode is updateplaylists')
routes.update_all_playlists(type=type)
elif mode[0] == 'updateplaylist':
dev.log('Mode is updateplaylist')
routes.update_playlist(type=type)
## PLAY VIDEO
elif mode[0] == "play":
dev.log('Mode is Play')
id = vars.args['id'][0] #Grab the vid id which we should be playing
show = vars.args['show'][0] #Grab the show
season = vars.args['season'][0] #Grab the season
episode = vars.args['episode'][0] #Grab the episode
filename = vars.args['filename'][0] #Grab the filename
play.playVid(id, filename, season, episode, show) #Play the video
## PLAY MUSICVIDEO
elif mode[0] == "playmusicvideo":
dev.log('Mode is PlayMusicVideo')
id = vars.args['id'][0] #Grab the vid id which we should be playing
artist = vars.args['artist'][0].decode('utf-8') #Grab the artist
song = vars.args['song'][0].decode('utf-8') #Grab the song
filename = vars.args['filename'][0] #Grab the filename
play.playMusicVid(id, filename, artist, song) #Play the video
## PLAY MOVIE
elif mode[0] == "playmovie":
dev.log('Mode is PlayMovie')
id = vars.args['id'][0] #Grab the vid id which we should be playing
filename = vars.args['filename'][0] #Grab the filename
folder = vars.args['folder'][0] #Grab the filename
play.playVid(id, filename, folder=folder, type='movies') #Play the video
########################## API
##Index
elif mode[0] == 'ApiIndex':
routes.api_home()
##Index
elif mode[0] == 'ApiIndex2':
type = vars.args['type'][0]
routes.api_index(type)
elif mode[0] == "ApiAddPlaylist":
#Display the videos of this playlistID
id = vars.args['id'][0]
type = vars.args['type'][0]
routes.apiAddPlaylist(id, type)
elif mode[0] == 'ApiBrowse':
api_url = vars.args['api_url'][0]
type = vars.args['type'][0]
routes.apiBrowse(api_url, type)
elif mode[0] == 'ApiGenres':
api_url = vars.args['api_url'][0]
type = vars.args['type'][0]
routes.apiGenres(api_url, type)
elif mode[0] == 'ApiTags':
api_url = vars.args['api_url'][0]
type = vars.args['type'][0]
routes.apiTags(api_url, type)
elif mode[0] == 'ApiSearch':
type = vars.args['type'][0]
routes.apiSearch(type)
elif mode[0] == 'ApiSearchChannel':
type = vars.args['type'][0]
routes.apiSearchChannel(type)
elif mode[0] == 'testIMDB':
m_imdb.test()
# ############################################################################## #
######################################### TESTS ##################################
# ############################################################################## #
## REMUX TEST
elif mode[0] == "remuxtest":
dev.log('Mode is remuxtest');
id = "Ivp6hfbQnts"
from resources.lib import pafy
pafy.set_api_key(vars.API_KEY)
#Resolve the youtube video url for ourselves
v = pafy.new(id)
url = dev.build_url({'mode': 'play', 'id': id})
dev.adddir(str(v.getbest()), url, description=v.getbest().url)
url = dev.build_url({'mode': 'playtest', 'foldername': 'remux'})
dev.adddir(str(v.getbestvideo()), url, description=v.getbestvideo().url)
dev.log('Remuxtest, best Video&Audio: '+str(v.getbest()));
dev.log('Remuxtest, best Video: '+str(v.getbestvideo()));
dev.log('Remuxtest, best Audio: '+str(v.getbestaudio()));
xbmcplugin.endOfDirectory(vars.addon_handle)
##Playvidtest
elif mode[0] == "striptest":
dev.log('mode is striptest')
title = 'Britney Spears - Gimme More (from Britney Spears Live: The Femme Fatale Tour)'
url = dev.build_url({'home': 'home'})
title = generators.strip_quality(title)
dev.adddir(title, url, description = 'strip_quality')
dev.log('After strip_quality: '+title)
if generators.strip_lyrics(title) != title:
dev.adddir(title, url, description = 'Title does not match strip_lyrics!')
title = generators.strip_lyrics(title)
dev.adddir(title, url, description = 'strip_lyrics')
dev.log('After strip_lyrics: '+title)
title = generators.strip_audio(title)
dev.adddir(title, url, description = 'strip_audio')
dev.log('After strip_audio: '+title)
title = generators.strip_live(title)
dev.adddir(title, url, description = 'strip_live')
dev.log('After strip_live: '+title)
xbmcplugin.endOfDirectory(vars.addon_handle)
elif mode[0] == "playtest":
dev.log('mode is playtest');
id = "Ivp6hfbQnts"
from resources.lib import pafy
pafy.set_api_key(vars.API_KEY)
#Resolve the youtube video url for ourselves
v = pafy.new(id)
meta = {};
meta['title'] = 'Test'
poster = 'Default.png'
xbmc.Player().play(v.getbestvideo().url) #Play this video
'''
liz = xbmcgui.ListItem(meta['title'], iconImage=poster, thumbnailImage=poster)
liz.setInfo( type="Video", infoLabels=meta )
liz.setPath(v.getbest().url)
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)'''
## STRM TEST
elif mode[0] == "strmtest":
dev.log('Mode is strm test')
id = vars.args['id'][0] #Grab the playlist id which we should be updating
update_playlist(id) #Update the nfo & strm files for this playlist
url = dev.build_url({'home': 'home'})
dev.adddir('Done building strms', url, description = 'Done building all strm files. Press this button to return home')
xbmcplugin.endOfDirectory(vars.addon_handle)
## XML TESTS
elif mode[0] == "xmlcreate":
dev.log('Mode is xmlcreate')
#Test the lxml module for writing xml and stuff
m_xml.create_xml()
url = dev.build_url({'mode': 'xmlcreate', 'foldername': 'xmlcreate'})
dev.adddir('XML Create Test', url)
xbmcplugin.endOfDirectory(vars.addon_handle)
## DELETE TESTS
elif mode[0] == "deletetest":
#success = xbmcvfs.rmdir('C:/Users/Mich/AppData/Roaming/Kodi/userdata/addon_data/plugin.video.youtubelibrary/Streams/R_mi GAILLARD') #Remove the directory
#success = xbmcvfs.rmtree('C:/Users/Mich/AppData/Roaming/Kodi/userdata/addon_data/plugin.video.youtubelibrary/Streams/R_mi GAILLARD/') #Remove the directory
success = shutil.rmtree('C:/Users/Mich/AppData/Roaming/Kodi/userdata/addon_data/plugin.video.youtubelibrary/Streams/R_mi GAILLARD/', ignore_errors=True) #Remove the directory
if success:
xbmcgui.Dialog().ok('Removed from library', 'Deleted this show from your library')
url = dev.build_url({'mode': 'deletetest', 'foldername': 'deletetest'})
dev.adddir('Delete test', url)
xbmcplugin.endOfDirectory(vars.addon_handle)