forked from saidul85/XBMC-gdrive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.py
2026 lines (1536 loc) · 88.7 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
'''
CloudService 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/>.
'''
# cloudservice - required python modules
import sys
import urllib
import re
import os
# cloudservice - standard XBMC modules
import xbmc, xbmcgui, xbmcplugin, xbmcaddon, xbmcvfs
# common routines
from resources.lib import kodi_common
# global variables
import addon_parameters
addon = addon_parameters.addon
cloudservice2 = addon_parameters.cloudservice2
cloudservice1 = addon_parameters.cloudservice1
#*** testing - gdrive
from resources.lib import tvWindow
from resources.lib import gSpreadsheets
from resources.lib import gSheets_api4
##**
# cloudservice - standard modules
#from resources.lib import gdrive
#from resources.lib import gdrive_api2
from resources.lib import cloudservice
from resources.lib import authorization
from resources.lib import folder
from resources.lib import file
from resources.lib import offlinefile
from resources.lib import package
from resources.lib import mediaurl
from resources.lib import crashreport
from resources.lib import gPlayer
from resources.lib import settings
from resources.lib import cache
from resources.lib import TMDB
#global variables
PLUGIN_URL = sys.argv[0]
plugin_handle = int(sys.argv[1])
plugin_queries = settings.parse_query(sys.argv[2][1:])
addon_dir = xbmc.translatePath( addon.getAddonInfo('path') )
kodi_common.debugger()
# cloudservice - create settings module
settings = settings.settings(addon)
# retrieve settings
user_agent = settings.getSetting('user_agent')
#obsolete, replace, revents audio from streaming
#if user_agent == 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)':
# addon.setSetting('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.38 Safari/532.0')
mode = settings.getParameter('mode','main')
# make mode case-insensitive
mode = mode.lower()
#*** old - gdrive
# allow for playback of public videos without authentication
if (mode == 'streamurl'):
authenticate = False
else:
authenticate = True
##**
instanceName = ''
try:
instanceName = (plugin_queries['instance']).lower()
except:
pass
# cloudservice - content type
contextType = settings.getParameter('content_type')
#support encfs?
encfs = settings.getParameter('encfs', False)
contentType = kodi_common.getContentType(contextType,encfs)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)
# xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_TRACKNUM)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_SIZE)
numberOfAccounts = kodi_common.numberOfAccounts(addon_parameters.PLUGIN_NAME)
invokedUsername = settings.getParameter('username')
# cloudservice - utilities
###
if mode == 'dummy' or mode == 'delete' or mode == 'enroll':
kodi_common.accountActions(addon, addon_parameters.PLUGIN_NAME, mode, instanceName, numberOfAccounts)
#create strm files
elif mode == 'buildstrm':
silent = settings.getParameter('silent', settings.getSetting('strm_silent',0))
if silent == '':
silent = 0
try:
path = settings.getSetting('strm_path')
except:
path = xbmcgui.Dialog().browse(0,addon.getLocalizedString(30026), 'files','',False,False,'')
addon.setSetting('strm_path', path)
if path == '':
path = xbmcgui.Dialog().browse(0,addon.getLocalizedString(30026), 'files','',False,False,'')
addon.setSetting('strm_path', path)
if path != '':
returnPrompt = xbmcgui.Dialog().yesno(addon.getLocalizedString(30000), addon.getLocalizedString(30027) + '\n'+path + '?')
if path != '' and returnPrompt:
if silent != 2:
try:
pDialog = xbmcgui.DialogProgressBG()
pDialog.create(addon.getLocalizedString(30000), 'Building STRMs...')
except:
pass
url = settings.getParameter('streamurl')
url = re.sub('---', '&', url)
title = settings.getParameter('title')
type = int(settings.getParameter('type', 0))
if url != '':
filename = path + '/' + title+'.strm'
strmFile = xbmcvfs.File(filename, "w")
strmFile.write(url+'\n')
strmFile.close()
else:
folderID = settings.getParameter('folder')
filename = settings.getParameter('filename')
title = settings.getParameter('title')
invokedUsername = settings.getParameter('username')
encfs = settings.getParameter('encfs', False)
encryptedPath = settings.getParameter('epath', '')
dencryptedPath = settings.getParameter('dpath', '')
if folderID != '':
count = 1
loop = True
while loop:
instanceName = addon_parameters.PLUGIN_NAME+str(count)
try:
username = settings.getSetting(instanceName+'_username')
if username == invokedUsername:
#let's log in
if ( settings.getSettingInt(instanceName+'_type',0)==0):
service = cloudservice1(PLUGIN_URL,addon,instanceName, user_agent, settings)
else:
service = cloudservice2(PLUGIN_URL,addon,instanceName, user_agent, settings)
loop = False
except:
service = cloudservice1(PLUGIN_URL,addon,instanceName, user_agent)
break
if count == numberOfAccounts:
try:
service
except NameError:
#fallback on first defined account
if ( settings.getSettingInt(instanceName+'_type',0)==0):
service = cloudservice1(PLUGIN_URL,addon,addon_parameters.PLUGIN_NAME+'1', user_agent, settings)
else:
service = cloudservice2(PLUGIN_URL,addon,addon_parameters.PLUGIN_NAME+'1', user_agent, settings)
break
count = count + 1
# encfs -- extract filename
if encfs:
extrapulatedFolderName = re.compile('([^/]+)/$')
titleDecrypted = extrapulatedFolderName.match(dencryptedPath)
if titleDecrypted is not None:
title = titleDecrypted.group(1)
if addon_parameters.spreadsheet and service.cloudResume == '2':
spreadsheetFile = xbmcvfs.File(path + '/spreadsheet.tab', "w")
service.buildSTRM(path + '/'+title,folderID, contentType=contentType, pDialog=pDialog, epath=encryptedPath, dpath=dencryptedPath, encfs=encfs, spreadsheetFile=spreadsheetFile)
spreadsheetFile.close()
else:
service.buildSTRM(path + '/'+title,folderID, contentType=contentType, pDialog=pDialog, epath=encryptedPath, dpath=dencryptedPath, encfs=encfs)
elif filename != '':
if encfs:
values = {'title': title, 'encfs': 'True', 'epath': encryptedPath, 'dpath': dencryptedPath, 'filename': filename, 'username': invokedUsername}
# encfs -- extract filename
extrapulatedFileName = re.compile('.*?/([^/]+)$')
titleDecrypted = extrapulatedFileName.match(dencryptedPath)
if titleDecrypted is not None:
title = titleDecrypted.group(1)
else:
values = {'title': title, 'filename': filename, 'username': invokedUsername}
if type == 1:
url = PLUGIN_URL+'?mode=audio&'+urllib.urlencode(values)
else:
url = PLUGIN_URL+'?mode=video&'+urllib.urlencode(values)
filename = path + '/' + title+'.strm'
strmFile = xbmcvfs.File(filename, "w")
strmFile.write(url+'\n')
strmFile.close()
else:
count = 1
while True:
instanceName = addon_parameters.PLUGIN_NAME+str(count)
username = settings.getSetting(instanceName+'_username')
if username != '' and username == invokedUsername:
if ( settings.getSettingInt(instanceName+'_type',0)==0):
service = cloudservice1(PLUGIN_URL,addon,instanceName, user_agent, settings)
else:
service = cloudservice2(PLUGIN_URL,addon,instanceName, user_agent, settings)
service.buildSTRM(path + '/'+username, contentType=contentType, pDialog=pDialog, epath=encryptedPath, dpath=dencryptedPath, encfs=encfs)
if count == numberOfAccounts:
#fallback on first defined account
try:
service
except NameError:
#fallback on first defined account
if ( settings.getSettingInt(instanceName+'_type',0)==0):
service = cloudservice1(PLUGIN_URL,addon,addon_parameters.PLUGIN_NAME+'1', user_agent, settings)
else:
service = cloudservice2(PLUGIN_URL,addon,addon_parameters.PLUGIN_NAME+'1', user_agent, settings)
break
count = count + 1
if silent != 2:
try:
pDialog.update(100)
pDialog.close()
except:
pass
if silent == 0:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30028))
xbmcplugin.endOfDirectory(plugin_handle)
###
###
#STRM playback without instance name; use default
if invokedUsername == '' and instanceName == '' and (mode == 'video' or mode == 'audio'):
instanceName = addon_parameters.PLUGIN_NAME + str(settings.getSetting('account_default', 1))
instanceName = kodi_common.getInstanceName(addon, addon_parameters.PLUGIN_NAME, mode, instanceName, invokedUsername, numberOfAccounts, contextType)
service = None
if instanceName is None and (mode == 'index' or mode == 'main' or mode == 'offline'):
service = None
elif instanceName is None:
service = cloudservice2(PLUGIN_URL,addon,'', user_agent, settings, authenticate=False)
elif settings.getSettingInt(instanceName+'_type',0)==0 :
service = cloudservice1(PLUGIN_URL,addon,instanceName, user_agent, settings)
else:
service = cloudservice2(PLUGIN_URL,addon,instanceName, user_agent, settings)
#create strm files
if mode == 'buildf2':
import time
currentDate = time.strftime("%Y%m%d")
try:
path = settings.getSetting('strm_path')
except:
pass
if path != '':
try:
pDialog = xbmcgui.DialogProgressBG()
pDialog.create(addon.getLocalizedString(30000), 'Building STRMs...')
except:
pass
#service = gdrive_api2.gdrive(PLUGIN_URL,addon,instanceName, user_agent, settings)
# try:
addon.setSetting(instanceName + '_changedate', currentDate)
service.buildSTRM2(path, contentType=contentType, pDialog=pDialog)
# except:
# pass
try:
pDialog.update(100)
pDialog.close()
except:
pass
xbmcplugin.endOfDirectory(plugin_handle)
# options menu
#if mode == 'main':
# addMenu(PLUGIN_URL+'?mode=options','<< '+addon.getLocalizedString(30043)+' >>')
if mode == 'offline':
title = settings.getParameter('title')
folderID = settings.getParameter('folder')
folderName = settings.getParameter('foldername')
mediaItems = kodi_common.getOfflineFileList(settings.getSetting('cache_folder'))
if mediaItems:
for offlinefile in mediaItems:
kodi_common.addOfflineMediaFile(offlinefile)
elif service is None:
xbmcplugin.endOfDirectory(plugin_handle)
#cloud_db actions
elif mode == 'cloud_db':
title = settings.getParameter('title')
folderID = settings.getParameter('folder')
folderName = settings.getParameter('foldername')
filename = settings.getParameter('filename')
action = settings.getParameter('action')
mediaFile = file.file(filename, title, '', 0, '','')
mediaFolder = folder.folder(folderID,folderName)
package=package.package(mediaFile,mediaFolder)
# TESTING
if addon_parameters.spreadsheet and service.cloudResume == '2':
if service.worksheetID == '':
try:
service.gSpreadsheet = gSpreadsheets.gSpreadsheets(service,addon, user_agent)
spreadsheets = service.gSpreadsheet.getSpreadsheetList()
except:
pass
for title in spreadsheets.iterkeys():
if title == 'CLOUD_DB':
worksheets = service.gSpreadsheet.getSpreadsheetWorksheets(spreadsheets[title])
for worksheet in worksheets.iterkeys():
if worksheet == 'db':
service.worksheetID = worksheets[worksheet]
addon.setSetting(instanceName + '_spreadsheet', service.worksheetID)
break
break
# TESTING
if addon_parameters.spreadsheet and service.cloudResume == '2':
if service.gSpreadsheet is None:
service.gSpreadsheet = gSpreadsheets.gSpreadsheets(service,addon, user_agent)
if action == 'watch':
service.gSpreadsheet.setMediaStatus(service.worksheetID,package, watched=1)
xbmc.executebuiltin("XBMC.Container.Refresh")
elif action == 'queue':
package.folder.id = 'QUEUED'
service.gSpreadsheet.setMediaStatus(service.worksheetID,package)
elif action == 'recentwatched' or action == 'recentstarted' or action == 'library' or action == 'queued':
mediaItems = service.gSpreadsheet.updateMediaPackage(service.worksheetID, criteria=action)
#ensure that folder view playback
if contextType == '':
contextType = 'video'
if mediaItems:
for item in mediaItems:
if item.file is None:
service.addDirectory(item.folder, contextType=contextType)
else:
service.addMediaFile(item, contextType=contextType)
service.updateAuthorization(addon)
#cloud_db actions
elif mode == 'cloud_dbtest':
title = settings.getParameter('title')
folderID = settings.getParameter('folder')
folderName = settings.getParameter('foldername')
filename = settings.getParameter('filename')
action = settings.getParameter('action')
# s = gSheets_api4.gSheets_api4(service,addon, user_agent)
# s.createSpreadsheet()
# s.addRows()
if action == 'library_menu':
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_dbtest&instance='+str(service.instanceName)+'&action=library_genre&content_type='+str(contextType),'Genre')
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_dbtest&instance='+str(service.instanceName)+'&action=library_year&content_type='+str(contextType),'Year')
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_dbtest&instance='+str(service.instanceName)+'&action=library_title&content_type='+str(contextType),'Title')
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_dbtest&instance='+str(service.instanceName)+'&action=library_country&content_type='+str(contextType),'Countries')
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_dbtest&instance='+str(service.instanceName)+'&action=library_director&content_type='+str(contextType),'Directors')
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_dbtest&instance='+str(service.instanceName)+'&action=library_studio&content_type='+str(contextType),'Studio')
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_dbtest&instance='+str(service.instanceName)+'&action=library_resolution&content_type='+str(contextType),'Quality (Resolution)')
else:
mediaFile = file.file(filename, title, '', 0, '','')
mediaFolder = folder.folder(folderID,folderName)
package=package.package(mediaFile,mediaFolder)
spreadsheet = None
# TESTING
if addon_parameters.spreadsheet:
try:
service.gSpreadsheet = gSpreadsheets.gSpreadsheets(service,addon, user_agent)
spreadsheets = service.gSpreadsheet.getSpreadsheetList()
except:
pass
for t in spreadsheets.iterkeys():
if t == 'Movie2':
worksheets = service.gSpreadsheet.getSpreadsheetWorksheets(spreadsheets[t])
for worksheet in worksheets.iterkeys():
if worksheet == 'db':
spreadsheet = worksheets[worksheet]
break
break
# TESTING
if addon_parameters.spreadsheet:
if service.gSpreadsheet is None:
service.gSpreadsheet = gSpreadsheets.gSpreadsheets(service,addon, user_agent)
if action == 'watch':
service.gSpreadsheet.setMediaStatus(service.worksheetID,package, watched=1)
xbmc.executebuiltin("XBMC.Container.Refresh")
elif action == 'queue':
package.folder.id = 'QUEUED'
service.gSpreadsheet.setMediaStatus(service.worksheetID,package)
elif action == 'genre' or action == 'year' or action == 'title' or action == 'country' or action == 'director' or action == 'studio' or action == 'recentstarted' or 'library' in action or action == 'queued':
if action == 'genre':
mediaItems = service.gSpreadsheet.getMovies(spreadsheet, genre=title)
elif action == 'year':
mediaItems = service.gSpreadsheet.getMovies(spreadsheet, year=title)
elif action == 'title':
mediaItems = service.gSpreadsheet.getMovies(spreadsheet, title=title)
elif action == 'resolution':
mediaItems = service.gSpreadsheet.getMovies(spreadsheet, resolution=title)
elif action == 'country':
mediaItems = service.gSpreadsheet.getMovies(spreadsheet, country=title)
elif action == 'director':
mediaItems = service.gSpreadsheet.getMovies(spreadsheet, director=title)
elif action == 'studio':
mediaItems = service.gSpreadsheet.getMovies(spreadsheet, studio=title)
elif action == 'library_title':
mediaItems = service.gSpreadsheet.getTitle(spreadsheet)
elif action == 'library_genre':
mediaItems = service.gSpreadsheet.getGenre(spreadsheet)
elif action == 'library_year':
mediaItems = service.gSpreadsheet.getYear(spreadsheet)
elif action == 'library_country':
mediaItems = service.gSpreadsheet.getCountries(spreadsheet)
elif action == 'library_director':
mediaItems = service.gSpreadsheet.getDirector(spreadsheet)
elif action == 'library_studio':
mediaItems = service.gSpreadsheet.getStudio(spreadsheet)
elif action == 'library_resolution':
mediaItems = service.gSpreadsheet.getResolution(spreadsheet)
#ensure that folder view playback
if contextType == '':
contextType = 'video'
tmdb= TMDB.TMDB(service,addon, user_agent)
if mediaItems:
for item in mediaItems:
if item.file is None:
service.addDirectory(item.folder, contextType=contextType)
else:
# movieID = tmdb.movieSearch(item.file.title,item.file.year)
# tmdb.movieDetails(movieID)
service.addMediaFile(item, contextType=contextType)
service.updateAuthorization(addon)
#dump a list of videos available to play
elif mode == 'main' or mode == 'index':
folderID = settings.getParameter('folder', False)
folderName = settings.getParameter('foldername', False)
#ensure that folder view playback
if contextType == '':
contextType = 'video'
# display option for all Videos/Music/Photos, across gdrive
#** gdrive specific
if mode == 'main':
if ('gdrive' in addon_parameters.PLUGIN_NAME):
if contentType in (2,4,7):
kodi_common.addMenu(PLUGIN_URL+'?mode=index&folder=ALL&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30018)+' '+addon.getLocalizedString(30030)+']')
elif contentType == 1:
kodi_common.addMenu(PLUGIN_URL+'?mode=index&folder=VIDEOMUSIC&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30018)+' '+addon.getLocalizedString(30031)+']')
elif contentType == 0:
kodi_common.addMenu(PLUGIN_URL+'?mode=index&folder=VIDEO&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30018)+' '+addon.getLocalizedString(30025)+']')
elif contentType == 3:
kodi_common.addMenu(PLUGIN_URL+'?mode=index&folder=MUSIC&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30018)+' '+addon.getLocalizedString(30094)+']')
elif contentType == 5:
kodi_common.addMenu(PLUGIN_URL+'?mode=index&folder=PHOTO&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30018)+' '+addon.getLocalizedString(30034)+']')
elif contentType == 6:
kodi_common.addMenu(PLUGIN_URL+'?mode=index&folder=PHOTOMUSIC&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30018)+' '+addon.getLocalizedString(30032)+']')
folderID = 'root'
if ('gdrive' in addon_parameters.PLUGIN_NAME):
# if (service.protocol != 2):
# kodi_common.addMenu(PLUGIN_URL+'?mode=index&folder=STARRED-FILES&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30018)+ ' '+addon.getLocalizedString(30095)+']')
# kodi_common.addMenu(PLUGIN_URL+'?mode=index&folder=STARRED-FOLDERS&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30018)+ ' '+addon.getLocalizedString(30096)+']')
kodi_common.addMenu(PLUGIN_URL+'?mode=index&folder=SHARED&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30018)+ ' '+addon.getLocalizedString(30098)+']')
kodi_common.addMenu(PLUGIN_URL+'?mode=index&folder=STARRED-FILESFOLDERS&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30018)+ ' '+addon.getLocalizedString(30097)+']')
kodi_common.addMenu(PLUGIN_URL+'?mode=search&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30111)+']')
kodi_common.addMenu(PLUGIN_URL+'?mode=buildstrm2&instance='+str(service.instanceName)+'&content_type='+str(contextType),'<Testing - manual run of change tracking build STRM>')
if addon_parameters.testing_features:
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_dbtest&instance='+str(service.instanceName)+'&action=library_menu&content_type='+str(contextType),'[MOVIES]')
#CLOUD_DB
if 'gdrive' in addon_parameters.PLUGIN_NAME and service.gSpreadsheet is not None:
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_db&action=recentstarted&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30177)+' recently started]')
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_db&action=recentwatched&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30177)+' recently watched]')
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_db&action=library&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30177)+' library]')
kodi_common.addMenu(PLUGIN_URL+'?mode=cloud_db&action=queued&instance='+str(service.instanceName)+'&content_type='+contextType,'['+addon.getLocalizedString(30177)+' queued]')
##**
# cloudservice - validate service
try:
service
except NameError:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30051), addon.getLocalizedString(30052))
xbmc.log(addon.getLocalizedString(30050)+ addon_parameters.PLUGIN_NAME+'-login', xbmc.LOGERROR)
xbmcplugin.endOfDirectory(plugin_handle)
#if encrypted, get everything(as encrypted files will be of type application/ostream)
if encfs:
#temporarly force crypto with encfs
settings.setCryptoParameters()
if settings.cryptoPassword != "":
mediaItems = service.getMediaList(folderID,contentType=8)
if mediaItems:
from resources.lib import encryption
encrypt = encryption.encryption(settings.cryptoSalt,settings.cryptoPassword)
if contentType == 9:
mediaList = ['.mp4', '.flv', '.mov', '.webm', '.avi', '.ogg', '.mkv']
elif contentType == 10:
mediaList = ['.mp3', '.flac']
else:# contentType == 11:
mediaList = ['.jpg', '.png']
media_re = re.compile("|".join(mediaList), re.I)
#create the files and folders for decrypting file/folder names
for item in mediaItems:
if item.file is None:
try:
item.folder.displaytitle = encrypt.decryptString(str(item.folder.title))
service.addDirectory(item.folder, contextType=contextType, encfs=True )
except: pass
else:
try:
item.file.displaytitle = encrypt.decryptString(str(item.file.title))
item.file.title = item.file.displaytitle
if contentType < 9 or media_re.search(str(item.file.title)):
service.addMediaFile(item, contextType=contextType, encfs=True)
except:
pass
else:
settings.setEncfsParameters()
encryptedPath = settings.getParameter('epath', '')
dencryptedPath = settings.getParameter('dpath', '')
encfs_source = settings.encfsSource
encfs_target = settings.encfsTarget
encfs_inode = settings.encfsInode
mediaItems = service.getMediaList(folderID,contentType=8)
if mediaItems:
dirListINodes = {}
fileListINodes = {}
#create the files and folders for decrypting file/folder names
for item in mediaItems:
if item.file is None:
xbmcvfs.mkdir(encfs_source + str(encryptedPath))
xbmcvfs.mkdir(encfs_source + str(encryptedPath) + str(item.folder.title) + '/' )
if encfs_inode == 0:
dirListINodes[(str(xbmcvfs.Stat(encfs_source + str(encryptedPath) + str(item.folder.title)).st_ino()))] = item.folder
else:
dirListINodes[(str(xbmcvfs.Stat(encfs_source + str(encryptedPath) + str(item.folder.title)).st_ctime()))] = item.folder
#service.addDirectory(item.folder, contextType=contextType, encfs=True)
else:
xbmcvfs.mkdir(encfs_source + str(encryptedPath))
xbmcvfs.mkdir(encfs_source + str(encryptedPath) + str(item.file.title))
if encfs_inode == 0:
fileListINodes[(str(xbmcvfs.Stat(encfs_source + str(encryptedPath)+ str(item.file.title)).st_ino()))] = item
else:
fileListINodes[(str(xbmcvfs.Stat(encfs_source + str(encryptedPath) + str(item.file.title)).st_ctime()))] = item
#service.addMediaFile(item, contextType=contextType)
if encfs_inode > 0:
xbmc.sleep(1000)
if contentType == 9:
mediaList = ['.mp4', '.flv', '.mov', '.webm', '.avi', '.ogg', '.mkv']
elif contentType == 10:
mediaList = ['.mp3', '.flac']
else:# contentType == 11:
mediaList = ['.jpg', '.png']
media_re = re.compile("|".join(mediaList), re.I)
#examine the decrypted file/folder names for files for playback and dirs for navigation
dirs, files = xbmcvfs.listdir(encfs_target + str(dencryptedPath) )
for dir in dirs:
index = ''
if encfs_inode == 0:
index = str(xbmcvfs.Stat(encfs_target + str(dencryptedPath) + dir).st_ino())
else:
index = str(xbmcvfs.Stat(encfs_target + str(dencryptedPath) + dir).st_ctime())
#we found a directory
if index in dirListINodes.keys():
xbmcvfs.rmdir(encfs_target + str(dencryptedPath) + dir)
# dirTitle = dir + ' [' +dirListINodes[index].title+ ']'
encryptedDir = dirListINodes[index].title
dirListINodes[index].displaytitle = dir + ' [' +dirListINodes[index].title+ ']'
service.addDirectory(dirListINodes[index], contextType=contextType, encfs=True, dpath=str(dencryptedPath) + str(dir) + '/', epath=str(encryptedPath) + str(encryptedDir) + '/' )
#we found a file
elif index in fileListINodes.keys():
xbmcvfs.rmdir(encfs_target + str(dencryptedPath) + dir)
fileListINodes[index].file.decryptedTitle = dir
if contentType < 9 or media_re.search(str(dir)):
service.addMediaFile(fileListINodes[index], contextType=contextType, encfs=True, dpath=str(dencryptedPath) + str(dir), epath=str(encryptedPath) )
# file is already downloaded
for file in files:
index = ''
if encfs_inode == 0:
index = str(xbmcvfs.Stat(encfs_target + str(dencryptedPath) + file).st_ino())
else:
index = str(xbmcvfs.Stat(encfs_target + str(dencryptedPath) + file).st_ctime())
if index in fileListINodes.keys():
fileListINodes[index].file.decryptedTitle = file
if contentType < 9 or media_re.search(str(file)):
service.addMediaFile(fileListINodes[index], contextType=contextType, encfs=True, dpath=str(dencryptedPath) + str(file), epath=str(encryptedPath) )
#xbmc.executebuiltin("XBMC.Container.Refresh")
else:
path = settings.getParameter('epath', '')
# real folder
if folderID != '':
mediaItems = service.getMediaList(folderID,contentType=contentType)
if addon_parameters.spreadsheet and service.cloudResume == '2':
if service.gSpreadsheet is None:
service.gSpreadsheet = gSpreadsheets.gSpreadsheets(service,addon, user_agent)
if service.worksheetID != '':
service.gSpreadsheet.updateMediaPackageList(service.worksheetID, folderID, mediaItems)
if mediaItems:
for item in sorted(mediaItems):
if item.file is None:
service.addDirectory(item.folder, contextType=contextType, epath=str(path)+ '/' + str(item.folder.title) + '/')
else:
service.addMediaFile(item, contextType=contextType)
# virtual folder; exists in spreadsheet only
# not in use
#elif folderName != '':
service.updateAuthorization(addon)
# NOT IN USE
#** testing - gdrive
elif mode == 'kiosk':
spreadshetModule = settings.getSetting('library', False)
if spreadshetModule:
gSpreadsheet = gSpreadsheets.gSpreadsheets(service,addon, user_agent)
service.gSpreadsheet = gSpreadsheet
spreadsheets = service.getSpreadsheetList()
channels = []
for title in spreadsheets.iterkeys():
if title == 'TVShows':
worksheets = gSpreadsheet.getSpreadsheetWorksheets(spreadsheets[title])
if 0:
import time
hour = time.strftime("%H")
minute = time.strftime("%M")
weekDay = time.strftime("%w")
month = time.strftime("%m")
day = time.strftime("%d")
for worksheet in worksheets.iterkeys():
if worksheet == 'schedule':
channels = gSpreadsheet.getChannels(worksheets[worksheet])
ret = xbmcgui.Dialog().select(addon.getLocalizedString(30112), channels)
shows = gSpreadsheet.getShows(worksheets[worksheet] ,channels[ret])
showList = []
for show in shows:
showList.append(shows[show][6])
ret = xbmcgui.Dialog().select(addon.getLocalizedString(30112), showList)
for worksheet in worksheets.iterkeys():
if worksheet == 'data':
episodes = gSpreadsheet.getVideo(worksheets[worksheet] ,showList[ret])
#player = gPlayer.gPlayer()
#player.setService(service)
player.setContent(episodes)
player.setWorksheet(worksheets['data'])
player.next()
while not player.isExit:
xbmc.sleep(5000)
else:
for worksheet in worksheets.iterkeys():
if worksheet == 'db':
episodes = gSpreadsheet.getMedia(worksheets[worksheet], service.getRootID())
#player = gPlayer.gPlayer()
#player.setService(service)
# player.setContent(episodes)
player.setWorksheet(worksheets['db'])
player.PlayStream('plugin://plugin.video.'+addon_parameters.PLUGIN_NAME+'-testing/?mode=video&instance='+str(service.instanceName)+'&title='+episodes[0][3], None,episodes[0][7],episodes[0][2])
#player.next()
while not player.isExit:
player.saveTime()
xbmc.sleep(5000)
##** not in use
elif mode == 'photo':
title = settings.getParameter('title',0)
title = re.sub('/', '_', title) #remap / from titles (google photos)
docid = settings.getParameter('filename')
folder = settings.getParameter('folder',0)
encfs = settings.getParameter('encfs', False)
if encfs:
settings.setEncfsParameters()
encryptedPath = settings.getParameter('epath', '')
dencryptedPath = settings.getParameter('dpath', '')
encfs_source = settings.encfsSource
encfs_target = settings.encfsTarget
encfs_inode = settings.encfsInode
# don't redownload if present already
if (not xbmcvfs.exists(str(encfs_source) + str(encryptedPath) +str(title))):
url = service.getDownloadURL(docid)
service.downloadGeneralFile(url, str(encfs_source) + str(encryptedPath) +str(title))
xbmc.executebuiltin("XBMC.ShowPicture(\""+str(encfs_target) + str(dencryptedPath)+"\")")
#item = xbmcgui.ListItem(path=str(encfs_target) + str(dencryptedPath))
#xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
else:
path = settings.getSetting('photo_folder')
#workaround for this issue: https://github.com/xbmc/xbmc/pull/8531
if not xbmcvfs.exists(path) and not os.path.exists(path):
path = ''
while path == '':
path = xbmcgui.Dialog().browse(0,addon.getLocalizedString(30038), 'files','',False,False,'')
#workaround for this issue: https://github.com/xbmc/xbmc/pull/8531
if not xbmcvfs.exists(path) and not os.path.exists(path):
path = ''
else:
addon.setSetting('photo_folder', path)
if (not xbmcvfs.exists(str(path) + '/'+str(folder) + '/')):
xbmcvfs.mkdir(str(path) + '/'+str(folder))
# try:
# xbmcvfs.rmdir(str(path) + '/'+str(folder)+'/'+str(title))
# except:
# pass
# don't redownload if present already
if (not xbmcvfs.exists(str(path) + '/'+str(folder)+'/'+str(title))):
url = service.getDownloadURL(docid)
service.downloadPicture(url, str(path) + '/'+str(folder) + '/'+str(title))
#xbmc.executebuiltin("XBMC.ShowPicture("+str(path) + '/'+str(folder) + '/'+str(title)+")")
#item = xbmcgui.ListItem(path=str(path) + '/'+str(folder) + '/'+str(title))
url = service.getDownloadURL(docid)
item = xbmcgui.ListItem(path=url + '|' + service.getHeadersEncoded())
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
elif mode == 'downloadfolder':
title = settings.getParameter('title')
folderID = settings.getParameter('folder')
folderName = settings.getParameter('foldername')
encfs = settings.getParameter('encfs', False)
try:
service
except NameError:
xbmcgui.Dialog().ok(addon.getLocalizedString(30000), addon.getLocalizedString(30051), addon.getLocalizedString(30052))
xbmc.log(addon.getLocalizedString(30050)+ addon_parameters.PLUGIN_NAME + '-login',xbmc.LOGERROR)
xbmcplugin.endOfDirectory(plugin_handle)
if encfs:
settings.setEncfsParameters()
encryptedPath = settings.getParameter('epath', '')
dencryptedPath = settings.getParameter('dpath', '')
encfs_source = settings.encfsSource
encfs_target = settings.encfsTarget
encfs_inode = settings.encfsInode
else:
path = settings.getParameter('epath', '/')
if encfs:
mediaItems = service.getMediaList(folderName=folderID, contentType=8)
path = str(encfs_source) + str(encryptedPath)
else:
mediaItems = service.getMediaList(folderName=folderID, contentType=contentType)
path = str(settings.getSetting('photo_folder')) + str(path)
if mediaItems:
progress = xbmcgui.DialogProgressBG()
progressBar = len(mediaItems)
progress.create(addon.getLocalizedString(30092), '')
count=0
if not xbmcvfs.exists(path) and not os.path.exists(path):
xbmcvfs.mkdirs(path)
for item in mediaItems:
count = count + 1
if item.file is not None:
progress.update((int)(float(count)/len(mediaItems)*100),addon.getLocalizedString(30092), str(item.file.title))
service.downloadGeneralFile(item.getMediaURL(),str(path) + str(item.file.title) )
# elif item.folder is not None:
# # create path if doesn't exist
# if (not xbmcvfs.exists(str(path) + '/'+str(folder) + '/')):
# xbmcvfs.mkdir(str(path) + '/'+str(folder))
progress.close()
elif mode == 'slideshow':
folder = settings.getParameter('folder',0)
title = settings.getParameter('title',0)
encfs = settings.getParameter('encfs', False)
if encfs:
settings.setEncfsParameters()
encfs_source = settings.encfsSource
encfs_target = settings.encfsTarget
encfs_inode = settings.encfsInode
if (not xbmcvfs.exists(str(encfs_target) + '/'+str(folder) + '/')):
xbmcvfs.mkdir(str(encfs_target) + '/'+str(folder))
folderINode = ''
if encfs_inode == 0:
folderINode = str(xbmcvfs.Stat(encfs_target + '/' + str(folder)).st_ino())
else:
folderINode = str(xbmcvfs.Stat(encfs_target + '/' + str(folder)).st_ctime())
mediaItems = service.getMediaList(folderName=folder, contentType=8)
if mediaItems:
dirs, filesx = xbmcvfs.listdir(encfs_source)