forked from bstrdsmkr/1Channel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.py
2029 lines (1741 loc) · 97.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
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
1Channel XBMC Addon
Copyright (C) 2012 Bstrdsmkr
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/>.
"""
# pylint: disable=C0301
# pylint: disable=F0401
# pylint: disable=W0621
import re
import os
import sys
import json
import string
import urllib
import datetime
import metapacks
import xbmc
import xbmcgui
import xbmcvfs
import xbmcaddon
import xbmcplugin
from addon.common.addon import Addon
try: from metahandler import metahandlers
except: xbmc.executebuiltin("XBMC.Notification(%s,%s,2000)" % ('Import Failed','metahandler')); pass
import utils
from urllib2 import HTTPError
from pw_scraper import PW_Scraper, PW_Error
from db_utils import DB_Connection
from pw_dispatcher import PW_Dispatcher
from utils import MODES
from utils import SUB_TYPES
import gui_utils
global urlresolver
_1CH = Addon('plugin.video.1channel', sys.argv)
META_ON = _1CH.get_setting('use-meta') == 'true'
FANART_ON = _1CH.get_setting('enable-fanart') == 'true'
USE_POSTERS = _1CH.get_setting('use-posters') == 'true'
POSTERS_FALLBACK = _1CH.get_setting('posters-fallback') == 'true'
THEME_LIST = ['Classic', 'Glossy_Black', 'PrimeWire', 'Firestorm']
THEME = THEME_LIST[int(_1CH.get_setting('theme'))]
if xbmc.getCondVisibility('System.HasAddon(script.1channel.themepak)'):
themepak_path = xbmcaddon.Addon('script.1channel.themepak').getAddonInfo('path')
else:
themepak_path=''
THEME_PATH = os.path.join(themepak_path, 'art', 'themes', THEME)
ICON_PATH = os.path.join(_1CH.get_path(), 'icon.png')
FAV_ACTIONS = utils.enum(ADD='add', REMOVE='remove')
PL_SORT = ['added', 'alphabet', 'popularity']
REMOVE_TW_MENU='Remove from ToWatch List'
REMOVE_W_MENU='Remove from Watched list'
REMOVE_FAV_MENU='Remove from Favorites'
pw_scraper = PW_Scraper(_1CH.get_setting("username"),_1CH.get_setting("passwd"))
db_connection = DB_Connection()
pw_dispatcher = PW_Dispatcher()
__metaget__ = metahandlers.MetaData()
if not xbmcvfs.exists(_1CH.get_profile()):
try: xbmcvfs.mkdirs(_1CH.get_profile())
except: os.mkdir(_1CH.get_profile())
def art(name):
path = os.path.join(THEME_PATH, name)
if not xbmcvfs.exists(path):
path = path.replace('.png','.jpg')
return path
@pw_dispatcher.register(MODES.SAVE_FAV, ['fav_type', 'title', 'url'], ['year'])
def save_favorite(fav_type, title, url, year=''):
if fav_type != 'tv': fav_type = 'movie'
utils.log('Saving Favorite type: %s name: %s url: %s year: %s' % (fav_type, title, url, year))
try:
if utils.website_is_integrated():
pw_scraper.add_favorite(url)
else:
db_connection.save_favorite(fav_type, title, url, year)
builtin = 'XBMC.Notification(PrimeWire, %s added to Favorites, 5000, %s)'
except:
builtin = 'XBMC.Notification(PrimeWire,%s already in Favorites, 5000, %s)'
xbmc.executebuiltin(builtin % (title, ICON_PATH))
xbmc.executebuiltin('Container.Refresh')
@pw_dispatcher.register(MODES.DEL_FAV, ['url'])
def delete_favorite(url):
utils.log('Deleting Favorite: %s' % (url))
if utils.website_is_integrated():
pw_scraper.delete_favorite(url)
else:
db_connection.delete_favorite(url)
builtin = 'XBMC.Notification(PrimeWire, Favorite Removed, 3000, %s)'
xbmc.executebuiltin(builtin % ICON_PATH)
xbmc.executebuiltin('Container.Refresh')
# returns true if user chooses to resume, else false
def get_resume_choice(url):
question = 'Resume from %s' % (utils.format_time(db_connection.get_bookmark(url)))
return xbmcgui.Dialog().yesno('Resume?', question, '', '', 'Start from beginning', 'Resume')==1
@pw_dispatcher.register(MODES.GET_SOURCES, ['url', 'title'], ['year', 'img', 'imdbnum', 'dialog'])
def get_sources(url, title, year='', img='', imdbnum='', dialog=None, respect_auto=True):
url = urllib.unquote(url)
utils.log('Getting sources from: %s' % url)
primewire_url = url
resume = False
if db_connection.bookmark_exists(url):
resume = get_resume_choice(url)
pattern = r'tv-\d{1,10}-(.*)/season-(\d{1,4})-episode-(\d{1,4})'
match = re.search(pattern, url, re.IGNORECASE | re.DOTALL)
if match:
video_type = 'episode'
season = int(match.group(2))
episode = int(match.group(3))
else:
video_type = 'movie'
season = ''
episode = ''
if META_ON and video_type == 'movie' and not imdbnum:
imdbnum=pw_scraper.get_last_imdbnum()
__metaget__.update_meta('movie', title, imdb_id='',new_imdb_id=imdbnum, year=year)
_img = xbmc.getInfoImage('ListItem.Thumb')
if _img != "":
img = _img
hosters=pw_scraper.get_sources(url)
if not hosters:
_1CH.show_ok_dialog(['No sources were found for this item'], title='PrimeWire')
return
dbid=get_dbid(video_type, title, season, episode, year)
# auto play is on
if respect_auto and _1CH.get_setting('auto-play')=='true':
auto_try_sources(hosters, title, img, year, imdbnum, video_type, season, episode, primewire_url, resume, dbid)
else: # autoplay is off, or respect_auto is False
# dialog is either True, False or None -- source-win is either Dialog or Directory
# If dialog is forced, or there is no force and it's set to dialog use the dialog
if dialog or (dialog is None and _1CH.get_setting('source-win') == 'Dialog'):
if _1CH.get_setting('filter-source') == 'true':
play_filtered_dialog(hosters, title, img, year, imdbnum, video_type, season, episode, primewire_url, resume, dbid)
else:
play_unfiltered_dialog(hosters, title, img, year, imdbnum, video_type, season, episode, primewire_url, resume, dbid)
# if dialog is forced off (0), or it's None, but source-win is Directory, then use a directory
else:
if _1CH.get_setting('filter-source') == 'true':
play_filtered_dir(hosters, title, img, year, imdbnum, video_type, season, episode, primewire_url, resume)
else:
play_unfiltered_dir(hosters, title, img, year, imdbnum, video_type, season, episode, primewire_url, resume)
def get_dbid(video_type, title, season='', episode='', year=''):
dbid=0
filter=''
#variable used to match title with closest len, if there is more than one match, the one with the closest title length is the winner,
#The Middle and Malcolm in the Middle in the same library would still match the corret title. Starts at high value and lowers
max_title_len_diff=1000
titleComp2=re.sub('[^a-zA-Z0-9]+','',title).lower()
#if it's a movie check if the titles match in the library, then pull the movieid
if video_type == 'movie':
if year: filter = '"filter": {"field": "year", "operator": "is", "value": "%s"},' % year
json_string = '{"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.GetMovies", "params": {%s "properties": ["title"], "limits": {"end": 10000}}}' % filter
result_key="movies"
id_key="movieid"
title_key="title"
#if it'a a tvshow episode filter out all tvshows which contain said season and episode, then match tvshow title
if video_type == 'episode':
filter = '"filter": {"and":['
if year: filter += '{"field": "year", "operator": "is", "value": "%s"},' % year
filter+='{"field": "season", "operator": "is", "value": "%s"},' % season
filter+='{"field": "episode", "operator": "is", "value": "%s"}]},' % episode
json_string = '{"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.GetEpisodes", "params": {%s "properties": ["showtitle"], "limits": {"end": 10000}}}' % (filter)
result_key="episodes"
id_key="episodeid"
title_key="showtitle"
result=xbmc.executeJSONRPC(json_string)
resultObj=json.loads(result)
if not ('result' in resultObj and result_key in resultObj['result']): return None
for item in resultObj['result'][result_key]:
#converts titles to only alpha numeric, then compares smallest title to largest title, for example
#'Adventure Time' would match to 'Adventure tIME with FiNn and Jake_ (en) (4214)'
titleComp1=re.sub('[^a-zA-Z0-9]+','',item[title_key]).lower()
found_match=0
if len(titleComp1)>len(titleComp2):
if titleComp2 in titleComp1: found_match=1
else:
if titleComp1 in titleComp2: found_match=1
if found_match:
title_len_diff=abs(len(titleComp1)-len(titleComp2))
if title_len_diff<=max_title_len_diff:
max_title_len_diff=title_len_diff
if video_type == 'movie':
dbid=item[id_key]
utils.log('successfully matched dbid to movieid %s' % (dbid), xbmc.LOGDEBUG)
if video_type == 'episode':
dbid=item[id_key]
utils.log('successfully matched dbid to episodeid %s' % (dbid), xbmc.LOGDEBUG)
if dbid:
return dbid
else:
utils.log('Failed to recover dbid, type: %s, title: %s, season: %s, episode: %s' % (video_type, title, season, episode), xbmc.LOGDEBUG)
return None
def play_filtered_dialog(hosters, title, img, year, imdbnum, video_type, season, episode, primewire_url, resume, dbid):
sources=[]
for item in hosters:
try:
label = utils.format_label_source(item)
hosted_media = urlresolver.HostedMediaFile(url=item['url'], title=label)
sources.append(hosted_media)
if item['multi-part']:
partnum = 2
for _ in item['parts']:
label = utils.format_label_source_parts(item, partnum)
hosted_media = urlresolver.HostedMediaFile(url=item['parts'][partnum - 2], title=label)
sources.append(hosted_media)
partnum += 1
except:
utils.log('Error while trying to resolve %s' % item['url'], xbmc.LOGERROR)
source = urlresolver.choose_source(sources)
if source:
source=source.get_url()
else:
return
PlaySource(source, title, video_type, primewire_url, resume, imdbnum, year, season, episode, dbid)
def play_unfiltered_dialog(hosters, title, img, year, imdbnum, video_type, season, episode, primewire_url, resume, dbid):
sources=[]
for item in hosters:
label = utils.format_label_source(item)
sources.append(label)
dialog = xbmcgui.Dialog()
index = dialog.select('Choose your stream', sources)
if index > -1:
PlaySource(hosters[index]['url'], title,video_type, primewire_url, resume, imdbnum, year, season, episode, dbid)
else:
return
def play_filtered_dir(hosters, title, img, year, imdbnum, video_type, season, episode, primewire_url, resume):
hosters_len = len(hosters)
for item in hosters:
#utils.log(item)
hosted_media = urlresolver.HostedMediaFile(url=item['url'])
if hosted_media:
label = utils.format_label_source(item)
_1CH.add_directory({'mode': MODES.PLAY_SOURCE, 'url': item['url'], 'title': title,
'img': img, 'year': year, 'imdbnum': imdbnum,
'video_type': video_type, 'season': season, 'episode': episode, 'primewire_url': primewire_url, 'resume': resume},
infolabels={'title': label}, properties={'resumeTime': str(0), 'totalTime': str(1)}, is_folder=False, img=img, fanart=art('fanart.png'), total_items=hosters_len)
if item['multi-part']:
partnum = 2
for part in item['parts']:
label = utils.format_label_source_parts(item, partnum)
partnum += 1
_1CH.add_directory({'mode': MODES.PLAY_SOURCE, 'url': part, 'title': title,
'img': img, 'year': year, 'imdbnum': imdbnum,
'video_type': video_type, 'season': season, 'episode': episode, 'primewire_url': primewire_url, 'resume': resume},
infolabels={'title': label}, properties={'resumeTime': str(0), 'totalTime': str(1)}, is_folder=False, img=img,
fanart=art('fanart.png'), total_items=hosters_len)
else:
utils.log('Skipping unresolvable source: %s' % (item['url']), xbmc.LOGWARNING)
_1CH.end_of_directory()
def play_unfiltered_dir(hosters, title, img, year, imdbnum, video_type, season, episode, primewire_url, resume):
hosters_len=len(hosters)
for item in hosters:
#utils.log(item)
label = utils.format_label_source(item)
_1CH.add_directory({'mode': MODES.PLAY_SOURCE, 'url': item['url'], 'title': title,
'img': img, 'year': year, 'imdbnum': imdbnum,
'video_type': video_type, 'season': season, 'episode': episode, 'primewire_url': primewire_url, 'resume': resume},
infolabels={'title': label}, properties={'resumeTime': str(0), 'totalTime': str(1)}, is_folder=False, img=img, fanart=art('fanart.png'), total_items=hosters_len)
if item['multi-part']:
partnum = 2
for part in item['parts']:
label = utils.format_label_source_parts(item, partnum)
partnum += 1
_1CH.add_directory({'mode': MODES.PLAY_SOURCE, 'url': part, 'title': title,
'img': img, 'year': year, 'imdbnum': imdbnum,
'video_type': video_type, 'season': season, 'episode': episode, 'primewire_url': primewire_url, 'resume': resume},
infolabels={'title': label}, properties={'resumeTime': str(0), 'totalTime': str(1)}, is_folder=False, img=img,
fanart=art('fanart.png'), total_items=hosters_len)
_1CH.end_of_directory()
def auto_try_sources(hosters, title, img, year, imdbnum, video_type, season, episode, primewire_url, resume, dbid):
dlg = xbmcgui.DialogProgress()
line1 = 'Trying Source: '
dlg.create('PrimeWire')
total = len(hosters)
count = 1
success = False
while not (success or dlg.iscanceled() or xbmc.abortRequested):
for source in hosters:
if dlg.iscanceled(): return
percent = int((count * 100) / total)
label = utils.format_label_source(source)
dlg.update(percent, '', line1 + label)
utils.log('Trying Source: %s' % (source['host']), xbmc.LOGDEBUG)
if not PlaySource(source['url'], title, video_type, primewire_url, resume, imdbnum, year, season, episode, dbid):
dlg.update(percent, 'Playback Failed: %s' % (label), line1 + label)
utils.log('Source Failed: %s' % (source['host']), xbmc.LOGWARNING)
count += 1
else:
success = True
break # Playback was successful, break out of the loop
else:
utils.log('All sources failed to play', xbmc.LOGERROR)
dlg.close()
_1CH.show_ok_dialog(['All Sources Failed to Play'], title='PrimeWire')
break
@pw_dispatcher.register(MODES.PLAY_SOURCE, ['url', ' title', 'video_type', 'primewire_url', 'resume'], ['imdbnum', 'year', 'season', 'episode'])
def PlaySource(url, title, video_type, primewire_url, resume, imdbnum='', year='', season='', episode='', dbid=None):
utils.log('Attempting to play url: %s' % url)
stream_url = urlresolver.HostedMediaFile(url=url).resolve()
#If urlresolver returns false then the video url was not resolved.
if not stream_url or not isinstance(stream_url, basestring):
return False
win = xbmcgui.Window(10000)
win.setProperty('1ch.playing.title', title)
win.setProperty('1ch.playing.year', year)
win.setProperty('1ch.playing.imdb', imdbnum)
win.setProperty('1ch.playing.season', str(season))
win.setProperty('1ch.playing.episode', str(episode))
win.setProperty('1ch.playing.url',primewire_url)
#metadata is enabled
if META_ON:
if not dbid or int(dbid) <= 0:
#we're not playing from a library item
if video_type == 'episode':
meta = __metaget__.get_episode_meta(title, imdbnum, season, episode)
meta['TVShowTitle'] = title
meta['title'] = utils.format_tvshow_episode(meta)
elif video_type == 'movie':
meta = __metaget__.get_meta('movie', title, year=year)
meta['title'] = utils.format_label_movie(meta)
else: #metadata is not enabled
if video_type == 'episode':
meta = {'label': title, 'TVShowTitle': title, 'year': year, 'season': int(season), 'episode': int(episode), 'title': '%sx%s' % (season, episode)}
else:
meta = {'label' : title, 'title' : title, 'year': year}
if dbid and int(dbid) > 0:
#we're playing from a library item
if video_type == 'episode':
cmd = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"episodeid" : %s, "properties" : ["title", "plot", "votes", "rating", "writer", "firstaired", "playcount", "runtime", "director", "productioncode", "season", "episode", "originaltitle", "showtitle", "lastplayed", "fanart", "thumbnail", "dateadded", "art"]}, "id": 1}'
cmd = cmd %(dbid)
meta = xbmc.executeJSONRPC(cmd)
meta = json.loads(meta)
meta = meta['result']['episodedetails']
meta['TVShowTitle'] = meta['showtitle']
meta['duration'] = meta['runtime']
meta['premiered'] = meta['firstaired']
meta['DBID']=dbid
meta['backdrop_url']=meta['fanart']
meta['cover_url']=meta['thumbnail']
if 'art' in meta:
meta['banner_url']=meta['art']['tvshow.banner']
del meta['art']
if video_type == 'movie':
cmd = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"movieid" : %s, "properties" : ["title", "plot", "votes", "rating", "writer", "playcount", "runtime", "director", "originaltitle", "lastplayed", "fanart", "thumbnail", "file", "year", "dateadded"]}, "id": 1}'
cmd = cmd %(dbid)
meta = xbmc.executeJSONRPC(cmd)
meta = json.loads(meta)
meta = meta['result']['moviedetails']
meta['duration'] = meta['runtime']
meta['DBID']=dbid
meta['backdrop_url']=meta['fanart']
meta['cover_url']=meta['thumbnail']
win = xbmcgui.Window(10000)
win.setProperty('1ch.playing', json.dumps(meta))
art=make_art(video_type, meta)
listitem = xbmcgui.ListItem(path=url, iconImage=art['thumb'], thumbnailImage=art['thumb'])
listitem.setProperty('fanart_image', art['fanart'])
try: listitem.setArt(art)
except: pass # method doesn't exist in Frodo
resume_point=0
if resume:
resume_point = db_connection.get_bookmark(primewire_url)
utils.log("Playing Video from: %s secs" % (resume_point), xbmc.LOGDEBUG)
listitem.setProperty('ResumeTime', str(resume_point))
listitem.setProperty('Totaltime', str(99999)) # dummy value to force resume to work
listitem.setProperty('IsPlayable', 'true')
listitem.setInfo(type = "Video", infoLabels = meta)
if _1CH.get_setting('enable-axel')=='true':
utils.log('Using Axel Downloader', xbmc.LOGDEBUG)
try:
download_name=title
if season and episode: download_name += ' %sx%s' % (season,episode)
import axelproxy as proxy
axelhelper = proxy.ProxyHelper()
stream_url, download_id = axelhelper.create_proxy_url(stream_url, name=download_name)
win.setProperty('download_id', str(download_id))
utils.log('Axel Downloader: stream_url: %s, download_id: %s' % (stream_url, download_id), xbmc.LOGDEBUG)
except:
message='Axel [COLOR blue]ENABLED[/COLOR] but [COLOR red]NOT INSTALLED[/COLOR]'
xbmc.executebuiltin("XBMC.Notification(%s,%s,10000, %s)" % ('Axel Downloader',message, ICON_PATH))
listitem.setPath(stream_url)
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
return True
@pw_dispatcher.register(MODES.CH_WATCH, ['video_type', 'title', 'primewire_url', 'watched'], ['imdbnum', 'season', 'episode', 'year', 'dbid'])
def change_watched(video_type, title, primewire_url , watched, imdbnum='', season='', episode='', year='', dbid=None):
if watched==True:
overlay=7
whattodo='add'
else:
whattodo='delete'
overlay=6
# meta['dbid'] only gets set for strms
if dbid and int(dbid) > 0:
if video_type == 'episode':
cmd = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"episodeid": %s, "properties": ["playcount"]}, "id": 1}'
cmd = cmd %(dbid)
result = json.loads(xbmc.executeJSONRPC(cmd))
cmd = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": {"episodeid": %s, "playcount": %s}, "id": 1}'
playcount = int(result['result']['episodedetails']['playcount']) + 1 if watched == True else 0
cmd = cmd %(dbid, playcount)
result = xbmc.executeJSONRPC(cmd)
xbmc.log('PrimeWire: Marking episode .strm as watched: %s' %result)
if video_type == 'movie':
cmd = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"movieid": %s, "properties": ["playcount"]}, "id": 1}'
cmd = cmd %(dbid)
result = json.loads(xbmc.executeJSONRPC(cmd))
cmd = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": {"movieid": %s, "playcount": %s}, "id": 1}'
playcount = int(result['result']['moviedetails']['playcount']) + 1 if watched == True else 0
cmd = cmd %(dbid, playcount)
result = xbmc.executeJSONRPC(cmd)
xbmc.log('PrimeWire: Marking movie .strm as watched: %s' %result)
__metaget__.change_watched(video_type, title, imdbnum, season=season, episode=episode, year=year, watched=overlay)
if utils.website_is_integrated():
change_watched_website(primewire_url, whattodo, refresh=False)
xbmc.executebuiltin("XBMC.Container.Refresh")
@pw_dispatcher.register(MODES.CH_WATCH_WEB, ['primewire_url', 'action'], ['refresh'])
def change_watched_website( primewire_url , action, refresh = True):
if utils.website_is_integrated():
pw_scraper.change_watched(primewire_url, "watched", action)
if refresh: xbmc.executebuiltin("XBMC.Container.Refresh")
@pw_dispatcher.register(MODES.CH_TOWATCH_WEB, ['primewire_url', 'action'], ['refresh'])
def change_towatch_website( primewire_url , action, refresh = True):
if utils.website_is_integrated():
pw_scraper.change_watched(primewire_url, "towatch", action)
if refresh: xbmc.executebuiltin("XBMC.Container.Refresh")
@pw_dispatcher.register(MODES.PLAY_TRAILER, ['url'])
def PlayTrailer(url):
url = url.decode('base-64')
url = 'http://www.youtube.com/watch?v=%s&hd=1' % (url)
utils.log('Attempting to resolve and play trailer at %s' % url)
sources = []
hosted_media = urlresolver.HostedMediaFile(url=url)
sources.append(hosted_media)
source = urlresolver.choose_source(sources)
stream_url = source.resolve() if source else ''
xbmc.Player().play(stream_url)
@pw_dispatcher.register(MODES.SEARCH_QUERY, ['section', 'next_mode'])
@pw_dispatcher.register(MODES.DESC_QUERY, ['section', 'next_mode'])
def GetSearchQuery(section, next_mode):
paginate=(_1CH.get_setting('paginate-search')=='true' and _1CH.get_setting('paginate')=='true')
keyboard = xbmc.Keyboard()
if section == 'tv':
keyboard.setHeading('Search TV Shows')
else:
keyboard.setHeading('Search Movies')
while True:
keyboard.doModal()
if keyboard.isConfirmed():
search_text = keyboard.getText()
if not paginate and not search_text:
_1CH.show_ok_dialog(['Blank searches are not allowed unless [B]Paginate Search Results[/B] is enabled.'], title='PrimeWire')
return
else:
break
else:
break
if keyboard.isConfirmed():
if search_text.startswith('!#'):
if search_text == '!#create metapacks': metapacks.create_meta_packs()
if search_text == '!#repair meta': repair_missing_images()
if search_text == '!#install all meta': metapacks.install_all_meta()
if search_text.startswith('!#sql:'):
utils.log('Running SQL: |%s|' % (search_text[6:]), xbmc.LOGDEBUG)
db_connection.execute_sql(search_text[6:])
else:
queries = {'mode': next_mode, 'section': section, 'query': keyboard.getText()}
pluginurl = _1CH.build_plugin_url(queries)
builtin = 'Container.Update(%s)' %(pluginurl)
xbmc.executebuiltin(builtin)
else:
BrowseListMenu(section)
@pw_dispatcher.register(MODES.ADV_QUERY, ['section'])
def GetSearchQueryAdvanced(section):
try:
query=gui_utils.get_adv_search_query(section)
js_query=json.dumps(query)
queries = {'mode': MODES.SEARCH_ADV, 'section': section, 'query': js_query}
pluginurl = _1CH.build_plugin_url(queries)
builtin = 'Container.Update(%s)' %(pluginurl)
xbmc.executebuiltin(builtin)
except:
BrowseListMenu(section)
@pw_dispatcher.register(MODES.SEARCH, ['mode', 'section'], ['query', 'page'])
@pw_dispatcher.register(MODES.SEARCH_DESC, ['mode', 'section'], ['query', 'page'])
@pw_dispatcher.register(MODES.SEARCH_ADV, ['mode', 'section'], ['query', 'page'])
@pw_dispatcher.register(MODES.REMOTE_SEARCH, ['section'], ['query'])
def Search(mode, section, query='', page=None):
section_params = get_section_params(section)
paginate=(_1CH.get_setting('paginate-search')=='true' and _1CH.get_setting('paginate')=='true')
try:
if mode==MODES.SEARCH:
results=pw_scraper.search(section,query, page, paginate)
elif mode==MODES.SEARCH_DESC:
results=pw_scraper.search_desc(section,query, page, paginate)
elif mode==MODES.SEARCH_ADV:
criteria = utils.unpack_query(query)
results=pw_scraper.search_advanced(section, criteria['title'], criteria['tag'], False, criteria['country'], criteria['genre'],
criteria['actor'], criteria['director'], criteria['year'], criteria['month'], criteria['decade'], page=page, paginate=paginate)
except PW_Error:
message='Site Blocked? Unexpected page received.'
xbmc.executebuiltin("XBMC.Notification(%s,%s,10000, %s)" % ('PrimeWire',message, ICON_PATH))
return
total_pages = pw_scraper.get_last_res_pages()
total=pw_scraper.get_last_res_total()
if paginate:
if page != total_pages:
total=PW_Scraper.ITEMS_PER_PAGE
else:
total=total % PW_Scraper.ITEMS_PER_PAGE
resurls = []
for result in results:
if result['url'] not in resurls:
resurls.append(result['url'])
create_item(section_params,result['title'],result['year'],result['img'],result['url'],totalItems=total)
if not page: page = 1
next_page = int(page) + 1
if int(page) < int(total_pages) and paginate:
label = 'Skip to Page...'
command = _1CH.build_plugin_url(
{'mode': MODES.SEARCH_PAGE_SELECT, 'pages': total_pages, 'query': query, 'search': mode, 'section': section})
command = 'RunPlugin(%s)' % command
menu_items = [(label, command)]
meta = {'title': 'Next Page >>'}
_1CH.add_directory(
{'mode': mode, 'query': query, 'page': next_page, 'section': section},
meta, contextmenu_items=menu_items, context_replace=True, img=art('nextpage.png'), fanart=art('fanart.png'), is_folder=True)
utils.set_view(section_params['content'], '%s-view' % (section_params['content']))
_1CH.end_of_directory()
# temporary method to fix bad urls
def fix_urls():
tables = ['favorites', 'subscriptions', 'external_subs']
for table in tables:
# remove any possible dupes
while True:
rows = db_connection.execute_sql("SELECT url from %s GROUP BY REPLACE(url,'-online-free','') HAVING COUNT(*)>1" % (table))
if rows:
db_connection.execute_sql("DELETE FROM %s WHERE url in (SELECT * FROM (SELECT url from %s GROUP BY REPLACE(url,'-online-free','') HAVING COUNT(*)>1) as t)" % (table, table))
else:
break
# strip the -online-free part of the url off
db_connection.execute_sql("UPDATE %s SET url=REPLACE(url,'-online-free','') WHERE SUBSTR(url, -12)='-online-free'" % (table))
@pw_dispatcher.register(MODES.MAIN)
def AddonMenu(): # homescreen
utils.log('Main Menu')
db_connection.init_database()
fix_urls()
if utils.has_upgraded():
utils.log('Showing update popup', xbmc.LOGDEBUG)
if _1CH.get_setting('show_splash')=='true':
msg = ('The 1Channel/PrimeWire addon is developed and supported by the team at [COLOR white]www.tvaddons.ag[/COLOR]\n\n'
'If you are having issues with the addon, visit our Forums for help. We also invite you to visit us regularly to show your support.\n\n'
'[I](This message is [B]only[/B] shown when the 1Channel addon is first installed or updated.)[/I]')
gui_utils.do_My_TextSplash(msg, HowLong=20, TxtColor='0xFF00FF00', BorderWidth=45)
utils.TextBox()
adn = xbmcaddon.Addon('plugin.video.1channel')
adn.setSetting('domain', 'http://www.primewire.ag')
adn.setSetting('old_version', _1CH.get_version())
_1CH.add_directory({'mode': MODES.LIST_MENU, 'section': 'movie'}, {'title': 'Movies'}, img=art('movies.png'),
fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.LIST_MENU, 'section': 'tv'}, {'title': 'TV shows'}, img=art('television.png'),
fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.PLAYLISTS_MENU, 'section': 'playlist'}, {'title': 'Playlists'}, img=art('playlists.png'),
fanart=art('fanart.png'))
if _1CH.get_setting('h99_hidden')=='true':
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': 'tv', 'sort': 'date'}, {'title': 'TV - Date added'},img=art('date_added.png'), fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.MANAGE_SUBS}, {'title': 'TV - Subscriptions'}, img=art('subscriptions.png'),fanart=art('fanart.png'))
add_search_item({'mode': MODES.SEARCH_QUERY, 'section': 'tv', 'next_mode': MODES.SEARCH}, 'TV - Search')
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': 'movie', 'sort': 'date'}, {'title': 'Movies - Date added'},img=art('date_added.png'), fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': 'movie', 'sort': 'release'},{'title': 'Movies - Date released'}, img=art('date_released.png'), fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': 'movie', 'sort': 'featured'}, {'title': 'Movies - Featured'},img=art('featured.png'), fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': 'movie', 'sort': 'views'}, {'title': 'Movies - Most Popular'},img=art('most_popular.png'), fanart=art('fanart.png'))
add_search_item({'mode': MODES.SEARCH_QUERY, 'section': 'movie', 'next_mode': MODES.SEARCH}, 'Movies - Search')
if not xbmc.getCondVisibility('System.HasAddon(script.1channel.themepak)') and xbmc.getCondVisibility('System.HasAddon(plugin.program.addoninstaller)'):
_1CH.add_directory({'mode': MODES.INSTALL_THEMES}, {'title': 'Install 1Channel Themes/Icons'}, img=art('settings.png'),fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.RES_SETTINGS}, {'title': 'Resolver Settings'}, img=art('settings.png'),
fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.HELP}, {'title': 'Help'}, img=art('help.png'), fanart=art('fanart.png'))
# _1CH.add_directory({'mode': 'test'}, {'title': 'Test'}, img=art('settings.png'), fanart=art('fanart.png'))
utils.set_view('list', '%s-view' % ('default'))
xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=False)
@pw_dispatcher.register(MODES.INSTALL_THEMES)
def install_themes():
addon='plugin://plugin.program.addoninstaller'
query={'mode': 'addoninstall', 'name': '1Channel.thempak', \
'url': 'https://offshoregit.com/tknorris/tknorris-release-repo/raw/master/zips/script.1channel.themepak/script.1channel.themepak-0.0.3.zip', \
'description': 'none', 'filetype': 'addon', 'repourl': 'none'}
run = 'RunPlugin(%s)' % (addon + '?' + urllib.urlencode(query))
xbmc.executebuiltin(run)
@pw_dispatcher.register(MODES.LIST_MENU, ['section'])
def BrowseListMenu(section):
utils.log('Browse Options')
_1CH.add_directory({'mode': MODES.AZ_MENU, 'section': section}, {'title': 'A-Z'}, img=art('atoz.png'),
fanart=art('fanart.png'))
add_search_item({'mode': MODES.SEARCH_QUERY, 'section': section, 'next_mode': MODES.SEARCH}, 'Search')
if utils.website_is_integrated():
_1CH.add_directory({'mode': MODES.BROWSE_FAVS_WEB, 'section': section}, {'title': 'Website Favourites'},
img=art('favourites.png'), fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.BROWSE_W_WEB, 'section': section}, {'title': 'Website Watched List'},
img=art('watched.png'), fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.BROWSE_TW_WEB, 'section': section}, {'title': 'Website To Watch List'},
img=art('towatch.png'), fanart=art('fanart.png'))
if section == 'tv':
_1CH.add_directory({'mode': MODES.SHOW_SCHEDULE}, {'title': 'My TV Schedule'}, img=art('schedule.png'),
fanart=art('fanart.png'))
else:
_1CH.add_directory({'mode': MODES.BROWSE_FAVS, 'section': section}, {'title': 'Favourites'},
img=art('favourites.png'), fanart=art('fanart.png'))
if section == 'tv':
_1CH.add_directory({'mode': MODES.MANAGE_SUBS}, {'title': 'Subscriptions'}, img=art('subscriptions.png'),
fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.GENRE_MENU, 'section': section}, {'title': 'Genres'}, img=art('genres.png'),
fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': section, 'sort': 'featured'}, {'title': 'Featured'},
img=art('featured.png'), fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': section, 'sort': 'views'}, {'title': 'Most Popular'},
img=art('most_popular.png'), fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': section, 'sort': 'ratings'}, {'title': 'Highly rated'},
img=art('highly_rated.png'), fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': section, 'sort': 'release'},
{'title': 'Date released'}, img=art('date_released.png'), fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': section, 'sort': 'date'}, {'title': 'Date added'},
img=art('date_added.png'), fanart=art('fanart.png'))
add_search_item({'mode': MODES.DESC_QUERY, 'section': section, 'next_mode': MODES.SEARCH_DESC}, 'Search (+Description)')
add_search_item({'mode': MODES.ADV_QUERY, 'section': section}, 'Search (Advanced Search)')
utils.set_view('list', '%s-view' % ('default'))
xbmcplugin.endOfDirectory(int(sys.argv[1]))
@pw_dispatcher.register(MODES.PLAYLISTS_MENU)
def playlist_menu():
utils.log('Playlist Menu')
_1CH.add_directory({'mode': MODES.BROWSE_PLAYLISTS, 'public': True, 'sort': 'date'}, {'title': 'Public Playlists (sorted by date)'}, img=art('public_playlists_date.png'),
fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.BROWSE_PLAYLISTS, 'public': True, 'sort': 'rating'}, {'title': 'Public Playlists (sorted by rating)'}, img=art('public_playlists_rating.png'),
fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.BROWSE_PLAYLISTS, 'public': True, 'sort': 'hits'}, {'title': 'Public Playlists (sorted by views)'}, img=art('public_playlists_views.png'),
fanart=art('fanart.png'))
if utils.website_is_integrated():
_1CH.add_directory({'mode': MODES.BROWSE_PLAYLISTS, 'public': False, 'sort': 'date'}, {'title': 'Personal Playlists (sorted by date)'}, img=art('personal_playlists_date.png'),
fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.BROWSE_PLAYLISTS, 'public': False, 'sort': 'rating'}, {'title': 'Personal Playlists (sorted by rating)'}, img=art('personal_playlists_rating.png'),
fanart=art('fanart.png'))
_1CH.add_directory({'mode': MODES.BROWSE_PLAYLISTS, 'public': False, 'sort': 'hits'}, {'title': 'Personal Playlists (sorted by views)'}, img=art('personal_playlists_views.png'),
fanart=art('fanart.png'))
utils.set_view('list', '%s-view' % ('default'))
xbmcplugin.endOfDirectory(int(sys.argv[1]))
@pw_dispatcher.register(MODES.BROWSE_PLAYLISTS, ['public'], ['sort', 'page'])
def browse_playlists(public,sort=None, page=None, paginate=True):
utils.log('Browse Playlists: public: |%s| sort: |%s| page: |%s| paginate: |%s|' % (public, sort, page, paginate))
playlists=pw_scraper.get_playlists(public, sort, page, paginate)
total_pages = pw_scraper.get_last_res_pages()
for playlist in playlists:
title = '%s (%s items) (%s views) (rating %s)' % (playlist['title'].encode('ascii', 'ignore'), playlist['item_count'], playlist['views'], playlist['rating'])
_1CH.add_directory({'mode': MODES.SHOW_PLAYLIST, 'url': playlist['url'], 'public': public}, {'title': title}, img=playlist['img'],fanart=art('fanart.png'))
if not page: page = 1
next_page = int(page)+1
if int(page) < int(total_pages) and paginate:
label = 'Skip to Page...'
command = _1CH.build_plugin_url(
{'mode': MODES.PL_PAGE_SELECT, 'section': 'playlist', 'pages': total_pages, 'public': public, 'sort': sort})
command = 'RunPlugin(%s)' % command
menu_items = [(label, command)]
meta = {'title': 'Next Page >>'}
_1CH.add_directory(
{'mode': MODES.BROWSE_PLAYLISTS, 'public': public, 'sort': sort, 'page': next_page},
meta, contextmenu_items=menu_items, context_replace=True, img=art('nextpage.png'), fanart=art('fanart.png'), is_folder=True)
utils.set_view('list', 'default-view')
xbmcplugin.endOfDirectory(int(sys.argv[1]))
@pw_dispatcher.register(MODES.SHOW_PLAYLIST, ['url', 'public'])
def show_playlist(url, public):
sort = PL_SORT[int(_1CH.get_setting('playlist-sort'))]
items=pw_scraper.show_playlist(url, public, sort)
# one playlist can contain both movies and tvshows so can't set the params for the whole playlist/section
item_params={}
item_params['subs'] = [row[0] for row in get_subscriptions()]
if utils.website_is_integrated():
item_params['fav_urls']=[]
else:
item_params['fav_urls']=get_fav_urls()
item_params['xbmc_fav_urls']=utils.get_xbmc_fav_urls()
for item in items:
item_params.update(get_item_params(item))
runstring = 'RunPlugin(%s)' % _1CH.build_plugin_url({'mode': MODES.RM_FROM_PL, 'playlist_url': url, 'item_url': item['url']})
menu_items = [('Remove from Playlist', runstring)]
create_item(item_params,item['title'],item['year'],item['img'],item['url'], menu_items=menu_items)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
@pw_dispatcher.register(MODES.ADD2PL, ['item_url'])
def add_to_playlist(item_url):
playlists=pw_scraper.get_playlists(False)
sel_list=[]
url_list=[]
for playlist in playlists:
title = '%s (%s items) (%s views) (rating %s)' % (playlist['title'], playlist['item_count'], playlist['views'], playlist['rating'])
sel_list.append(title)
url_list.append(playlist['url'])
if sel_list:
dialog=xbmcgui.Dialog()
ret = dialog.select('Select Playlist', sel_list)
if ret>-1:
try:
pw_scraper.add_to_playlist(url_list[ret], item_url)
message = 'Item added to playlist.'
except:
message = 'Error adding item to playlist.'
builtin = 'XBMC.Notification(PrimeWire,%s,4000, %s)'
xbmc.executebuiltin(builtin % (message,ICON_PATH))
else:
builtin = 'XBMC.Notification(PrimeWire,%s,4000, %s)'
xbmc.executebuiltin(builtin % ('Create a playlist on the website first.',ICON_PATH))
@pw_dispatcher.register(MODES.RM_FROM_PL, ['playlist_url', 'item_url'])
def remove_from_playlist(playlist_url, item_url):
pw_scraper.remove_from_playlist(playlist_url, item_url)
xbmc.executebuiltin('Container.Refresh')
# add searches as an items so they don't get added to the path history
# _1CH.add_item doesn't work because it insists on adding non-folder items as playable
def add_search_item(queries, label):
liz = xbmcgui.ListItem(label=label, iconImage=art('search.png'), thumbnailImage=art('search.png'))
liz.setProperty('IsPlayable', 'false')
liz.setProperty('fanart_image', art('fanart.png'))
liz.setInfo('video', {'title': label})
liz_url = _1CH.build_plugin_url(queries)
xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, liz, isFolder=False)
@pw_dispatcher.register(MODES.AZ_MENU, ['section'])
def BrowseAlphabetMenu(section=None):
utils.log('Browse by alphabet screen')
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': section, 'sort': 'alphabet', 'letter': '123'},
{'title': '#123'}, img=art('123.png'), fanart=art('fanart.png'))
for character in (ltr for ltr in string.ascii_uppercase):
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': section, 'sort': 'alphabet', 'letter': character},
{'title': character}, img=art(character.lower() + '.png'), fanart=art('fanart.png'))
xbmcplugin.endOfDirectory(int(sys.argv[1]))
@pw_dispatcher.register(MODES.GENRE_MENU, ['section'])
def BrowseByGenreMenu(section=None): #2000
utils.log('Browse by genres screen')
for genre in pw_scraper.get_genres():
_1CH.add_directory({'mode': MODES.FILTER_RESULTS, 'section': section, 'sort': 'date', 'genre': genre},
{'title': genre}, img=art(genre.lower() + '.png'))
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def add_contextsearchmenu(title, video_type):
contextmenuitems = []
nameonly=utils.filename_filter_out_year(title); #print 'nameonly: '+nameonly
if os.path.exists(xbmc.translatePath("special://home/addons/") + 'plugin.video.solarmovie.so'):
if video_type == 'tv':
section = 'tv'
contextmenuitems.append(('Find AirDates', 'XBMC.Container.Update(%s?mode=%s&title=%s)' % ('plugin://plugin.video.solarmovie.so/','SearchForAirDates',nameonly)))
else: section = 'movies'
contextmenuitems.append(('Search Solarmovie.so', 'XBMC.Container.Update(%s?mode=%s§ion=%s&title=%s)' % ('plugin://plugin.video.solarmovie.so/','ApiSearch',section,nameonly)))
if os.path.exists(xbmc.translatePath("special://home/addons/") + 'plugin.video.icefilms'):
contextmenuitems.append(('Search Icefilms',
'XBMC.Container.Update(%s?mode=555&url=%s&search=%s&nextPage=%s)' % (
'plugin://plugin.video.icefilms/', 'http://www.icefilms.info/', nameonly, '1')))
if os.path.exists(xbmc.translatePath("special://home/addons/") + 'plugin.video.tubeplus'):
if video_type == 'tv':
section = 'tv-shows'
else:
section = 'movies'
contextmenuitems.append(('Search tubeplus', 'XBMC.Container.Update(%s?mode=Search§ion=%s&query=%s)' % (
'plugin://plugin.video.tubeplus/', section, nameonly)))
if os.path.exists(xbmc.translatePath("special://home/addons/") + 'plugin.video.tvlinks'):
if video_type == 'tv':
contextmenuitems.append(('Search tvlinks', 'XBMC.Container.Update(%s?mode=Search&query=%s)' % (
'plugin://plugin.video.tvlinks/', nameonly)))
return contextmenuitems
def get_item_params(item):
item_params = {}
if item['video_type']=='movie':
item_params['section']='movies'
item_params['nextmode'] = MODES.GET_SOURCES
item_params['video_type'] = 'movie'
item_params['folder']=(_1CH.get_setting('source-win') == 'Directory' and _1CH.get_setting('auto-play') == 'false')
else:
item_params['section']='tv'
item_params['nextmode'] = MODES.SEASON_LIST
item_params['video_type'] = 'tvshow'
item_params['folder']=True
return item_params
def get_section_params(section):
section_params={}
section_params['section']=section
if section == 'tv':
section_params['content']='tvshows'
section_params['nextmode'] = MODES.SEASON_LIST
section_params['video_type'] = 'tvshow'
section_params['folder'] = True
subscriptions = get_subscriptions()
section_params['subs'] = [row[0] for row in subscriptions]
elif section=='episode':
section_params['nextmode'] = MODES.GET_SOURCES
section_params['video_type']='episode'
section_params['content']='episodes'
section_params['folder'] = (_1CH.get_setting('source-win') == 'Directory' and _1CH.get_setting('auto-play') == 'false')
section_params['subs'] = []
elif section == 'calendar':
section_params['nextmode'] = MODES.GET_SOURCES
section_params['video_type']='episode'
section_params['content']='calendar'
section_params['folder'] = (_1CH.get_setting('source-win') == 'Directory' and _1CH.get_setting('auto-play') == 'false')
section_params['subs'] = []
else:
section_params['content']='movies'
section_params['nextmode'] = MODES.GET_SOURCES
section_params['video_type'] = 'movie'
section_params['folder'] = (_1CH.get_setting('source-win') == 'Directory' and _1CH.get_setting('auto-play') == 'false')
section_params['subs'] = []
# only grab actual fav_urls if not using website favs (otherwise too much site load)
if utils.website_is_integrated():
section_params['fav_urls']=[]
else:
section_params['fav_urls']=get_fav_urls(section)
section_params['xbmc_fav_urls']=utils.get_xbmc_fav_urls()
return section_params
def create_item(section_params,title,year,img,url, imdbnum='', season='', episode = '', day='', totalItems=0, menu_items=None):
#utils.log('Create Item: %s, %s, %s, %s, %s, %s, %s, %s, %s' % (section_params, title, year, img, url, imdbnum, season, episode, totalItems))
if menu_items is None: menu_items=[]
if section_params['nextmode']==MODES.GET_SOURCES and _1CH.get_setting('auto-play')=='true':
queries = {'mode': MODES.SELECT_SOURCES, 'title': title, 'url': url, 'img': img, 'imdbnum': imdbnum, 'video_type': section_params['video_type'], 'year': year}
if _1CH.get_setting('source-win')=='Dialog':
runstring = 'PlayMedia(%s)' % _1CH.build_plugin_url(queries)
else:
runstring = 'Container.Update(%s)' % _1CH.build_plugin_url(queries)
menu_items.insert(0,('Select Source', runstring),)
# fix episode url being added to subs
if section_params['video_type']=='episode':
temp_url=re.match('(/.*/).*',url).groups()[0]
else:
temp_url=url
liz,menu_items = build_listitem(section_params, title, year, img, temp_url, imdbnum, season, episode, day=day, extra_cms=menu_items)
img = liz.getProperty('img')
imdbnum = liz.getProperty('imdb')
if not section_params['folder']: # should only be when it's a movie and dialog are off and autoplay is off
liz.setProperty('isPlayable','true')
queries = {'mode': section_params['nextmode'], 'title': title, 'url': url, 'img': img, 'imdbnum': imdbnum, 'video_type': section_params['video_type'], 'year': year}
liz_url = _1CH.build_plugin_url(queries)
if utils.in_xbmc_favs(liz_url, section_params['xbmc_fav_urls']):
action=FAV_ACTIONS.REMOVE
label='Remove from XBMC Favourites'
else:
action=FAV_ACTIONS.ADD
label='Add to XBMC Favourites'
runstring = 'RunPlugin(%s)' % _1CH.build_plugin_url({'mode': MODES.TOGGLE_X_FAVS, 'title': liz.getLabel(), 'url': liz_url, 'img': img, 'is_playable': liz.getProperty('isPlayable')=='true', 'action': action})
menu_items.insert(0,(label, runstring),)
liz.addContextMenuItems(menu_items, replaceItems=True)
xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, liz,section_params['folder'],totalItems)
def build_listitem(section_params, title, year, img, resurl, imdbnum='', season='', episode='', day='', extra_cms=None):
if not extra_cms: extra_cms = []
menu_items = add_contextsearchmenu(title, section_params['section'])
menu_items = menu_items + extra_cms
# fav_urls is only populated when local favs are used
if resurl in section_params['fav_urls']:
runstring = 'RunPlugin(%s)' % _1CH.build_plugin_url({'mode': MODES.DEL_FAV, 'section': section_params['section'], 'title': title, 'url': resurl, 'year': year})
menu_items.append((REMOVE_FAV_MENU, runstring),)
# will show add to favs always when using website favs and not on favorites view;
# but only when item isn't in favs when using local favs
elif REMOVE_FAV_MENU not in [menu[0] for menu in menu_items]:
queries = {'mode': MODES.SAVE_FAV, 'fav_type': section_params['section'], 'title': title, 'url': resurl, 'year': year}
runstring = 'RunPlugin(%s)' % _1CH.build_plugin_url(queries)
menu_items.append(('Add to Favorites', runstring), )
if resurl and utils.website_is_integrated():
if REMOVE_TW_MENU not in (item[0] for item in menu_items):
watchstring = 'RunPlugin(%s)' % _1CH.build_plugin_url({'mode': MODES.CH_TOWATCH_WEB, 'primewire_url': resurl, 'action':'add', 'refresh':True})
menu_items.append(('Add to ToWatch list', watchstring),)
if REMOVE_W_MENU not in (item[0] for item in menu_items):
watchedstring = 'RunPlugin(%s)' % _1CH.build_plugin_url({'mode': MODES.CH_WATCH_WEB, 'primewire_url': resurl,'action':'add', 'refresh':True})
menu_items.append(('Add to Watched List', watchedstring),)
queries = {'mode': MODES.ADD2LIB, 'video_type': section_params['video_type'], 'title': title, 'img': img, 'year': year,
'url': resurl}
runstring = 'RunPlugin(%s)' % _1CH.build_plugin_url(queries)
menu_items.append(('Add to Library', runstring), )