-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathlogos.py
76 lines (69 loc) · 2.5 KB
/
logos.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
import os
import re
import xbmc
import xbmcgui
import xbmcaddon
import xbmcvfs
import urllib
import requests
from rpc import RPC
ADDON = xbmcaddon.Addon(id='script.tvguide.fullscreen')
file_name = 'special://profile/addon_data/script.tvguide.fullscreen/folders.list'
f = xbmcvfs.File(file_name)
items = f.read().splitlines()
f.close()
unique = set(items)
logos = {}
for path in unique:
try:
response = RPC.files.get_directory(media="files", directory=path, properties=["thumbnail"])
except:
continue
files = response["files"]
#dirs = dict([[f["label"], f["file"]] for f in files if f["filetype"] == "directory"])
#links = dict([[f["label"], f["file"]] for f in files if f["filetype"] == "file"])
thumbnails = dict([[f["label"], f["thumbnail"]] for f in files if f["filetype"] == "file"])
match = re.match(r"plugin://(.*?)/",path)
if match:
plugin = match.group(1)
else:
match = re.match(r"plugin://(.*?)$",path)
if match:
plugin = match.group(1)
else:
continue
if plugin not in logos:
logos[plugin] = {}
thumbs = logos[plugin]
for file in thumbnails:
thumb = thumbnails[file]
thumbs[file] = thumb
logo_folder = 'special://profile/addon_data/script.tvguide.fullscreen/addon_logos/'
for addonId in sorted(logos):
folder = 'special://profile/addon_data/script.tvguide.fullscreen/addon_logos/%s' % addonId
xbmcvfs.mkdirs(folder)
addonLogos = logos[addonId]
for label in sorted(addonLogos):
logo = addonLogos[label]
if logo:
label = re.sub(r'[:/\\]', '',label)
label = label.strip()
label = re.sub(r"\[/?[BI]\]",'',label)
label = re.sub(r"\[/?COLOR.*?\]",'',label)
logo = re.sub(r'^image://','',logo)
logo = urllib.unquote_plus(logo)
logo = logo.strip('/')
file_name = "%s/%s.png" % (folder,label)
if not xbmcvfs.exists(file_name):
try:
r = requests.get(logo)
if r.status_code == 200:
f = xbmcvfs.File(file_name, 'wb')
chunk_size = 16 * 1024
for chunk in r.iter_content(chunk_size):
f.write(chunk)
f.close()
except Exception as detail:
xbmcvfs.copy(logo,file_name)
dialog = xbmcgui.Dialog()
dialog.notification("TV Guide Fullscreen","Done: Download Logos")