forked from ddurdle/Hive-for-KODI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.py
992 lines (777 loc) · 34.5 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
'''
Hive XBMC Plugin
Copyright (C) 2013-2014 ddurdle
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 xbmc, xbmcgui, xbmcplugin, xbmcaddon
import sys
import urllib
import cgi
import re
# global variables
PLUGIN_NAME = 'hive'
#helper methods
def log(msg, err=False):
if err:
xbmc.log(addon.getAddonInfo('name') + ': ' + msg, xbmc.LOGERROR)
else:
xbmc.log(addon.getAddonInfo('name') + ': ' + msg, xbmc.LOGDEBUG)
def parse_query(query):
queries = cgi.parse_qs(query)
q = {}
for key, value in queries.items():
q[key] = value[0]
q['mode'] = q.get('mode', 'main')
return q
def addMediaFile(service, package):
listitem = xbmcgui.ListItem(package.file.displayTitle(), iconImage=package.file.thumbnail,
thumbnailImage=package.file.thumbnail)
if package.file.type == package.file.AUDIO:
if package.file.hasMeta:
infolabels = decode_dict({ 'title' : package.file.displayTitle(), 'tracknumber' : package.file.trackNumber, 'artist': package.file.artist, 'album': package.file.album,'genre': package.file.genre,'premiered': package.file.releaseDate })
else:
infolabels = decode_dict({ 'title' : package.file.displayTitle() })
listitem.setInfo('Music', infolabels)
playbackURL = '?mode=audio'
elif package.file.type == package.file.VIDEO:
infolabels = decode_dict({ 'title' : package.file.displayTitle() , 'plot' : package.file.plot })
listitem.setInfo('Video', infolabels)
playbackURL = '?mode=video'
elif package.file.type == package.file.PICTURE:
infolabels = decode_dict({ 'title' : package.file.displayTitle() , 'plot' : package.file.plot })
listitem.setInfo('Pictures', infolabels)
playbackURL = '?mode=photo'
else:
infolabels = decode_dict({ 'title' : package.file.displayTitle() , 'plot' : package.file.plot })
llistitem.setInfo('Video', infolabels)
playbackURL = '?mode=video'
listitem.setProperty('IsPlayable', 'true')
listitem.setProperty('fanart_image', package.file.fanart)
cm=[]
try:
url = package.getMediaURL()
cleanURL = re.sub('---', '', url)
cleanURL = re.sub('&', '---', cleanURL)
except:
cleanURL = ''
# url = PLUGIN_URL+'?mode=streamurl&title='+package.file.title+'&url='+cleanURL
url = PLUGIN_URL+playbackURL+'&title='+package.file.title+'&filename='+package.file.id
if package.file.isEncoded == False:
cm.append(( addon.getLocalizedString(30086), 'XBMC.RunPlugin('+PLUGIN_URL+'?mode=requestencoding&title='+package.file.title+'&filename='+package.file.id+')', ))
cm.append(( addon.getLocalizedString(30042), 'XBMC.RunPlugin('+PLUGIN_URL+'?mode=buildstrm&title='+package.file.title+'&filename='+package.file.id+')', ))
# cm.append(( addon.getLocalizedString(30046), 'XBMC.PlayMedia('+playbackURL+'&title='+ package.file.title + '&directory='+ package.folder.id + '&filename='+ package.file.id +'&playback=0)', ))
# cm.append(( addon.getLocalizedString(30047), 'XBMC.PlayMedia('+playbackURL+'&title='+ package.file.title + '&directory='+ package.folder.id + '&filename='+ package.file.id +'&playback=1)', ))
# cm.append(( addon.getLocalizedString(30048), 'XBMC.PlayMedia('+playbackURL+'&title='+ package.file.title + '&directory='+ package.folder.id + '&filename='+ package.file.id +'&playback=2)', ))
#cm.append(( addon.getLocalizedString(30032), 'XBMC.RunPlugin('+PLUGIN_URL+'?mode=download&title='+package.file.title+'&filename='+package.file.id+')', ))
# listitem.addContextMenuItems( commands )
# if cm:
listitem.addContextMenuItems(cm, False)
xbmcplugin.addDirectoryItem(plugin_handle, url, listitem,
isFolder=False, totalItems=0)
def addDirectory(service, folder):
if folder.id == 'SAVED-SEARCH':
listitem = xbmcgui.ListItem('Search - ' + decode(folder.displayTitle()), iconImage='', thumbnailImage='')
else:
listitem = xbmcgui.ListItem(decode(folder.displayTitle()), iconImage=decode(folder.thumb), thumbnailImage=decode(folder.thumb))
fanart = addon.getAddonInfo('path') + '/fanart.jpg'
if folder.id != '':
cm=[]
cm.append(( addon.getLocalizedString(30042), 'XBMC.RunPlugin('+PLUGIN_URL+'?mode=buildstrm&title='+folder.title+'&instanceName='+str(service.instanceName)+'&folderID='+str(folder.id)+')', ))
cm.append(( addon.getLocalizedString(30081), 'XBMC.RunPlugin('+PLUGIN_URL+'?mode=createbookmark&title='+folder.title+'&instanceName='+str(service.instanceName)+'&folderID='+str(folder.id)+')', ))
listitem.addContextMenuItems(cm, False)
listitem.setProperty('fanart_image', fanart)
if folder.id == 'SAVED-SEARCH':
xbmcplugin.addDirectoryItem(plugin_handle, PLUGIN_URL+'?mode=search&criteria='+folder.title, listitem,
isFolder=True, totalItems=0)
else:
xbmcplugin.addDirectoryItem(plugin_handle, service.getDirectoryCall(folder), listitem,
isFolder=True, totalItems=0)
def addMenu(url,title):
listitem = xbmcgui.ListItem(decode(title), iconImage='', thumbnailImage='')
fanart = addon.getAddonInfo('path') + '/fanart.jpg'
listitem.setProperty('fanart_image', fanart)
xbmcplugin.addDirectoryItem(plugin_handle, url, listitem,
isFolder=True, totalItems=0)
#http://stackoverflow.com/questions/1208916/decoding-html-entities-with-python/1208931#1208931
def _callback(matches):
id = matches.group(1)
try:
return unichr(int(id))
except:
return id
def decode(data):
return re.sub("&#(\d+)(;|(?=\s))", _callback, data).strip()
def decode_dict(data):
for k, v in data.items():
if type(v) is str or type(v) is unicode:
data[k] = decode(v)
return data
def numberOfAccounts(accountType):
count = 1
max_count = int(addon.getSetting(accountType+'_numaccounts'))
actualCount = 0
while True:
try:
if addon.getSetting(accountType+str(count)+'_username') != '':
actualCount = actualCount + 1
except:
break
if count == max_count:
break
count = count + 1
return actualCount
#global variables
PLUGIN_URL = sys.argv[0]
plugin_handle = int(sys.argv[1])
plugin_queries = parse_query(sys.argv[2][1:])
addon = xbmcaddon.Addon(id='plugin.video.hive')
addon_dir = xbmc.translatePath( addon.getAddonInfo('path') )
import os
sys.path.append(os.path.join( addon_dir, 'resources', 'lib' ) )
import hive
import cloudservice
import folder
import file
import package
import mediaurl
import authorization
#from resources.lib import gPlayer
#from resources.lib import tvWindow
#debugging
try:
remote_debugger = addon.getSetting('remote_debugger')
remote_debugger_host = addon.getSetting('remote_debugger_host')
# append pydev remote debugger
if remote_debugger == 'true':
# Make pydev debugger works for auto reload.
# Note pydevd module need to be copied in XBMC\system\python\Lib\pysrc
import pysrc.pydevd as pydevd
# stdoutToServer and stderrToServer redirect stdout and stderr to eclipse console
pydevd.settrace(remote_debugger_host, stdoutToServer=True, stderrToServer=True)
except ImportError:
log(addon.getLocalizedString(30016), True)
sys.exit(1)
except :
pass
# retrieve settings
user_agent = addon.getSetting('user_agent')
mode = plugin_queries['mode']
# make mode case-insensitive
mode = mode.lower()
log('plugin url: ' + PLUGIN_URL)
log('plugin queries: ' + str(plugin_queries))
log('plugin handle: ' + str(plugin_handle))
instanceName = ''
try:
instanceName = (plugin_queries['instance']).lower()
except:
pass
#* utilities *
#clear the authorization token(s) from the identified instanceName or all instances
if mode == 'clearauth':
if instanceName != '':
try:
addon.setSetting(instanceName + '_token', '')
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30023))
except:
#error: instance doesn't exist
pass
# clear all accounts
else:
count = 1
max_count = int(addon.getSetting(PLUGIN_NAME+'_numaccounts'))
while True:
instanceName = PLUGIN_NAME+str(count)
try:
addon.setSetting(instanceName + '_token', '')
except:
break
if count == max_count:
break
count = count + 1
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30023))
xbmcplugin.endOfDirectory(plugin_handle)
#create strm files
elif mode == 'buildstrm':
try:
path = addon.getSetting('path')
except:
path = xbmcgui.Dialog().browse(0,addon.getLocalizedString(30026), 'files','',False,False,'')
if path == '':
path = xbmcgui.Dialog().browse(0,addon.getLocalizedString(30026), 'files','',False,False,'')
if path != '':
returnPrompt = xbmcgui.Dialog().yesno(addon.getLocalizedString(30000), addon.getLocalizedString(30027) + '\n'+path + '?')
if path != '' and returnPrompt:
try:
url = plugin_queries['streamurl']
title = plugin_queries['title']
url = re.sub('---', '&', url)
except:
url=''
if url != '':
filename = xbmc.translatePath(os.path.join(path, title+'.strm'))
strmFile = open(filename, "w")
strmFile.write(url+'\n')
strmFile.close()
else:
try:
folderID = plugin_queries['folderID']
title = plugin_queries['title']
instanceName = plugin_queries['instanceName']
except:
folderID = ''
try:
filename = plugin_queries['filename']
title = plugin_queries['title']
except:
filename = ''
if folderID != '':
try:
username = addon.getSetting(instanceName+'_username')
except:
username = ''
if username != '':
service = hive.hive(PLUGIN_URL,addon,instanceName, user_agent)
service.buildSTRM(path + '/'+title,folderID)
elif filename != '':
url = PLUGIN_URL+'?mode=video&title='+title+'&filename='+filename
filename = xbmc.translatePath(os.path.join(path, title+'.strm'))
strmFile = open(filename, "w")
strmFile.write(url+'\n')
strmFile.close()
else:
count = 1
max_count = int(addon.getSetting(PLUGIN_NAME+'_numaccounts'))
while True:
instanceName = PLUGIN_NAME+str(count)
try:
username = addon.getSetting(instanceName+'_username')
except:
username = ''
if username != '':
service = hive.hive(PLUGIN_URL,addon,instanceName, user_agent)
service.buildSTRM(path + '/'+username)
if count == max_count:
break
count = count + 1
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30028))
xbmcplugin.endOfDirectory(plugin_handle)
#create strm files
elif mode == 'createbookmark':
try:
folderID = plugin_queries['folderID']
title = plugin_queries['title']
instanceName = plugin_queries['instanceName']
except:
folderID = ''
if folderID != '':
try:
username = addon.getSetting(instanceName+'_username')
except:
username = ''
if username != '':
service = hive.hive(PLUGIN_URL,addon,instanceName, user_agent)
newTitle = ''
try:
dialog = xbmcgui.Dialog()
newTitle = dialog.input('Enter a name for the bookmark', title, type=xbmcgui.INPUT_ALPHANUM)
except:
newTitle = title
if newTitle == '':
newTitle = title
service.createBookmark(folderID,newTitle)
xbmcplugin.endOfDirectory(plugin_handle)
#create strm files
elif mode == 'createsearch':
searchText = ''
try:
searchText = addon.getSetting('criteria')
except:
searchText = ''
if searchText == '':
try:
dialog = xbmcgui.Dialog()
searchText = dialog.input('Enter search string', type=xbmcgui.INPUT_ALPHANUM)
except:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30100))
searchText = 'life'
if searchText != '':
instanceName = ''
try:
instanceName = (plugin_queries['instance']).lower()
except:
pass
numberOfAccounts = numberOfAccounts(PLUGIN_NAME)
# show list of services
if numberOfAccounts > 1 and instanceName == '':
count = 1
max_count = int(addon.getSetting(PLUGIN_NAME+'_numaccounts'))
while True:
instanceName = PLUGIN_NAME+str(count)
try:
username = addon.getSetting(instanceName+'_username')
if username != '':
addMenu(PLUGIN_URL+'?mode=main&instance='+instanceName,username)
except:
break
if count == max_count:
break
count = count + 1
else:
# show index of accounts
if instanceName == '' and numberOfAccounts == 1:
count = 1
max_count = int(addon.getSetting(PLUGIN_NAME+'_numaccounts'))
loop = True
while loop:
instanceName = PLUGIN_NAME+str(count)
try:
username = addon.getSetting(instanceName+'_username')
if username != '':
#let's log in
service = hive.hive(PLUGIN_URL,addon,instanceName, user_agent)
loop = False
except:
break
if count == max_count:
break
count = count + 1
# no accounts defined
elif numberOfAccounts == 0:
#legacy account conversion
try:
username = addon.getSetting('username')
if username != '':
addon.setSetting(PLUGIN_NAME+'1_username', username)
addon.setSetting(PLUGIN_NAME+'1_password', addon.getSetting('password'))
addon.setSetting(PLUGIN_NAME+'1_auth_token', addon.getSetting('auth_token'))
addon.setSetting(PLUGIN_NAME+'1_auth_session', addon.getSetting('auth_session'))
addon.setSetting('username', '')
addon.setSetting('password', '')
addon.setSetting('auth_token', '')
addon.setSetting('auth_session', '')
else:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30015))
log(addon.getLocalizedString(30015), True)
xbmcplugin.endOfDirectory(plugin_handle)
except :
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30015))
log(addon.getLocalizedString(30015), True)
xbmcplugin.endOfDirectory(plugin_handle)
#let's log in
service = hive.hive(PLUGIN_URL,addon,instanceName, user_agent)
# show entries of a single account (such as folder)
elif instanceName != '':
service = hive.hive(PLUGIN_URL,addon,instanceName, user_agent)
try:
service
except NameError:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30051), addon.getLocalizedString(30052), addon.getLocalizedString(30053))
log(addon.getLocalizedString(30050)+ 'hive-login', True)
xbmcplugin.endOfDirectory(plugin_handle)
service.createSearch(searchText)
mediaItems = service.getSearchResults(searchText)
isSorted = "0"
try:
isSorted = addon.getSetting('sorted')
except:
pass
if mediaItems:
if isSorted == "0":
for item in sorted(mediaItems, key=lambda package: package.sortTitle):
try:
if item.file == 0:
addDirectory(service, item.folder)
else:
addMediaFile(service, item)
except:
addMediaFile(service, item)
elif isSorted == "1":
for item in sorted(mediaItems, key=lambda package: package.sortTitle, reverse=True):
try:
if item.file == 0:
addDirectory(service, item.folder)
else:
addMediaFile(service, item)
except:
addMediaFile(service, item)
else:
for item in mediaItems:
try:
if item.file == 0:
addDirectory(service, item.folder)
else:
addMediaFile(service, item)
except:
addMediaFile(service, item)
service.updateAuthorization(addon)
xbmcplugin.endOfDirectory(plugin_handle)
numberOfAccounts = numberOfAccounts(PLUGIN_NAME)
# show list of services
if numberOfAccounts > 1 and instanceName == '':
mode = ''
count = 1
max_count = int(addon.getSetting(PLUGIN_NAME+'_numaccounts'))
while True:
instanceName = PLUGIN_NAME+str(count)
try:
username = addon.getSetting(instanceName+'_username')
if username != '':
addMenu(PLUGIN_URL+'?mode=main&instance='+instanceName,username)
except:
break
if count == max_count:
break
count = count + 1
else:
# show index of accounts
if instanceName == '' and numberOfAccounts == 1:
count = 1
max_count = int(addon.getSetting(PLUGIN_NAME+'_numaccounts'))
loop = True
while loop:
instanceName = PLUGIN_NAME+str(count)
try:
username = addon.getSetting(instanceName+'_username')
if username != '':
#let's log in
service = hive.hive(PLUGIN_URL,addon,instanceName, user_agent)
loop = False
except:
break
if count == max_count:
break
count = count + 1
# no accounts defined
elif numberOfAccounts == 0:
#legacy account conversion
try:
username = addon.getSetting('username')
if username != '':
addon.setSetting(PLUGIN_NAME+'1_username', username)
addon.setSetting(PLUGIN_NAME+'1_password', addon.getSetting('password'))
addon.setSetting(PLUGIN_NAME+'1_auth_token', addon.getSetting('auth_token'))
addon.setSetting(PLUGIN_NAME+'1_auth_session', addon.getSetting('auth_session'))
addon.setSetting('username', '')
addon.setSetting('password', '')
addon.setSetting('auth_token', '')
addon.setSetting('auth_session', '')
else:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30015))
log(addon.getLocalizedString(30015), True)
xbmcplugin.endOfDirectory(plugin_handle)
except :
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30015))
log(addon.getLocalizedString(30015), True)
xbmcplugin.endOfDirectory(plugin_handle)
#let's log in
service = hive.hive(PLUGIN_URL,addon,instanceName, user_agent)
# show entries of a single account (such as folder)
elif instanceName != '':
service = hive.hive(PLUGIN_URL,addon,instanceName, user_agent)
if mode == 'main':
addMenu(PLUGIN_URL+'?mode=options','<< '+addon.getLocalizedString(30043)+' >>')
addMenu(PLUGIN_URL+'?mode=search','<<SEARCH>>')
#dump a list of videos available to play
if mode == 'main' or mode == 'folder':
folderName=''
if (mode == 'folder'):
folderName = plugin_queries['directory']
else:
pass
try:
service
except NameError:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30051), addon.getLocalizedString(30052), addon.getLocalizedString(30053))
log(addon.getLocalizedString(30050)+ 'hive-login', True)
xbmcplugin.endOfDirectory(plugin_handle)
if folderName == '':
addMenu(PLUGIN_URL+'?mode=folder&instance='+instanceName+'&directory=FRIENDS','[Friends]')
addMenu(PLUGIN_URL+'?mode=folder&instance='+instanceName+'&directory=FEED','[Latest Feed]')
mediaItems = service.getMediaList(folderName,0)
isSorted = "0"
try:
isSorted = addon.getSetting('sorted')
except:
pass
if mediaItems:
if isSorted == "0":
for item in sorted(mediaItems, key=lambda package: package.sortTitle):
try:
if item.file == 0:
addDirectory(service, item.folder)
else:
addMediaFile(service, item)
except:
addMediaFile(service, item)
elif isSorted == "1":
for item in sorted(mediaItems, key=lambda package: package.sortTitle, reverse=True):
try:
if item.file == 0:
addDirectory(service, item.folder)
else:
addMediaFile(service, item)
except:
addMediaFile(service, item)
else:
for item in mediaItems:
try:
if item.file == 0:
addDirectory(service, item.folder)
else:
addMediaFile(service, item)
except:
addMediaFile(service, item)
service.updateAuthorization(addon)
#dump a list of videos available to play
elif mode == 'search':
searchText = ''
try:
searchText = plugin_queries['criteria']
except:
searchText = ''
if searchText == '':
try:
dialog = xbmcgui.Dialog()
searchText = dialog.input('Enter search string', type=xbmcgui.INPUT_ALPHANUM)
except:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30100))
searchText = 'life'
try:
service
except NameError:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30051), addon.getLocalizedString(30052), addon.getLocalizedString(30053))
log(addon.getLocalizedString(30050)+ 'hive-login', True)
xbmcplugin.endOfDirectory(plugin_handle)
mediaItems = service.getSearchResults(searchText)
isSorted = "0"
try:
isSorted = addon.getSetting('sorted')
except:
pass
if mediaItems:
if isSorted == "0":
for item in sorted(mediaItems, key=lambda package: package.sortTitle):
try:
if item.file == 0:
addDirectory(service, item.folder)
else:
addMediaFile(service, item)
except:
addMediaFile(service, item)
elif isSorted == "1":
for item in sorted(mediaItems, key=lambda package: package.sortTitle, reverse=True):
try:
if item.file == 0:
addDirectory(service, item.folder)
else:
addMediaFile(service, item)
except:
addMediaFile(service, item)
else:
for item in mediaItems:
try:
if item.file == 0:
addDirectory(service, item.folder)
else:
addMediaFile(service, item)
except:
addMediaFile(service, item)
service.updateAuthorization(addon)
#play a video given its exact-title
elif mode == 'video' or mode == 'audio':
filename = plugin_queries['filename']
try:
directory = plugin_queries['directory']
except:
directory = ''
try:
title = plugin_queries['title']
except:
title = ''
try:
service
except NameError:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30051), addon.getLocalizedString(30052), addon.getLocalizedString(30053))
log(aaddon.getLocalizedString(30050)+ 'hive-login', True)
xbmcplugin.endOfDirectory(plugin_handle)
playbackType = 0
try:
playbackType = plugin_queries['playback']
except:
playbackType = ''
if service.isPremium:
try:
if mode == 'audio':
playbackType = int(addon.getSetting('playback_type_audio'))
else:
playbackType = int(addon.getSetting('playback_type_video'))
except:
playbackType = 0
else:
try:
if mode == 'audio':
playbackType = int(addon.getSetting('free_playback_type_audio'))
else:
playbackType = int(addon.getSetting('free_playback_type_video'))
except:
if mode == 'audio':
playbackType = 0
else:
playbackType = 1
mediaFile = file.file(filename, title, '', 0, '','')
mediaFolder = folder.folder(directory,directory)
mediaURLs = service.getPlaybackCall(playbackType,package.package(mediaFile,mediaFolder ))
playbackURL = ''
# BEGIN JoKeRzBoX
# - Get list of possible resolutions (quality), pre-ordered from best to lower res, from a String constant
# - Create associative array (a.k.a. hash list) availableQualities with each available resolution (key) and media URL (value)
# - Simple algorithm to go through possible resolutions and find the best available one based on user's choice
# FIX: list of qualities shown to user are now ordered from highest to low resolution
if mode == 'audio':
possibleQualities = addon.getLocalizedString(30058)
else:
possibleQualities = addon.getLocalizedString(30057)
listPossibleQualities = possibleQualities.split("|")
availableQualities = {}
for mediaURL in mediaURLs:
availableQualities[mediaURL.qualityDesc] = mediaURL.url
## User has chosen: "Always original quality"
#if playbackType == 0:
# playbackURL = availableQualities['original']
# User has chosen a max quality other than "original". Let's decide on the best stream option available
#else:
userChosenQuality = listPossibleQualities[playbackType]
reachedThreshold = 0
for quality in listPossibleQualities:
if quality == userChosenQuality:
reachedThreshold = 1
if reachedThreshold and quality in availableQualities:
playbackURL = availableQualities[quality]
chosenRes = str(quality)
reachedThreshold = 0
if reachedThreshold and playbackType != len(listPossibleQualities)-1 and len(availableQualities) == 3:
# Means that the exact encoding requested by user was not found.
# Also, there are the only available: original, 360p and 240p (because cont = 3).
# Therefore if user did not choose "always ask" it is safe to assume "original" is the one closest to the quality selected by user
playbackURL = availableQualities['original']
# Desired quality still not found. Lets bring list of available options and let user select
if playbackURL == '':
options = []
for quality in listPossibleQualities:
if quality in availableQualities:
options.append(quality)
ret = xbmcgui.Dialog().select(addon.getLocalizedString(30033), options)
if ret >= 0:
playbackURL = availableQualities[str(options[ret])]
chosenRes = str(options[ret])
# END JoKeRzBoX
# JoKeRzBox: FIX: when user does not choose from list, addon was still playing a stream
if playbackURL != '':
item = xbmcgui.ListItem(path=playbackURL)
# item.setInfo( type="Video", infoLabels={ "Title": title , "Plot" : title } )
# item.setInfo( type="Video")
# Add resolution to beginning of title while playing media. Format "<RES> | <TITLE>"
if mode == 'audio':
item.setInfo( type="music", infoLabels={ "Title": title + " @ " + chosenRes} )
else:
item.setInfo( type="video", infoLabels={ "Title": title + " @ " + chosenRes, "Plot" : title } )
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
#play a video given its exact-title
elif mode == 'requestencoding':
filename = plugin_queries['filename']
try:
directory = plugin_queries['directory']
except:
directory = ''
try:
title = plugin_queries['title']
except:
title = ''
try:
service
except NameError:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30051), addon.getLocalizedString(30052), addon.getLocalizedString(30053))
log(aaddon.getLocalizedString(30050)+ 'hive-login', True)
xbmcplugin.endOfDirectory(plugin_handle)
mediaFile = file.file(filename, title, '', 0, '','')
mediaFolder = folder.folder(directory,directory)
mediaURLs = service.getPlaybackCall(0,package.package(mediaFile,mediaFolder ))
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30087), title)
elif mode == 'photo':
filename = plugin_queries['filename']
try:
directory = plugin_queries['directory']
except:
directory = ''
try:
title = plugin_queries['title']
except:
title = ''
try:
service
except NameError:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30051), addon.getLocalizedString(30052), addon.getLocalizedString(30053))
log(aaddon.getLocalizedString(30050)+ 'hive-login', True)
xbmcplugin.endOfDirectory(plugin_handle)
path = ''
try:
path = addon.getSetting('photo_folder')
except:
pass
import os.path
if not os.path.exists(path):
path = ''
while path == '':
path = xbmcgui.Dialog().browse(0,addon.getLocalizedString(30038), 'files','',False,False,'')
if not os.path.exists(path):
path = ''
else:
addon.setSetting('photo_folder', path)
mediaFile = file.file(filename, title, '', 0, '','')
mediaFolder = folder.folder(directory,directory)
mediaURLs = service.getPlaybackCall(0,package.package(mediaFile,mediaFolder ))
playbackURL = ''
for mediaURL in mediaURLs:
if mediaURL.qualityDesc == 'original':
playbackURL = mediaURL.url
import xbmcvfs
xbmcvfs.mkdir(path + '/'+str(directory))
try:
xbmcvfs.rmdir(path + '/'+str(directory)+'/'+str(title))
except:
pass
service.downloadPicture(playbackURL, path + '/'+str(directory) + '/'+str(title))
xbmc.executebuiltin("XBMC.ShowPicture("+path + '/'+str(directory) + '/'+str(title)+")")
#play a video given its exact-title
elif mode == 'streamurl':
url = plugin_queries['url']
try:
title = plugin_queries['title']
except:
title = ''
try:
service
except NameError:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30051), addon.getLocalizedString(30052), addon.getLocalizedString(30053))
log(aaddon.getLocalizedString(30050)+ 'hive-login', True)
xbmcplugin.endOfDirectory(plugin_handle)
url = re.sub('---', '&', url)
item = xbmcgui.ListItem(path=url)
item.setInfo( type="Video", infoLabels={ "Title": title , "Plot" : title } )
# item.setInfo( type="Music", infoLabels={ "Title": title , "Plot" : title } )
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
if mode == 'options' or mode == 'buildstrm' or mode == 'clearauth':
addMenu(PLUGIN_URL+'?mode=clearauth','<<'+addon.getLocalizedString(30018)+'>>')
addMenu(PLUGIN_URL+'?mode=buildstrm','<<'+addon.getLocalizedString(30025)+'>>')
addMenu(PLUGIN_URL+'?mode=createsearch','<<Save Search>>')
xbmcplugin.endOfDirectory(plugin_handle)