forked from rmrector/script.artwork.beef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.py
53 lines (46 loc) · 1.7 KB
/
context.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
import sys
import xbmc
from lib.artworkprocessor import ArtworkProcessor
# DEPRECATED: StringCompare in addon.xml is deprecated in Krypton, gone in Leia,
# but both resolve to False when unrecognized so the result is the same for all versions
def main(mode):
listitem = sys.listitem
mediatype = get_mediatype(listitem)
dbid = get_dbid(listitem)
if dbid and mediatype:
processor = ArtworkProcessor()
processor.process_item(mediatype, dbid, mode)
def get_mediatype(listitem):
try:
item = listitem.getVideoInfoTag().getMediaType()
if not item:
item = listitem.getMusicInfoTag().getMediaType()
return item
except AttributeError:
# DEPRECATED: Before Krypton
pass
count = 0
mediatype = xbmc.getInfoLabel('ListItem.DBTYPE')
while not mediatype and count < 5:
count += 1
xbmc.sleep(200)
mediatype = xbmc.getInfoLabel('ListItem.DBTYPE')
if not mediatype:
xbmc.executebuiltin('Notification(Artwork Beef cannot proceed, "Got an unexpected content type. Try again, it should work.", 6000, DefaultIconWarning.png)')
return mediatype
def get_dbid(listitem):
try:
dbid = listitem.getVideoInfoTag().getDbId()
if dbid == -1:
dbid = listitem.getMusicInfoTag().getDbId()
return dbid
except AttributeError:
# DEPRECATED: Before Krypton
pass
if listitem.getLabel() != xbmc.getInfoLabel('ListItem.Label'):
# InfoLabels can report the wrong item
return int(listitem.getfilename().split('?')[0].rstrip('/').split('/')[-1])
else:
return int(xbmc.getInfoLabel('ListItem.DBID'))
if __name__ == '__main__':
main('auto')