/
Default.py
681 lines (613 loc) · 27.6 KB
/
Default.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ChannelAwesome.com Addon
import urllib
import socket
import re
import sys
import os
from bs4 import BeautifulSoup
import sqlite3
import xbmcplugin
import xbmcgui
import xbmcaddon
import xbmc
import utils
addonID = 'plugin.video.channelawesome'
addon = xbmcaddon.Addon(id=addonID)
socket.setdefaulttimeout(30)
pluginhandle = int(sys.argv[1])
addonDir = xbmc.translatePath(addon.getAddonInfo('path'))
icon = os.path.join(addonDir, 'icon.png')
profile = xbmc.translatePath(addon.getAddonInfo('profile'))
local_db = os.path.join(profile, 'local_db.db')
pluginDir = sys.argv[0]
# Create addon folder in user_data, necessary for the sqlite db
if addon.getSetting("firstrun") != 'false':
addon.setSetting("firstrun", 'false')
# Main List View
def CATEGORIES():
addDir('Latest Videos', 'http://channelawesome.com', 2, icon)
addDir('All Shows', 'http://channelawesome.com', 1, '')
addDir('Search ChannelAwesome.com', '', 4, '')
addDir('Addon Favorites', '', 5, '')
addDir('Local Database', '', 7, '')
xbmc.executebuiltin('Container.SetViewMode(500)')
xbmcplugin.endOfDirectory(pluginhandle)
def ALLSHOWS(url):
content = utils.grab_url(url)
match = re.compile(
'<li id="menu-item-.+?" class="ubermenu-item ubermenu-item-type-taxonomy ubermenu-item-object-category '
'ubermenu-item-.+? ubermenu-item-auto ubermenu-item-normal ubermenu-item-level-2 ubermenu-column '
'ubermenu-column-auto" ><a class="ubermenu-target ubermenu-item-layout-default ubermenu-item-layout-text_only" '
'href="(.+?)"><span class="ubermenu-target-title ubermenu-target-text">(.+?)</span>').findall(content)
xbmcplugin.addSortMethod(int(sys.argv[1]), 1)
for url, name in match:
addDir(name, url, 2, '', dirmode='allshows')
xbmcplugin.endOfDirectory(pluginhandle)
def LISTVIDEOS(url):
baseurl = url
if '/?s=' in url:
is_search = 1
else:
is_search = 0
content = utils.grab_url(url)
video_info = utils.scrape_data(content)
if is_search and (len(video_info) < 1):
print 'No search results'
dialog = xbmcgui.Dialog()
dialog.notification('No results!', 'No videos found with this search!', xbmcgui.NOTIFICATION_INFO, 1000)
# TODO: Go Back to Mode 1
return
# Get current page and max page number
matchc = re.compile('class="pages">Page (.+?) of (.+?)</span>').findall(content)
if matchc == []:
print 'This show or search result only has one page' #DEBUG INFO
for url, name, thumbnail, plot in video_info:
addLink(name, url, 3, thumbnail, plot)
return
else:
curp = int(matchc[0][0])
nextp = curp + 1
prevp = curp - 1
lastp = int(matchc[0][1])
position = 'Page ' + str(curp) + ' of ' + str(lastp)
# Display Page Indicator if activated in settings!
if get_bool_settings('page_indicator'):
addInfo(matchc[0][0], matchc[0][1], baseurl)
for url, name, thumbnail, plot in video_info:
addLink(name, url, 3, thumbnail, plot, show_url=baseurl, max_page=lastp)
if is_search == 0:
if '/page/' in baseurl:
baseurl = re.sub("/page/.+", "/page/", baseurl)
else:
baseurl = baseurl + '/page/'
if curp == 1:
addDir('Prev Page (' + str(lastp) + ' of ' + str(lastp) + ')', baseurl + str(lastp), 2, '')
else:
addDir('Prev Page (' + str(prevp) + ' of ' + str(lastp) + ')', baseurl + str(prevp), 2, '')
if curp < lastp:
addDir('Next Page (' + str(nextp) + ' of ' + str(lastp) + ')', baseurl + str(nextp), 2, '')
else:
sstring = re.sub(".+?/?s=", "/?s=", baseurl)
surl = 'http://channelawesome.com/page/'
if curp == 1:
addDir('Prev Page (' + str(lastp) + ' of ' + str(lastp) + ')', surl + str(lastp) + sstring, 2, '')
else:
addDir('Prev Page (' + str(prevp) + ' of ' + str(lastp) + ')', surl + str(prevp) + sstring, 2, '')
if curp < lastp:
addDir('Next Page (' + str(nextp) + ' of ' + str(lastp) + ')', surl + str(nextp) + sstring, 2, '')
def RESOLVELINK(url): # Grab the urls of the embedded videos
content = utils.grab_url(url)
screenwave = 'src="(http:\/\/player(?:[0-9]|).screenwavemedia.com(?:\/play|)\/player.php\?id=.+)"(?:\s|\>\<\/s)'
# This should capture all embedded screenwavemedia videos (i have encountered yet)
# The brackets that begin with "?:" are non capturing brackets.
youtube = 'youtube.com/embed/(.+?)"'
dailymotion = '<iframe frameborder="[0-1]" width="[0-9]{3}" height="[0-9]{3}" src="(//www.dailymotion.com/embed/video/.+?)" allowfullscreen></iframe>'
sw_match = re.compile(screenwave).findall(content)
yt_match = re.compile(youtube).findall(content)
dm_match = re.compile(dailymotion).findall(content)
videos = sw_match + yt_match + dm_match
if len(videos) > 1:
print 'More than one Video on this page'
video_lst = videos
select_lst = []
dialog = xbmcgui.Dialog()
num = 0
for entry in video_lst:
num = num + 1
selection = 'Part ' + str(num)
select_lst.append(selection)
print video_lst
ret = dialog.select('Choose Part', select_lst)
if ret == -1:
print 'Canceled'
dialog = xbmcgui.Dialog()
dialog.notification('Selection canceled', 'No Video selected', xbmcgui.NOTIFICATION_INFO, 5000)
return
else:
print ret
video_url = utils.get_video(video_lst[ret])
elif len(videos) == 1:
url = videos[0]
video_url = utils.get_video(url)
else:
soup = BeautifulSoup(content, "html.parser")
header = soup.find("span", {"itemprop" : "name"}).text
entry = soup.find("div", class_='entry').text
showText(header, entry)
dialog = xbmcgui.Dialog()
dialog.notification('No Video', 'No embedded video found.', xbmcgui.NOTIFICATION_INFO, 3000)
video_url=None
return
listitem = xbmcgui.ListItem(path=video_url)
return xbmcplugin.setResolvedUrl(pluginhandle, True, listitem)
def SEARCHSITE(name):
dialog = xbmcgui.Dialog()
d = dialog.input('Search ChannelAwesome.com', type=xbmcgui.INPUT_ALPHANUM)
d = d.replace(" ", "+")
if d == '':
print 'No input' #Debug Info
dialog = xbmcgui.Dialog()
dialog.notification('Info', 'No Input or Canceled', xbmcgui.NOTIFICATION_INFO, 1000)
# TODO: Go Back to Mode 1
else:
url = 'http://channelawesome.com/?s=' + d
LISTVIDEOS(url)
#kodi_url = pluginDir + '?mode=2&url=' + urllib.quote_plus('http://channelawesome.com/?s=' + d)
#builtin = 'ReplaceWindow(10025,{})'.format(kodi_url)
#builtin = 'Container.Update({})'.format(kodi_url)
#builtin = 'Container.Refresh'
#xbmc.executebuiltin(builtin)
# NOT Perfect! with Container.Update you will be presented with the search dialog again if you go back
# with Replace.Window you kinda messup kodis windows and wont end up where you started from
# after leaving the addon with "back"
def DISPLAY_FAVS():
print 'Display Favorite Shows'
conn = sqlite3.connect(local_db)
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS fav_list (fav_name TEXT PRIMARY KEY, fav_url TEXT)')
c.execute('SELECT fav_name, fav_url FROM fav_list')
shows = c.fetchall()
conn.close()
if len(shows):
print shows # DEBUG
xbmcplugin.addSortMethod(int(sys.argv[1]), 1)
for fav_name, fav_url in shows:
addDir(fav_name, fav_url, 2, '', dirmode='favorites')
else:
dialog = xbmcgui.Dialog()
dialog.notification('Info', 'No shows were added to the addon favorites.', xbmcgui.NOTIFICATION_INFO, 1000)
#xbmc.executebuiltin("ReplaceWindow(10024,{})".format(pluginDir))
#xbmc.executebuiltin("PreviousMenu")
#xbmc.executebuiltin("Back")
def EDIT_FAVS(fav_arg):
print 'Favorites function activated'
print 'Parameter: ' + str(fav_arg)
data = fav_arg.split(';')
fav_mode = data[0].replace('MODE:', '')
fav_name = data[1].replace('NAME:', '')
fav_url = data[2].replace('URL:', '')
print 'Mode:',fav_mode
print 'Url:',fav_url
print 'Show name:',fav_name
# Connect to DB
conn = sqlite3.connect(local_db)
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS fav_list (fav_name TEXT PRIMARY KEY, fav_url TEXT)')
if fav_mode == 'ADD':
print 'Adding Favorite'
c.execute('INSERT OR REPLACE INTO fav_list VALUES ("{}", "{}")'.format(fav_name, fav_url))
else:
print 'Removing Favorite'
c.execute('DELETE FROM fav_list WHERE fav_name="{}"'.format(fav_name))
conn.commit()
conn.close()
xbmc.executebuiltin("Container.Refresh")
def DISPLAY_DB():
print 'Display stored Shows'
conn = sqlite3.connect(local_db)
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS show_list (table_name TEXT PRIMARY KEY, show_name TEXT, show_url TEXT)')
c.execute("SELECT table_name, show_name, show_url, show_icon FROM show_list")
shows = c.fetchall()
conn.close()
if len(shows):
print shows # DEBUG
xbmcplugin.addSortMethod(int(sys.argv[1]), 1)
for table_name, show_name, show_url, show_icon in shows:
addDBShow(show_name, table_name, 8, show_icon, show_url)
else:
dialog = xbmcgui.Dialog()
dialog.notification('Info', 'No shows were added to the local db.', xbmcgui.NOTIFICATION_INFO, 2000)
# TODO: Go Back to Mode 1
def DISPLAY_DB_SHOW(db_table):
conn = sqlite3.connect(local_db)
c = conn.cursor()
try:
c.execute('SELECT id, name, url, thumb, plot, airdate FROM {}'.format(db_table))
except:
dialog = xbmcgui.Dialog()
dialog.notification('DB Error', 'Try readding the show or clear DB', xbmcgui.NOTIFICATION_ERROR, 3000)
# TODO: Go Back
else:
video_info = c.fetchall()
conn.close()
for id, name, url, thumbnail, plot, airdate in video_info:
name = name.encode('ascii', 'ignore')
plot = plot.encode('ascii', 'ignore')
# .encode(...) is needed because coming from the DB python cant display some utf8 symbols
if get_bool_settings('episode_view'):
addLink(name, url, 3, thumbnail, plot, episode=id, date=airdate)
else:
addLink(name, url, 3, thumbnail, plot, date=airdate)
if get_bool_settings('episode_view'):
xbmc.executebuiltin('Container.SetViewMode(504)')
xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_EPISODE)
else:
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_TITLE)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
xbmc.executebuiltin("Container.SetSortMethod(2)")
def EDIT_DB(db_arg):
print 'Scrape for DB Activated'
#print 'Parameter: ' + str(db_arg)
aborted = 0
data = db_arg.split(';')
db_mode = data[0].replace('MODE:', '')
db_name = data[1].replace('NAME:', '')
db_url = data[2].replace('URL:', '')
show_name = db_name
db_name = db_name.replace(' ', '').lower()
print 'DB Mode: ' + db_mode
print 'DB Url:' + db_url
print 'DB name:' + db_name
print 'Show name:' + show_name
# Connect to DB
conn = sqlite3.connect(local_db)
conn.text_factory = str
c = conn.cursor()
if db_mode == 'UPDATE':
print 'UPDATE STARTED!!!'
print 'Show URL: '+ db_url
# Progress Dialog
progress = xbmcgui.DialogProgress()
progress.create('Updating Show', 'Scraping new videos...')
progress.update( 1, "", 'Initializing scrape...', "" )
# Grab Page Content
content = utils.grab_url(db_url)
# Grab Show Icon
show_icon = utils.grab_icon(content)
# Get max page number
matchc = re.compile('class="pages">Page (.+?) of (.+?)</span>').findall(content)
lastp = int(matchc[0][1])
counter = 0
video_list = []
for i in range(1, lastp + 1):
allready_in_db = 0
percent = int( (100 / lastp) * i)
message = "Scraping page " + str(i) + " of " + str(lastp)
progress.update( percent, "", message, "" )
xbmc.sleep( 1000 )
url = db_url + 'page/' + str(i)
page_content = utils.grab_url(url)
video_info = utils.scrape_data(page_content, 'DB')
for url, name, thumbnail, plot, airdate in video_info:
# Test to see if entry is allready in DB
c.execute('SELECT airdate FROM {} WHERE name="{}"'.format(db_name, name))
test = c.fetchone()
if test is None:
print 'Episode: "{}" not in DB, adding to update list now!'.format(name)
entry = (name, url, thumbnail, plot, airdate)
video_list.append(entry)
counter = counter + 1
else: # Entry available in local DB
print 'Episode: "{}" Allready in DB, breaking loop now!'.format(name)
print 'Stopping update process but will commit changes (if any) to DB'
allready_in_db = 1
break
if progress.iscanceled():
aborted = True
break
if allready_in_db:
break
progress.close()
if aborted:
print 'Scrape was aborted!' # DEBUG INFO
dialog = xbmcgui.Dialog()
dialog.notification('Update canceled!', 'No updates were stored in the DB', xbmcgui.NOTIFICATION_WARNING, 3000)
else:
dialog = xbmcgui.Dialog()
c.execute('UPDATE show_list SET show_icon="{}" WHERE table_name="{}"'.format(show_icon, db_name))
if len(video_list) > 0:
video_list.reverse()
c.executemany('INSERT INTO {} (name, url, thumb, plot, airdate) VALUES (?,?,?,?,?)'.format(db_name), video_list)
dialog.notification('Update Successfull', '{} entries added to the DB'.format(str(counter)), xbmcgui.NOTIFICATION_INFO, 3000)
else:
dialog.notification('No Updates', 'No updates were found for this show', xbmcgui.NOTIFICATION_INFO, 3000)
conn.commit()
conn.close()
elif db_mode == 'ADD':
c.execute('SELECT name FROM sqlite_master WHERE type="table" AND name="{}"'.format(db_name))
test = c.fetchone()
if test is None:
print 'Table: "{}" does not exist in DB, i will continue'.format(db_name)
# Progress Dialog
progress = xbmcgui.DialogProgress()
progress.create('Adding Show to local Database', 'Scraping all videos...')
progress.update( 1, "", 'Initializing scrape...', "" )
# Grab Page Conent
content = utils.grab_url(db_url)
# Grab Show Icon
show_icon = utils.grab_icon(content)
# Get max page number
matchc = re.compile('class="pages">Page (.+?) of (.+?)</span>').findall(content)
lastp = int(matchc[0][1])
video_list = []
for i in range(1, lastp + 1):
percent = int( (100 / lastp) * i)
message = "Scraping page " + str(i) + " of " + str(lastp)
progress.update( percent, "", message, "" )
xbmc.sleep( 1000 )
url = db_url + 'page/' + str(i) # Modified "/page/" to "page/"
page_content = utils.grab_url(url)
video_info = utils.scrape_data(page_content, 'DB')
for url, name, thumbnail, plot, airdate in video_info:
print 'name: ' + utils.cleanName(name) # + '\nplot: ' + utils.cleanName(plot) # DEBUG INFO
entry = (name, url, thumbnail, plot, airdate)
video_list.append(entry)
if progress.iscanceled():
aborted = True
break
progress.close()
dialog = xbmcgui.Dialog()
if aborted:
print 'Scrape was aborted!' # DEBUG INFO
dialog.notification('Process canceled!', 'The show was not added to the local DB.', xbmcgui.NOTIFICATION_WARNING, 3000)
else:
if len(video_list) > 0:
# Turn List of Videos arround to get accurate list based on release date
video_list.reverse()
# Create DB Tables
c.execute('CREATE TABLE IF NOT EXISTS {} (id INTEGER PRIMARY KEY, name TEXT, url TEXT, thumb TEXT, plot TEXT, airdate TEXT)'.format(db_name))
c.execute('CREATE TABLE IF NOT EXISTS show_list (table_name TEXT PRIMARY KEY, show_name TEXT, show_url TEXT, show_icon TEXT)')
# Add Content to DB
c.execute('INSERT OR REPLACE INTO show_list VALUES ("{}", "{}", "{}", "{}")'.format(db_name, show_name, db_url, show_icon))
c.executemany('INSERT INTO {} (name, url, thumb, plot, airdate) VALUES (?,?,?,?,?)'.format(db_name), video_list)
dialog.notification('Process Complete!',
'The show "{}" was added to the local DB.'.format(show_name),
xbmcgui.NOTIFICATION_INFO, 3000)
conn.commit()
else:
print 'Table: "{}" does exist in DB, i will not continue'.format(db_name)
dialog = xbmcgui.Dialog()
dialog.ok('Database', 'Show "{}" is allready in the local DB. Update from there.'.format(show_name))
conn.close()
elif db_mode == 'REMOVE':
dialog = xbmcgui.Dialog()
if dialog.yesno("Remove from local DB", 'Dou you really want to remove the show:','{}'.format(show_name), "",'No','Yes'):
c.execute('DROP TABLE IF EXISTS "{}"'.format(db_name))
c.execute('DELETE FROM show_list WHERE table_name="{}"'.format(db_name))
conn.commit()
conn.close()
xbmc.executebuiltin("Container.Refresh")
# Remove local DB (can be run from settings)
def CLEAR_DB():
dialog1 = xbmcgui.Dialog()
dialog2 = xbmcgui.Dialog()
if dialog1.yesno("Clear local DB", 'Dou you really want to clear local DB','and remove all saved favorites and shows?', "",'No','Yes'):
os.remove(os.path.join(profile, 'local_db.db'))
dialog2.notification('DB Cleared', 'Local DB was cleared!', xbmcgui.NOTIFICATION_INFO, 3000)
else:
dialog2.notification('Process Canceled', 'Local DB was not removed!', xbmcgui.NOTIFICATION_INFO, 3000)
def JUMPTO(url, max_page):
print 'Max Page:' + str(max_page)
dialog = xbmcgui.Dialog()
d = dialog.input('Jump to page', type=xbmcgui.INPUT_NUMERIC)
print 'Dialog input: ' + d
if (d == ''):
print 'No dialog input' #DEBUG INFO
elif (int(d) > max_page):
dialog.notification('Page not available!', 'Entered page number to high!', xbmcgui.NOTIFICATION_WARNING, 3000)
else:
if ('/?s=' in url): # If URL is result of Search
sstring = re.sub(".+?/?s=", "/?s=", url)
surl = 'http://channelawesome.com/page/'
goto_url = surl + d + sstring
else:
if '/page/' in url:
baseurl = re.sub("/page/.+", "page/", url)
else:
baseurl = url + '/page/'
goto_url = baseurl + d
if d:
kodi_url = pluginDir + '?mode=2&url={}'.format(urllib.quote_plus(goto_url))
builtin = 'Container.Update({})'.format(kodi_url)
xbmc.executebuiltin(builtin)
def LISTALL1(url):
kodi_url = pluginDir + '?mode=13&url={}'.format(urllib.quote_plus(url))
builtin = 'Container.Update({})'.format(kodi_url)
xbmc.executebuiltin(builtin)
def LISTALL2(url):
baseurl = url
content = utils.grab_url(url)
# Get max page number
matchc = re.compile('class="pages">Page (.+?) of (.+?)</span>').findall(content)
lastp = int(matchc[0][1])
progress = xbmcgui.DialogProgress()
progress.create('Progress', 'Listing all videos...')
for i in range(1, lastp + 1):
percent = int( (100 / lastp) * i)
message = "Scraping page " + str(i) + " out of " + str(lastp)
progress.update( percent, "", message, "" )
xbmc.sleep( 1000 )
url = baseurl + '/page/' + str(i)
page_content = utils.grab_url(url)
video_info = utils.scrape_data(page_content)
for url, name, thumbnail, plot in video_info:
addLink(name, url, 4, thumbnail, plot)
if progress.iscanceled():
break
progress.close()
def addInfo(curp, lastp, show_url):
liz = xbmcgui.ListItem('[COLOR yellow]Page ' + curp + ' of ' + lastp + '[/COLOR]')
liz.setProperty('IsPlayable', 'false')
RunPlugin1 = 'RunPlugin({}?mode=11&url={}&max_page={})'.format(sys.argv[0], urllib.quote_plus(show_url), lastp)
RunPlugin2 = 'RunPlugin({}?mode=12&url={})'.format(sys.argv[0], urllib.quote_plus(show_url))
# Only Display List all function if not a search result and if first page
no_list_all = ['/?s=', '/page/']
if any(x in urllib.unquote_plus(show_url) for x in no_list_all) or (int(lastp) > 100):
liz.addContextMenuItems([('Jump to page', RunPlugin1,),])
else:
liz.addContextMenuItems([('Jump to page', RunPlugin1,), ('List all', RunPlugin2,)])
return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=None, listitem=liz)
def addLink(name, url, mode, iconimage, plot='Plot Info', episode=None, date=None, show_url=None, max_page=None):
u = sys.argv[0] + "?url=" + urllib.quote_plus(url) + "&mode=" + str(mode) + "&name=" + urllib.quote_plus(name)
ok = True
liz = xbmcgui.ListItem(utils.cleanName(name), iconImage="DefaultVideo.png", thumbnailImage=iconimage)
if date and episode:
labels = {"Title": utils.cleanName(name), "Plot" : utils.cleanName(plot), "Season": '0', "Episode": str(episode), "Aired" : utils.convert_airdate(date, 'aired')}
xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
elif date:
labels = {"Title": utils.cleanName(name), "Plot" : utils.cleanName(plot), "date" : utils.convert_airdate(date, 'date')}
else:
labels = {"Title": utils.cleanName(name), "plot" : utils.cleanName(plot)}
liz.setInfo(type="Video", infoLabels=labels)
liz.setProperty('IsPlayable', 'true')
if show_url and max_page:
RunPlugin = 'RunPlugin({}?mode=11&url={}&max_page={})'.format(sys.argv[0], urllib.quote_plus(show_url), str(max_page))
liz.addContextMenuItems([('Jump to page', RunPlugin,),])
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz)
return ok
def addDir(name, url, mode, iconimage, dirmode=None): # Standard
u = sys.argv[0] + "?url=" + urllib.quote_plus(url) + "&mode=" + str(mode) + "&name=" + urllib.quote_plus(name)
ok = True
liz = xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
#liz.setInfo(type="Video", infoLabels={"Title": name})
if dirmode == 'allshows': # All Shows
add_db_cmd = 'MODE:ADD;NAME:{};URL:{}'.format(urllib.quote_plus(name), urllib.quote_plus(url))
add_fav_cmd = 'MODE:ADD;NAME:{};URL:{}'.format(urllib.quote_plus(name), urllib.quote_plus(url))
RunPlugin1 = 'RunPlugin({}?mode=9&db_arg={})'.format(sys.argv[0], add_db_cmd)
RunPlugin2 = 'RunPlugin({}?mode=6&fav_arg={})'.format(sys.argv[0], add_fav_cmd)
liz.addContextMenuItems([('Add content to DB', RunPlugin1,), ('Add addon Favorites', RunPlugin2,)])
if dirmode == 'favorites': # Addon Favorites
rem_fav_cmd = 'MODE:REMOVE;NAME:{};URL:{}'.format(urllib.quote_plus(name), urllib.quote_plus(url))
RunPlugin = 'RunPlugin({}?mode=6&fav_arg={})'.format(sys.argv[0], rem_fav_cmd)
liz.addContextMenuItems([('Remove from Addon Favorites', RunPlugin,)])
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=True)
return ok
def addDBShow(name, db_table, mode, iconimage, show_url): # Directories in local DB
u = sys.argv[0] + "?db_table=" + urllib.quote_plus(db_table) + "&mode=" + str(mode) + "&name=" + urllib.quote_plus(name)
ok = True
liz = xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo(type="Video", infoLabels={"Title": name})
upd_db_cmd = 'MODE:UPDATE;NAME:{};URL:{}'.format(urllib.quote_plus(name), urllib.quote_plus(show_url))
rem_db_cmd = 'MODE:REMOVE;NAME:{};URL:{}'.format(urllib.quote_plus(name), urllib.quote_plus(show_url))
RunPlugin1 = 'RunPlugin({}?mode=9&db_arg={})'.format(sys.argv[0], upd_db_cmd)
RunPlugin2 = 'RunPlugin({}?mode=9&db_arg={})'.format(sys.argv[0], rem_db_cmd)
liz.addContextMenuItems([('Update this show', RunPlugin1,), ('Remove from local DB', RunPlugin2,)])
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=True)
return ok
def showText(heading, text):
id = 10147
xbmc.executebuiltin('ActivateWindow({})'.format(id))
xbmc.sleep(100)
win = xbmcgui.Window(id)
retry = 50
while (retry > 0):
try:
xbmc.sleep(10)
retry -= 1
win.getControl(1).setLabel(heading)
win.getControl(5).setText(text)
return
except:
pass
# Get Bool Settings
def get_bool_settings(id):
if addon.getSetting(id=id) == 'true':
return True
else:
return False
params = utils.get_params()
url = None
name = None
mode = None
max_page = None
fav_arg = None
db_arg = None
db_table = None
try:
url = urllib.unquote_plus(params["url"])
except:
pass
try:
name = urllib.unquote_plus(params["name"])
except:
pass
try:
mode = int(params["mode"])
except:
pass
try:
db_table = urllib.unquote_plus(params["db_table"])
except:
pass
try:
max_page = int(params["max_page"])
except:
pass
try:
fav_arg = urllib.unquote_plus(params["fav_arg"])
except:
pass
try:
db_arg = urllib.unquote_plus(params["db_arg"])
except:
pass
print "Mode: " + str(mode)
print "URL: " + str(url)
print "Name: " + str(name)
print "DB Table: " + str(db_table)
print "Fav. Arg.: " + str(fav_arg)
print "DB Arg.: " + str(db_arg)
if mode == None: # Function to display main view
print "Main View"
CATEGORIES()
elif mode == 1: # Function di List all available shows linked on the main page
print "All Shows"
ALLSHOWS(url)
elif mode == 2: # Function to List Videos on a page
print "List Videos: " + url
LISTVIDEOS(url)
elif mode == 3: # Function to resolve video links
print "Resolve Link: " + url
RESOLVELINK(url)
elif mode == 4: # Function to search site
print "" + name
SEARCHSITE(name)
elif mode == 5: # Function to display addon favorites
print "" + name
DISPLAY_FAVS()
elif mode == 6: # Function to edit favorites
print "Edit Favorites"
EDIT_FAVS(fav_arg)
elif mode == 7: # Function to list all shows in db
print "" + name
DISPLAY_DB()
elif mode == 8: # Function to Display a show in DB
print "Display DB Show: " + name
DISPLAY_DB_SHOW(db_table)
elif mode == 9: # Function to modifiy shows stored in local db
print "Edit Database"
EDIT_DB(db_arg)
elif mode == 10: # Function to remove local DB
print "Clear DB"
CLEAR_DB()
elif mode == 11: # Function to jump to a certain page
print "Jump to page"
JUMPTO(url, max_page)
elif mode == 12: # Function to initialize LIST ALL Function
LISTALL1(url)
elif mode == 13: # Function to list all videos of a show
LISTALL2(url)
xbmcplugin.endOfDirectory(int(sys.argv[1]))