-
Notifications
You must be signed in to change notification settings - Fork 8
/
mezzmo.py
1866 lines (1658 loc) · 100 KB
/
mezzmo.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
import sys
import pickle
import xbmcgui
import xbmcplugin
import ssdp
import xbmcaddon
import xbmcvfs
import urllib.request, urllib.error, urllib.parse
import xml.etree.ElementTree
import re
import xml.etree.ElementTree as ET
import browse
import contentrestriction
import xbmc
import datetime
import time
import json
import os
import media
import sync
from server import updateServers, getContentURL, picDisplay, showSingle, delServer
from server import clearPictures, updatePictures, addServers, checkSync, downServer
from server import onlyDiscMezzmo
from views import content_mapping, setViewMode
from generic import ghandleBrowse, gBrowse
addon = xbmcaddon.Addon()
base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
argmod = sys.argv[2][1:].replace(';','&') # Handle change in urllib parsing to default to &
args = urllib.parse.parse_qs(argmod)
#xbmc.log('Name of script: ' + str(sys.argv[0]), xbmc.LOGINFO)
#xbmc.log('Number of arguments: ' + str(len(sys.argv)), xbmc.LOGINFO)
#xbmc.log('The arguments are: ' + str(args), xbmc.LOGINFO)
addon_path = addon.getAddonInfo("path")
addon_icon = addon_path + '/resources/icon.png'
addon_fanart = addon_path + '/resources/fanart.jpg'
searchcontrol = 'browse'
searchcontrol2 = ''
installed_version = media.get_installedversion()
def perfStats(TotalMatches, brtime, endtime, patime, srtime, ctitle, pobject): # Log performance stats
tduration = endtime - brtime
sduration = (patime - brtime) + srtime
pduration = tduration - sduration
displayrate = int(TotalMatches) / tduration
try:
psfile = media.openNosyncDB() # Open Perf Stats database
xbmc.log('Mezzmo perfstats: ' + str(ctitle) + ' ' + str(pobject), xbmc.LOGDEBUG)
currDate = datetime.datetime.now().strftime('%Y-%m-%d')
currTime = datetime.datetime.now().strftime('%H:%M:%S')
if ctitle != ".." and ctitle != "": # Do not save Go up and refresh actions
sduration = '{:.2f}'.format(sduration) + "s"
pduration = '{:.2f}'.format(pduration) + "s"
tduration = '{:.2f}'.format(tduration) + "s"
displayrate = "{:.2f}".format(displayrate) + " i/s"
objects = psfile.execute('SELECT psPlaylist FROM mperfIndex WHERE psObject=?', (pobject,))
objtuple = objects.fetchone()
if objtuple == None: # Ensure objectId doesn't exist
psfile.execute('INSERT into mperfIndex (psObject, psPlaylist) values (?, ?)', (pobject, ctitle))
else:
ctitle = objtuple[0]
psfile.execute('INSERT into mperfStats (psDate, psTime, psPlaylist, psCount, pSrvTime, mSrvTime, \
psTTime, psDispRate) values (?, ?, ?, ?, ?, ?, ?, ?)', (currDate, currTime, ctitle, TotalMatches, \
pduration, sduration, tduration, displayrate))
psfile.commit()
psfile.close()
except:
xbmc.log('Mezzmo there was a problem adding perfstats to the database: ', xbmc.LOGINFO)
pass
def message(msg):
__addon__ = xbmcaddon.Addon()
__addonname__ = __addon__.getAddonInfo('name')
xbmcgui.Dialog().ok(__addonname__, str(msg))
def listServers(force):
timeoutval = float(media.settings('ssdp_timeout'))
contenturl = ''
msgdialogprogress = xbmcgui.DialogProgress()
dialogmsg = media.translate(30402)
dialoghead = media.translate(30398)
msgdialogprogress.create(dialoghead, dialogmsg)
saved_servers = media.settings('saved_servers')
if len(saved_servers) < 5 or saved_servers == 'none' or force:
srvrlist = ssdp.discover("urn:schemas-upnp-org:device:MediaServer:1", timeout=timeoutval)
xbmc.log('Mezzmo UPnP servers found: ' + str(srvrlist), xbmc.LOGDEBUG)
servers = onlyDiscMezzmo(srvrlist)
# save the servers for faster loading
media.settings('saved_servers', pickle.dumps(servers,0,fix_imports=True))
else:
saved_servers = saved_servers.encode('utf-8')
servers = pickle.loads(saved_servers, fix_imports=True)
onlyShowMezzmo = media.settings('only_mezzmo_servers') == 'true'
itemurl = build_url({'mode': 'serverList', 'refresh': True})
li = xbmcgui.ListItem(addon.getLocalizedString(30347))
li.setArt({'icon': addon_path + '/resources/media/refresh.png'})
xbmcplugin.addDirectoryItem(handle=addon_handle, url=itemurl, listitem=li, isFolder=True)
itemurl = build_url({'mode': 'manual'})
li = xbmcgui.ListItem(addon.getLocalizedString(30447))
li.setArt({'icon': addon_icon})
xbmcplugin.addDirectoryItem(handle=addon_handle, url=itemurl, listitem=li, isFolder=True)
srvcount = len(servers)
addtlmsg = ' ' + str(srvcount) + ' UPnP servers discovered.'
ddialogmsg = dialogmsg + addtlmsg
msgdialogprogress.update(50, ddialogmsg)
if force:
xbmc.sleep(1000)
a = sselect = 0
mgenlog ='Mezzmo server search: ' + str(srvcount) + ' UPnP servers found.'
#xbmc.log(mgenlog, xbmc.LOGINFO)
media.mgenlogUpdate(mgenlog)
for server in servers:
try:
url = server.location
except:
url = server.get('serverurl')
try:
response = urllib.request.urlopen(url, timeout=int(timeoutval))
xmlstring = re.sub(' xmlns="[^"]+"', '', response.read().decode(), count=1)
e = xml.etree.ElementTree.fromstring(xmlstring)
mgenlog ='Mezzmo UPnP server url: ' + url[:48]
#xbmc.log(mgenlog, xbmc.LOGINFO)
media.mgenlogUpdate(mgenlog)
device = e.find('device')
friendlyname = device.find('friendlyName').text
manufacturer = device.find('manufacturer')
if manufacturer != None:
manufacturer = manufacturer.text
else:
manufacturer = 'None'
modelnumber = device.find('modelNumber')
if modelnumber != None:
modelnumber = modelnumber.text
else:
modelnumber = 'None'
udn = device.find('UDN')
if udn != None:
udn = udn.text
else:
udn = 'None'
description = device.find('modelDescription')
if description != None:
description = description.text
else:
description = 'None'
serviceList = device.find('serviceList')
iconList = device.find('iconList')
iconurl = ''
isMezzmo = False
if manufacturer != None and manufacturer == 'Conceiva Pty. Ltd.':
iconurl = addon_icon
isMezzmo = True
elif iconList != None:
bestWidth = 0
for icon in iconList.findall('icon'):
mimetype = icon.find('mimetype').text
width = icon.find('width').text
height = icon.find('height').text
width = int(width)
if width > bestWidth:
bestWidth = width
iconurl = icon.find('url').text
if iconurl.startswith('/'):
end = url.find('/', 8)
length = len(url)
iconurl = url[:end-length] + iconurl
else:
end = url.rfind('/')
length = len(url)
iconurl = url[:end-length] + '/' + iconurl
else:
iconurl = addon_path + '/resources/media/otherserver.png'
if isMezzmo or onlyShowMezzmo == False:
contenturl = ''
for service in serviceList.findall('service'):
serviceId = service.find('serviceId')
if serviceId.text == 'urn:upnp-org:serviceId:ContentDirectory':
contenturl = service.find('controlURL').text
if contenturl.startswith('/'):
end = url.find('/', 8)
length = len(url)
contenturl = url[:end-length] + contenturl
elif 'http' not in contenturl:
end = url.rfind('/')
length = len(url)
contenturl = url[:end-length] + '/' + contenturl
itemurl = build_url({'mode': 'server', 'contentdirectory': contenturl})
li = xbmcgui.ListItem(friendlyname)
li.setArt({'thumb': iconurl, 'poster': iconurl, 'icon': iconurl, 'fanart': addon_fanart})
xbmcplugin.addDirectoryItem(handle=addon_handle, url=itemurl, listitem=li, isFolder=True)
updateServers(url, friendlyname, contenturl, manufacturer, modelnumber, iconurl, description, udn)
except (urllib.error.URLError, urllib.error.HTTPError) : # Detect Server Issues
mgenlog = 'Mezzmo UPnP server not responding: ' + url
xbmc.log(mgenlog, xbmc.LOGINFO)
media.mgenlogUpdate(mgenlog)
dialog_text = media.translate(30405) + '\n\n' + url
sselect = xbmcgui.Dialog().yesno(media.translate(30404), dialog_text)
if sselect == 1: # Delete nonresponding UPnP server
delServer(url)
except Exception as e:
media.printexception()
a += 1
percent = int(a / float(srvcount) * 50) + 50
dialogmsg = str(a) + ' / ' + str(srvcount) + ' server completed.'
msgdialogprogress.update(percent, dialogmsg)
if srvcount > 5:
xbmc.sleep(200)
else:
xbmc.sleep(100)
msgdialogprogress.close()
setViewMode('servers')
xbmcplugin.endOfDirectory(addon_handle, updateListing=force )
if sselect == 1: # Reset UPnP delete flag after listing
sselect = 0
if contenturl != None:
media.kodiCleanDB(0) # Call function to delete Kodi actor database if user enabled.
if media.settings('kodiclean') == 'resync':
syncpin = media.settings('content_pin')
syncurl = checkSync(0) # Get server control URL
if syncpin and syncurl != 'None':
sync.syncMezzmo(syncurl, syncpin, 15) # Trigger resync process
media.settings('kodiclean', 'false') # reset back to false after resync
def build_url(query):
return base_url + '?' + urllib.parse.urlencode(query)
def handleBrowse(content, contenturl, objectID, parentID):
contentType = 'movies'
itemsleft = -1
pitemsleft = -1
global brtime, patime
srtime = 0
media.settings('contenturl', contenturl)
koditv = media.settings('koditv')
knative = media.settings('knative')
kdirector = media.settings('kdirector')
nativeact = media.settings('nativeact')
perflog = media.settings('perflog')
musicvid = media.settings('musicvid') # Check if musicvideo sync is enabled
duplogs = media.settings('mdupelog') # Check if Mezzmo duplicate logging is enabled
synlogs = media.settings('kodisync') # Check if Mezzmo background sync is enabled
slideshow = media.settings('slideshow') # Check if slideshow is enabled
kodichange = media.settings('kodichange') # Checks for change detection user setting
kodiactor = media.settings('kodiactor') # Checks for actor info setting
trcount = media.settings('trcount') # Checks multiple trailer setting
sstudio = media.settings('singlestudio') # Checks for single studio setting
mbackdrop = media.settings('mbackdrop') # Checks container backdrop setting
enhdesc = media.settings('enhdesc') # Enhanced description setting
kodiart = media.settings('kodiart') # Additional Kodi artwork
menuitem1 = addon.getLocalizedString(30347)
menuitem2 = addon.getLocalizedString(30346)
menuitem3 = addon.getLocalizedString(30372)
menuitem4 = addon.getLocalizedString(30373)
menuitem5 = addon.getLocalizedString(30379)
menuitem6 = addon.getLocalizedString(30380)
menuitem7 = addon.getLocalizedString(30384)
menuitem8 = addon.getLocalizedString(30412)
menuitem9 = addon.getLocalizedString(30434)
menuitem10 = addon.getLocalizedString(30435)
autostart = media.settings('autostart')
sync.deleteTexturesCache(contenturl) # Call function to delete textures cache if user enabled.
#xbmc.log('Kodi version: ' + installed_version, xbmc.LOGINFO)
try:
while True:
if len(content) == 0: # Handle downed server
downServer() # Down server response
break; #sanity check
e = xml.etree.ElementTree.fromstring(content)
body = e.find('.//{http://schemas.xmlsoap.org/soap/envelope/}Body')
browseresponse = body.find('.//{urn:schemas-upnp-org:service:ContentDirectory:1}BrowseResponse')
result = browseresponse.find('Result')
NumberReturned = browseresponse.find('NumberReturned').text
TotalMatches = browseresponse.find('TotalMatches').text
if int(NumberReturned) == 0:
dialog_text = media.translate(30421) + '\n' + xbmc.getInfoLabel("ListItem.Label")
xbmcgui.Dialog().ok(media.translate(30423), dialog_text)
xbmc.executebuiltin('Action(ParentDir)')
break; #sanity check
if itemsleft == -1:
itemsleft = int(TotalMatches)
#elems = xml.etree.ElementTree.fromstring(result.text.encode('utf-8'))
elems = xml.etree.ElementTree.fromstring(result.text)
picnotify = 0
for container in elems.findall('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}container'):
title = container.find('.//{http://purl.org/dc/elements/1.1/}title').text
containerid = container.get('id')
description_text = ''
description = container.find('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}longDescription')
if description != None and description.text != None:
description_text = description.text
icon = container.find('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}albumArtURI')
if icon != None:
icon = icon.text
#if (icon[-4:]) != '.jpg':
# icon = icon + '.jpg'
xbmc.log('Handle browse initial icon is: ' + icon, xbmc.LOGDEBUG)
cbackdropurl = container.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}cvabackdrop')
if cbackdropurl != None and mbackdrop == 'Mezzmo':
cbackdropurl = cbackdropurl.text
#if '.jpg' not in cbackdropurl:
# cbackdropurl = cbackdropurl + '.jpg'
else:
cbackdropurl = addon_fanart
itemurl = build_url({'mode': 'server', 'parentID': objectID, 'objectID': containerid, \
'contentdirectory': contenturl})
li = xbmcgui.ListItem(title, offscreen=True)
mediaClass_text = 'video'
if installed_version == '19': # Kodi 19 format
info = {
'plot': description_text,
}
li.setInfo(mediaClass_text, info)
else: # Kodi 20 format
finfo = li.getVideoInfoTag()
finfo.setTitle(title)
finfo.setPlot(description_text)
finfo.setMediaType(mediaClass_text)
if mbackdrop != 'None':
li.setArt({'banner': icon, 'poster': icon, 'icon': icon, 'fanart': cbackdropurl})
else:
li.setArt({'banner': icon, 'poster': icon, 'icon': icon})
searchargs = urllib.parse.urlencode({'mode': 'search', 'contentdirectory': contenturl, \
'objectID': containerid})
itempath = xbmc.getInfoLabel("ListItem.FileNameAndPath ")
autitle = xbmc.getInfoLabel("ListItem.Label") # Get title of selected playlist
if (autostart == '' or autostart == 'clear' or len(autostart) < 6):
li.addContextMenuItems([ (menuitem1, 'Container.Refresh'), (menuitem2, 'Action(ParentDir)'), \
('Search', 'Container.Update( plugin://plugin.video.mezzmo?' + searchargs + ')'), \
(menuitem7, 'RunScript(%s, %s)' % ("plugin.video.mezzmo", "performance")), (menuitem5, \
'RunScript(%s, %s, %s, %s)' % ("plugin.video.mezzmo", "auto", itempath, autitle)) ])
elif len(autostart) > 6 :
li.addContextMenuItems([ (menuitem1, 'Container.Refresh'), (menuitem2, 'Action(ParentDir)'), \
('Search', 'Container.Update( plugin://plugin.video.mezzmo?' + searchargs + ')'), \
(menuitem7, 'RunScript(%s, %s)' % ("plugin.video.mezzmo", "performance")), (menuitem6, \
'RunScript(%s, %s, %s, %s)' % ("plugin.video.mezzmo", "auto", "clear", autitle)) ])
if '###' not in title:
xbmcplugin.addDirectoryItem(handle=addon_handle, url=itemurl, listitem=li, isFolder=True)
picnotify += 1
if parentID == '0':
contentType = 'top'
else:
contentType = 'folders'
contentType = content_mapping(contentType)
piclist = []
clearPictures()
ctitle = xbmc.getInfoLabel("ListItem.Label") # Get title of selected playlist
xbmc.log('Mezzmo content title: ' + ctitle + ' ' + str(parentID) + ' ' + objectID + \
' Content type: ' + contentType, xbmc.LOGDEBUG)
dbfile = media.openKodiDB() # Open Kodi database
for item in elems.findall('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}item'):
title = item.find('.//{http://purl.org/dc/elements/1.1/}title').text
itemid = item.get('id')
icon = None
albumartUri = item.find('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}albumArtURI')
if albumartUri != None:
icon = albumartUri.text
#if (icon[-4:]) != '.jpg':
# icon = icon + '.jpg'
xbmc.log('Handle browse second icon is: ' + icon, xbmc.LOGDEBUG)
res = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}res')
subtitleurl = None
duration_text = ''
video_width = 0
video_height = 0
aspect = 0.0
validf = 0
if res != None:
itemurl = res.text
#xbmc.log('The current URL is: ' + itemurl, xbmc.LOGINFO)
subtitleurl = res.get('{http://www.pv.com/pvns/}subtitleFileUri')
duration_text = res.get('duration')
if duration_text == None:
duration_text = '00:00:00.000'
resolution_text = res.get('resolution')
if resolution_text != None:
mid = resolution_text.find('x')
video_width = int(resolution_text[0:mid])
video_height = int(resolution_text[mid + 1:])
aspect = float(float(video_width) / float(video_height))
validf = 1 # Set valid file info flag
backdropurl = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}cvabackdrop')
if backdropurl != None:
backdropurl = backdropurl.text
#if (backdropurl [-4:]) != '.jpg':
# backdropurl = backdropurl + '.jpg'
li = xbmcgui.ListItem(title, offscreen=True)
#li.setArt({'thumb': icon, 'poster': icon, 'icon': icon, 'fanart': backdropurl})
if subtitleurl != None:
li.setSubtitles([subtitleurl])
trailerurl = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}trailer')
if trailerurl != None:
trailerurl = trailerurl.text
genre_text = ''
genre = item.find('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}genre')
if genre != None:
genre_text = genre.text
aired_text = ''
aired = item.find('.//{http://purl.org/dc/elements/1.1/}date')
if aired != None:
aired_text = aired.text
album_text = ''
album = item.find('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}album')
if album != None:
album_text = album.text
release_year_text = ''
release_year = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}release_year')
if release_year != None:
release_year_text = release_year.text
release_date_text = ''
release_date = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}release_date')
if release_date != None:
release_date_text = release_date.text
description_text = ''
description = item.find('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}longDescription')
if description != None and description.text != None:
description_text = description.text
imageSearchUrl = ''
imageSearchUrl = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}imageSearchUrl')
if imageSearchUrl != None:
imageSearchUrl = imageSearchUrl.text
artist_text = ''
artist = item.find('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}artist')
if artist != None:
artist_text = artist.text
actor_list = ''
cast_dict = [] # Added cast & thumbnail display from Mezzmo server
cast_dict_keys = ['name','thumbnail']
actors = item.find('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}artist')
if actors != None and imageSearchUrl != None and len(actors.text) > 2:
actor_list = actors.text.replace(', Jr.' , ' Jr.').replace(', Sr.' , ' Sr.').split(',')
if installed_version == '19':
for a in actor_list:
actorSearchUrl = imageSearchUrl + "?imagesearch=" + a.lstrip().replace(" ","+")
#xbmc.log('search URL: ' + actorSearchUrl, xbmc.LOGINFO) # uncomment for thumbnail debugging
new_record = [ a.strip() , actorSearchUrl]
cast_dict.append(dict(list(zip(cast_dict_keys, new_record))))
else:
for a in range(len(actor_list)):
actorSearchUrl = imageSearchUrl + "?imagesearch=" + actor_list[a].lstrip().replace(" ","+")
#xbmc.log('search URL: ' + actorSearchUrl, xbmc.LOGINFO) # uncomment for thumbnail debugging
if len(actor_list[a]) > 0:
actor = xbmc.Actor(actor_list[a].strip(), '', a, actorSearchUrl)
cast_dict.append(actor)
else:
mgenlog = 'Mezzmo issue with actor list in: ' + str(title)
media.mgenlogUpdate(mgenlog)
creator_text = ''
creator = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}creator')
if creator != None:
creator_text = creator.text
date_added_text = ''
date_added = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}date_added')
if date_added != None:
date_added_text = date_added.text
tagline_text = ''
tagline = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}tag_line')
if tagline != None:
tagline_text = tagline.text
tags_text = taglist = ''
tags = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}keywords')
if tags != None:
tags_text = tags.text
taglist = str(tags_text).replace(',', '$')
categories_text = 'movie'
categories = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}categories')
if categories != None and categories.text != None:
categories_text = categories.text
xbmc.log('Mezzmo categories_text: ' + str(categories_text), xbmc.LOGDEBUG)
if album_text:
movieset = album_text
else:
movieset = album_text = ''
if 'trailer' in categories_text.lower():
trtype = categories_text.lower()
else:
trtype = 'video'
if 'tv show' in categories_text.lower():
categories_text = 'episode'
contentType = 'episodes'
showtitle = album_text
elif 'movie' in categories_text.lower() or 'trailer' in categories_text.lower():
categories_text = 'movie'
contentType = 'movies'
showtitle = title
elif 'music video' in categories_text.lower():
categories_text = 'musicvideo'
contentType = 'musicvideos'
showtitle = title
else:
categories_text = 'video'
contentType = 'videos'
showtitle = title
else:
movieset = album_text = trtype = ''
categories_text = 'video'
contentType = 'videos'
showtitle = title
if 'tvtrailer' in trtype and imageSearchUrl != None and actors != None \
and actors.text == 'Unknown Artist': # TV trailer cast search
trcurr = dbfile.execute('select idEpisode FROM episode_view WHERE \
strTitle = ? ORDER BY c12, c13 ASC LIMIT 1', (movieset,))
trtuple = trcurr.fetchone()
cast_dict = []
if trtuple != None:
trcurc = dbfile.execute('SELECT name FROM actor INNER JOIN actor_link \
USING (actor_id) WHERE media_id = ? and media_type = ? ORDER BY \
cast_order ASC LIMIT 20', (trtuple[0], 'episode',))
tctuples = trcurc.fetchall()
xbmc.log('Mezzmo searching Kodi for TV traileractors. ' + str(tctuples), xbmc.LOGDEBUG)
for a in range(len(tctuples)):
actorSearchUrl = imageSearchUrl + "?imagesearch=" + tctuples[a][0].lstrip().replace(" ","+")
#xbmc.log('search URL: ' + actorSearchUrl, xbmc.LOGINFO) # uncomment for thumbnail debugging
if installed_version == '19' and tctuples[a][0] != 'Unknown Artist':
new_record = [ tctuples[a][0] , actorSearchUrl]
cast_dict.append(dict(list(zip(cast_dict_keys, new_record))))
elif tctuples[a][0] != 'Unknown Artist':
actor = xbmc.Actor(tctuples[a][0], '', a, actorSearchUrl)
cast_dict.append(actor)
actor_list = ''
episode_text = ''
episode = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}episode')
if episode != None:
episode_text = episode.text
season_text = season_kodi = ''
season = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}season')
if season != None:
season_text = season.text
if season_text == '0' and 'episode' not in contentType:
season_kodi = None
else:
season_kodi = season_text
playcount = 0
playcount_text = ''
playcountElem = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}playcount')
if playcountElem != None:
playcount_text = playcountElem.text
playcount = int(playcount_text)
last_played_text = ''
last_played = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}last_played')
if last_played != None:
last_played_text = last_played.text
writer_text = ''
writer = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}writers')
if writer != None:
writer_text = writer.text
content_rating_text = ''
content_rating = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}content_rating')
if content_rating != None:
content_rating_text = content_rating.text
imdb_text = ''
imdb = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}imdb_id')
if imdb != None:
imdb_text = imdb.text
moviedb_text = ''
moviedb = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}the_moviedb_id')
if moviedb != None:
moviedb_text = moviedb.text
tvdb_text = ''
tvdb = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}tvdb_id')
if tvdb != None:
tvdb_text = tvdb.text
dcmInfo_text = '0'
dcmInfo = item.find('.//{http://www.sec.co.kr/}dcmInfo')
if dcmInfo != None:
dcmInfo_text = dcmInfo.text
valPos = dcmInfo_text.find('BM=') + 3
dcmInfo_text = dcmInfo_text[valPos:]
rating_val = ''
rating = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}rating')
if rating != None:
rating_val = rating.text
rating_valf = float(rating_val) * 2
rating_val = str(rating_valf) #kodi ratings are out of 10, Mezzmo is out of 5
production_company_text = production_company = ''
production_company = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}production_company')
if production_company != None and sstudio == 'false':
production_company_text = production_company.text
elif production_company != None and sstudio == 'true':
try:
production_company_text = production_company.text.split(',')[0]
except:
pass
sort_title_text = ''
sort_title = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}sort_title')
if sort_title != None:
sort_title_text = sort_title.text
video_codec_text = ''
video_codec = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}video_codec')
if video_codec != None:
video_codec_text = video_codec.text
if video_codec_text == 'vc1': # adjust for proper Kodi codec display
video_codec_text = 'vc-1'
audio_codec_text = ''
audio_codec = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}audio_codec')
if audio_codec != None:
audio_codec_text = audio_codec.text
audio_channels_text = ''
audio_channels = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}audio_channels')
if audio_channels != None:
audio_channels_text = audio_channels.text
audio_lang = ''
audio_streams = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}audio')
if audio_streams != None:
for stream in audio_streams.findall('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}stream'):
if stream.get('selected') == 'auto' or stream.get('selected') == 'true':
audio_lang = stream.get('lang')
break
subtitle_lang = ''
captions_streams = item.find('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}captions')
if captions_streams != None:
for stream in captions_streams.findall('.//{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}stream'):
if stream.get('selected') == 'auto' or stream.get('selected') == 'true':
subtitle_lang = stream.get('language')
break
mediaClass_text = 'video'
mediaClass = item.find('.//{urn:schemas-sony-com:av}mediaClass')
if mediaClass != None:
mediaClass_text = mediaClass.text
if mediaClass_text == 'V':
mediaClass_text = 'video'
if mediaClass_text == 'M':
mediaClass_text = 'music'
if mediaClass_text == 'P':
mediaClass_text = 'pictures'
durationsecs = sync.getSeconds(duration_text) # convert movie duration to seconds
if kodiart == 'false' or categories_text != 'movie' : # Normal artwork
li.setArt({'thumb': icon, 'poster': icon, 'icon': icon, 'fanart': backdropurl})
if mediaClass_text == 'video' and validf == 1:
if enhdesc in ['GUI', 'Both']: # Check for enhanced description
description_text = media.enhancedDesc(last_played_text, \
playcount_text, description_text)
mtitle = media.displayTitles(title) # Normalize title
if kodiart == 'true' and categories_text == 'movie': # Additional artwork
arttitle = media.kodiArtTitle(mtitle)
cleararturl = imageSearchUrl + arttitle + "+clearart"
clearlogourl = imageSearchUrl + arttitle + "+clearlogo"
bannerurl = imageSearchUrl + arttitle + "+banner"
discarturl = imageSearchUrl + arttitle + "+discart"
keyarturl = imageSearchUrl + arttitle + "+keyart"
landscurl = imageSearchUrl + arttitle + "+landscape"
artwork = {'thumb': icon, 'poster': icon, 'icon': icon, 'fanart': backdropurl,
'clearart': cleararturl, 'clearlogo': clearlogourl, 'banner': bannerurl,
'discart': discarturl, 'keyart': keyarturl, 'landscape': landscurl,
}
li.setArt(artwork)
xbmc.log('Mezzmo Kodi artwork is: ' + str(artwork), xbmc.LOGDEBUG)
else:
li.setArt({'thumb': icon, 'poster': icon, 'icon': icon, 'fanart': backdropurl})
pctitle = '"' + mtitle + '"' # Handle commas
pcseries = '"' + album_text + '"' # Handle commas
mtype = categories_text
li.addContextMenuItems([ (menuitem1, 'Container.Refresh'), (menuitem2, 'Action(ParentDir)'), \
(menuitem10, 'RunScript(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' % \
("plugin.video.mezzmo", "context", pctitle, itemurl, season_text, episode_text, playcount, \
pcseries, mtype, contenturl, dcmInfo_text, icon, movieset, taglist, release_year_text, trtype, \
imdb_text))])
if installed_version == '19':
info = {
'duration': durationsecs,
'genre': genre_text,
'year': release_year_text,
'title': title,
'plot': description_text,
'director': creator_text,
'tagline': tagline_text,
'writer': writer_text,
'cast': artist_text.split(','),
'artist': artist_text.split(','),
'rating': rating_val,
'imdbnumber': imdb_text,
'mediatype': categories_text,
'season': season_kodi,
'episode': episode_text,
'lastplayed': last_played_text,
'aired': aired_text,
'mpaa':content_rating_text,
'studio':production_company_text,
'playcount':playcount,
'trailer':trailerurl,
'tvshowtitle':showtitle,
'dateadded':date_added_text,
}
li.setInfo(mediaClass_text, info)
li.setProperty('ResumeTime', dcmInfo_text)
li.setProperty('TotalTime', str(durationsecs))
video_info = {
'codec': video_codec_text,
'aspect': aspect,
'width': video_width,
'height': video_height,
}
li.addStreamInfo('video', video_info)
li.addStreamInfo('audio', {'codec': audio_codec_text, 'language': audio_lang, \
'channels': int(audio_channels_text)})
li.addStreamInfo('subtitle', {'language': subtitle_lang})
li.setCast(cast_dict)
else:
vinfo = li.getVideoInfoTag()
vinfo.setDuration(durationsecs)
if genre_text is not None: vinfo.setGenres(genre_text.split(','))
if len(release_year_text) > 0: vinfo.setYear(int(release_year_text))
vinfo.setTitle(title)
vinfo.setPlot(description_text)
if creator_text is not None: vinfo.setDirectors(creator_text.split(','))
vinfo.setTagLine(tagline_text)
if writer_text is not None: vinfo.setWriters(writer_text.split(','))
if artist_text is not None: vinfo.setArtists(artist_text.split(','))
vinfo.setRating(rating_valf)
vinfo.setIMDBNumber(imdb_text)
vinfo.setMediaType(categories_text)
if season_kodi is not None: vinfo.setSeason(int(season_text))
if episode_text is not None: vinfo.setEpisode(int(episode_text))
vinfo.setLastPlayed(last_played_text)
vinfo.setFirstAired(aired_text)
vinfo.setMpaa(content_rating_text)
if production_company_text is not None: vinfo.setStudios(production_company_text.split(','))
if playcount is not None: vinfo.setPlaycount(int(playcount))
vinfo.setSortTitle(sort_title_text)
vinfo.setTvShowTitle(showtitle)
vinfo.setTrailer(trailerurl)
vinfo.setDateAdded(date_added_text)
vinfo.setResumePoint(float(dcmInfo_text), durationsecs)
vstrinfo = xbmc.VideoStreamDetail(video_width, video_height, aspect, codec=video_codec_text)
vinfo.addVideoStream(vstrinfo)
astrinfo = xbmc.AudioStreamDetail(int(audio_channels_text), audio_codec_text, audio_lang)
vinfo.addAudioStream(astrinfo)
sstrinfo = xbmc.SubtitleStreamDetail(subtitle_lang)
vinfo.addSubtitleStream(sstrinfo)
if 'Unknown Artist' not in actor_list: vinfo.setCast(cast_dict)
tvcheckval = media.tvChecker(season_text, episode_text, koditv, mtitle, categories) # Check if Ok to add
if int(installed_version) >= 19 and kodiactor == 'true' and tvcheckval[0] == 1:
pathcheck = media.getPath(itemurl) # Get path string for media file
serverid = media.getMServer(itemurl) # Get Mezzmo server id
filekey = media.checkDBpath(itemurl, mtitle, playcount, dbfile, pathcheck, serverid, \
season_text, episode_text, album_text, last_played_text, date_added_text, 'false', koditv, \
categories_text, knative, musicvid)
xbmc.log('Mezzmo filekey is: ' + str(filekey), xbmc.LOGDEBUG)
showId = 0 # Set default
if filekey[4] == 1:
showId = media.checkTVShow(filekey, album_text, genre_text, dbfile, content_rating_text, \
production_company_text, icon, backdropurl, knative)
mediaId = media.writeEpisodeToDb(filekey, mtitle, description_text, tagline_text, \
writer_text, creator_text, aired_text, rating_val, durationsecs, genre_text, trailerurl, \
content_rating_text, icon, kodichange, backdropurl, dbfile, production_company_text, \
sort_title_text, season_text, episode_text, showId, 'false', itemurl, imdb_text, tags_text, \
imageSearchUrl, kdirector)
elif filekey[4] == 2:
mediaId = media.writeMusicVToDb(filekey, mtitle, description_text, tagline_text, writer_text, \
creator_text, release_date_text, rating_val, durationsecs, genre_text, trailerurl, \
content_rating_text, icon, kodichange, backdropurl, dbfile, production_company_text, \
sort_title_text, 'false', itemurl, imdb_text, tags_text, knative, movieset, episode_text, \
artist_text, imageSearchUrl, kdirector)
else:
mediaId = media.writeMovieToDb(filekey, mtitle, description_text, tagline_text, writer_text, \
creator_text, release_date_text, rating_val, durationsecs, genre_text, trailerurl, \
content_rating_text, icon, kodichange, backdropurl, dbfile, production_company_text, \
sort_title_text, 'false', itemurl, imdb_text, tags_text, knative, movieset, imageSearchUrl, \
kdirector, int(installed_version))
if (artist != None and filekey[0] > 0) or mediaId == 999999: # Add actor information to new movie
media.writeActorsToDb(artist_text, mediaId, imageSearchUrl, mtitle, dbfile, filekey,
nativeact, showId)
media.writeMovieStreams(filekey, video_codec_text, aspect, video_height, video_width, \
audio_codec_text, audio_channels_text, audio_lang, durationsecs, mtitle, kodichange, itemurl,\
icon, backdropurl, dbfile, pathcheck, 'false', knative) # Update movie stream info
xbmc.log('The movie name is: ' + mtitle, xbmc.LOGDEBUG)
elif mediaClass_text == 'music':
mtitle = media.displayTitles(title) # Normalize title
pctitle = '"' + mtitle + '"' # Handle commas
pcseries = '"' + album_text + '"' # Handle commas
offsetmenu = 'Resume from ' + time.strftime("%H:%M:%S", time.gmtime(int(dcmInfo_text)))
if int(dcmInfo_text) > 0 and playcount == 0:
li.addContextMenuItems([ (menuitem1, 'Container.Refresh'), (menuitem2, 'Action(ParentDir)'), \
(menuitem3, 'RunScript(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' % ("plugin.video.mezzmo", "count", \
pctitle, itemurl, season_text, episode_text, playcount, pcseries, 'audiom', contenturl)), \
(offsetmenu, 'RunScript(%s, %s, %s, %s, %s, %s, %s, %s)' % ("plugin.video.mezzmo", "playm", \
itemurl, li, title, icon, backdropurl, dcmInfo_text)) ])
elif int(dcmInfo_text) > 0 and playcount > 0:
li.addContextMenuItems([ (menuitem1, 'Container.Refresh'), (menuitem2, 'Action(ParentDir)'), \
(menuitem4, 'RunScript(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' % ("plugin.video.mezzmo", "count", \
pctitle, itemurl, season_text, episode_text, playcount, pcseries, 'audiom', contenturl)), \
(offsetmenu, 'RunScript(%s, %s, %s, %s, %s, %s, %s, %s)' % ("plugin.video.mezzmo", "playm", \
itemurl, li, title, icon, backdropurl, dcmInfo_text)), ])
elif int(dcmInfo_text) == 0 and playcount > 0:
li.addContextMenuItems([ (menuitem1, 'Container.Refresh'), (menuitem2, 'Action(ParentDir)'), \
(menuitem4, 'RunScript(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' % ("plugin.video.mezzmo", "count", \
pctitle, itemurl, season_text, episode_text, playcount, pcseries, 'audiom', contenturl)) ])
elif int(dcmInfo_text) == 0 and playcount == 0:
li.addContextMenuItems([ (menuitem1, 'Container.Refresh'), (menuitem2, 'Action(ParentDir)'), \
(menuitem3, 'RunScript(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' % ("plugin.video.mezzmo", "count", \
pctitle, itemurl, season_text, episode_text, playcount, pcseries, 'audiom', contenturl)) ])
info = {
'duration': durationsecs,
'genre': genre_text,
'year': release_year_text,
'title': title,
'artist': artist_text.split(','),
'rating': rating_val,
'discnumber': season_text,
'mediatype': 'song',
'tracknumber': episode_text,
'album': album_text,
'playcount':playcount,
'lastplayed': last_played_text,
}
mcomment = media.mComment(info, duration_text, offsetmenu[11:])
if installed_version == '19':
info.update(comment = mcomment)
li.setInfo(mediaClass_text, info)
else:
minfo = li.getMusicInfoTag()
minfo.setDuration(durationsecs)
if genre_text is not None: minfo.setGenres(genre_text.split(','))
if len(release_year_text) > 0: minfo.setYear(int(release_year_text))
minfo.setTitle(title)
minfo.setComment(mcomment)
if artist_text is not None: minfo.setArtist(artist_text)
minfo.setRating(rating_valf)
if season_text is not None: minfo.setDisc(int(season_text))
minfo.setMediaType('song')
if episode_text is not None: minfo.setTrack(int(episode_text))
minfo.setAlbum(album_text)
if playcount is not None: minfo.setPlayCount(int(playcount))
minfo.setLastPlayed(last_played_text)
validf = 1 # Set valid file info flag
contentType = 'songs'
elif mediaClass_text == 'pictures':
li.addContextMenuItems([ (menuitem1, 'Container.Refresh'), (menuitem2, 'Action(ParentDir)'), \
(menuitem8, 'RunScript(%s, %s)' % ("plugin.video.mezzmo", "pictures")) ])
if installed_version == '19': # Kodi 19 format
info = {
'title': title,
}
li.setInfo(mediaClass_text, info)
else: # Kodi 20 format
pinfo = li.getPictureInfoTag()
validf = 1 # Set valid file info flag
contentType = 'files'
picnotify += 1
itemdict = {
'title': title,
'url': itemurl,
'idate': aired_text,
'iwidth': video_width,
'iheight': video_height,
'idesc': description_text,
}
piclist.append(itemdict)
if picnotify == int(NumberReturned): # Update picture DB
updatePictures(piclist)
if slideshow == 'true': # Slideshow display prompt
picDisplay()
itemurl = build_url({'mode': 'picture', 'itemurl': itemurl})
if validf == 1:
xbmcplugin.addDirectoryItem(handle=addon_handle, url=itemurl, listitem=li, isFolder=False)
else:
dialog_text = "Video file: " + title + " is invalid. Check Mezzmo video properties for this file."
xbmcgui.Dialog().ok("Mezzmo", dialog_text)
itemsleft = itemsleft - int(NumberReturned) - 1
dbfile.commit() # Commit writes
xbmc.log('Mezzmo items left: ' + str(itemsleft), xbmc.LOGDEBUG)
if itemsleft <= 0:
dbfile.commit()
dbfile.close() # Final commit writes and close Kodi database
if int(TotalMatches) > 49 and perflog == "true":
endtime = time.time()
perfStats(TotalMatches, brtime, endtime, patime, srtime, ctitle, objectID)
xbmc.log('Mezzmo perfstats: ' + str(ctitle) + ' ' + str(parentID), xbmc.LOGDEBUG)
break
if pitemsleft == itemsleft: # Detect items left not incrementing
dbfile.commit()
dbfile.close() # Final commit writes and close Kodi database
mgenlog ='Mezzmo items not displayed: ' + str(pitemsleft)
#xbmc.log(mgenlog, xbmc.LOGINFO)
media.mgenlogUpdate(mgenlog)
if int(TotalMatches) > 49 and perflog == "true":
endtime = time.time()
perfStats(TotalMatches, brtime, endtime, patime, srtime, ctitle, objectID)
xbmc.log('Mezzmo perfstats: ' + str(ctitle) + ' ' + str(parentID), xbmc.LOGDEBUG)
break
else:
pitemsleft = itemsleft
# get the next items
offset = int(TotalMatches) - itemsleft
requestedCount = 1000
if itemsleft < 1000:
requestedCount = itemsleft
pin = media.settings('content_pin')
brtime2 = time.time() # Additional browse begin time
content = browse.Browse(contenturl, objectID, 'BrowseDirectChildren', offset, requestedCount, pin)
srtime = srtime + (time.time() - brtime2) # Calculate total server time
except Exception as e:
media.printexception()
pass
setViewMode(contentType)
if contentType == 'top' or contentType == 'folders':
contentType = ''
xbmcplugin.setContent(addon_handle, contentType)
xbmcplugin.addSortMethod(addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(addon_handle, xbmcplugin.SORT_METHOD_DATE)
xbmcplugin.addSortMethod(addon_handle, xbmcplugin.SORT_METHOD_TITLE_IGNORE_THE)
xbmcplugin.addSortMethod(addon_handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
xbmcplugin.addSortMethod(addon_handle, xbmcplugin.SORT_METHOD_GENRE)
xbmcplugin.addSortMethod(addon_handle, xbmcplugin.SORT_METHOD_DURATION)
xbmcplugin.addSortMethod(addon_handle, xbmcplugin.SORT_METHOD_TRACKNUM)
xbmcplugin.endOfDirectory(addon_handle)