12
12
import xbmc
13
13
from xbmcvfs import exists
14
14
15
- from utils import settings , language as lang , kodi_sql , try_encode , try_decode ,\
16
- thread_methods , dialog , exists_dir
17
- import state
15
+ from . import utils
16
+ from . import state
18
17
19
18
###############################################################################
20
- LOG = getLogger (" PLEX." + __name__ )
19
+ LOG = getLogger (' PLEX.artwork' )
21
20
22
21
# Disable annoying requests warnings
23
22
requests .packages .urllib3 .disable_warnings ()
24
23
ARTWORK_QUEUE = Queue ()
25
24
IMAGE_CACHING_SUSPENDS = ['SUSPEND_LIBRARY_THREAD' , 'DB_SCAN' , 'STOP_SYNC' ]
26
- if not settings ('imageSyncDuringPlayback' ) == 'true' :
25
+ if not utils . settings ('imageSyncDuringPlayback' ) == 'true' :
27
26
IMAGE_CACHING_SUSPENDS .append ('SUSPEND_SYNC' )
28
27
29
28
###############################################################################
@@ -37,7 +36,7 @@ def double_urldecode(text):
37
36
return unquote (unquote (text ))
38
37
39
38
40
- @thread_methods (add_suspends = IMAGE_CACHING_SUSPENDS )
39
+ @utils . thread_methods (add_suspends = IMAGE_CACHING_SUSPENDS )
41
40
class Image_Cache_Thread (Thread ):
42
41
sleep_between = 50
43
42
# Potentially issues with limited number of threads
@@ -73,20 +72,20 @@ def run(self):
73
72
'Window.IsVisible(DialogAddonSettings.xml)' ):
74
73
# Avoid saving '0' all the time
75
74
set_zero = True
76
- settings ('caching_artwork_count' , value = '0' )
75
+ utils . settings ('caching_artwork_count' , value = '0' )
77
76
xbmc .sleep (1000 )
78
77
continue
79
78
set_zero = False
80
79
if isinstance (url , ArtworkSyncMessage ):
81
80
if state .IMAGE_SYNC_NOTIFICATIONS :
82
- dialog ('notification' ,
83
- heading = lang (29999 ),
84
- message = url .message ,
85
- icon = '{plex}' ,
86
- sound = False )
81
+ utils . dialog ('notification' ,
82
+ heading = utils . lang (29999 ),
83
+ message = url .message ,
84
+ icon = '{plex}' ,
85
+ sound = False )
87
86
queue .task_done ()
88
87
continue
89
- url = double_urlencode (try_encode (url ))
88
+ url = double_urlencode (utils . try_encode (url ))
90
89
sleeptime = 0
91
90
while True :
92
91
try :
@@ -133,14 +132,15 @@ def run(self):
133
132
if (counter > 20 and not xbmc .getCondVisibility (
134
133
'Window.IsVisible(DialogAddonSettings.xml)' )):
135
134
counter = 0
136
- settings ('caching_artwork_count' , value = str (queue .qsize ()))
135
+ utils .settings ('caching_artwork_count' ,
136
+ value = str (queue .qsize ()))
137
137
# Sleep for a bit to reduce CPU strain
138
138
xbmc .sleep (sleep_between )
139
139
LOG .info ("---===### Stopped Image_Cache_Thread ###===---" )
140
140
141
141
142
142
class Artwork ():
143
- enableTextureCache = settings ('enableTextureCache' ) == "true"
143
+ enableTextureCache = utils . settings ('enableTextureCache' ) == "true"
144
144
if enableTextureCache :
145
145
queue = ARTWORK_QUEUE
146
146
@@ -156,15 +156,15 @@ def cache_major_artwork(self):
156
156
artworks = list ()
157
157
# Get all posters and fanart/background for video and music
158
158
for kind in ('video' , 'music' ):
159
- connection = kodi_sql (kind )
159
+ connection = utils . kodi_sql (kind )
160
160
cursor = connection .cursor ()
161
161
for typus in ('poster' , 'fanart' ):
162
162
cursor .execute ('SELECT url FROM art WHERE type == ?' ,
163
163
(typus , ))
164
164
artworks .extend (cursor .fetchall ())
165
165
connection .close ()
166
166
artworks_to_cache = list ()
167
- connection = kodi_sql ('texture' )
167
+ connection = utils . kodi_sql ('texture' )
168
168
cursor = connection .cursor ()
169
169
for url in artworks :
170
170
query = 'SELECT url FROM texture WHERE url == ? LIMIT 1'
@@ -175,40 +175,41 @@ def cache_major_artwork(self):
175
175
if not artworks_to_cache :
176
176
LOG .info ('Caching of major images to Kodi texture cache done' )
177
177
# Set to "None"
178
- settings ('caching_artwork_count' , value = lang (30069 ))
178
+ utils . settings ('caching_artwork_count' , value = utils . lang (30069 ))
179
179
return
180
180
length = len (artworks_to_cache )
181
181
LOG .info ('Caching has not been completed - caching %s major images' ,
182
182
length )
183
- settings ('caching_artwork_count' , value = str (length ))
183
+ utils . settings ('caching_artwork_count' , value = str (length ))
184
184
# Caching %s Plex images
185
- self .queue .put (ArtworkSyncMessage (lang (30006 ) % length ))
185
+ self .queue .put (ArtworkSyncMessage (utils . lang (30006 ) % length ))
186
186
for i , url in enumerate (artworks_to_cache ):
187
187
self .queue .put (url [0 ])
188
188
# Plex image caching done
189
- self .queue .put (ArtworkSyncMessage (lang (30007 )))
189
+ self .queue .put (ArtworkSyncMessage (utils . lang (30007 )))
190
190
191
191
def fullTextureCacheSync (self ):
192
192
"""
193
193
This method will sync all Kodi artwork to textures13.db
194
194
and cache them locally. This takes diskspace!
195
195
"""
196
- if not dialog ('yesno' , "Image Texture Cache" , lang (39250 )):
196
+ if not utils . dialog ('yesno' , "Image Texture Cache" , utils . lang (39250 )):
197
197
return
198
198
199
199
LOG .info ("Doing Image Cache Sync" )
200
200
201
201
# ask to rest all existing or not
202
- if dialog ('yesno' , "Image Texture Cache" , lang (39251 )):
202
+ if utils . dialog ('yesno' , "Image Texture Cache" , utils . lang (39251 )):
203
203
LOG .info ("Resetting all cache data first" )
204
204
# Remove all existing textures first
205
- path = try_decode (xbmc .translatePath ("special://thumbnails/" ))
206
- if exists_dir (path ):
205
+ path = utils .try_decode (
206
+ xbmc .translatePath ("special://thumbnails/" ))
207
+ if utils .exists_dir (path ):
207
208
rmtree (path , ignore_errors = True )
208
209
self .restore_cache_directories ()
209
210
210
211
# remove all existing data from texture DB
211
- connection = kodi_sql ('texture' )
212
+ connection = utils . kodi_sql ('texture' )
212
213
cursor = connection .cursor ()
213
214
query = 'SELECT tbl_name FROM sqlite_master WHERE type=?'
214
215
cursor .execute (query , ('table' , ))
@@ -221,7 +222,7 @@ def fullTextureCacheSync(self):
221
222
connection .close ()
222
223
223
224
# Cache all entries in video DB
224
- connection = kodi_sql ('video' )
225
+ connection = utils . kodi_sql ('video' )
225
226
cursor = connection .cursor ()
226
227
# dont include actors
227
228
query = "SELECT url FROM art WHERE media_type != ?"
@@ -234,7 +235,7 @@ def fullTextureCacheSync(self):
234
235
for url in result :
235
236
self .cache_texture (url [0 ])
236
237
# Cache all entries in music DB
237
- connection = kodi_sql ('music' )
238
+ connection = utils . kodi_sql ('music' )
238
239
cursor = connection .cursor ()
239
240
cursor .execute ("SELECT url FROM art" )
240
241
result = cursor .fetchall ()
@@ -309,7 +310,7 @@ def delete_cached_artwork(url):
309
310
"""
310
311
Deleted the cached artwork with path url (if it exists)
311
312
"""
312
- connection = kodi_sql ('texture' )
313
+ connection = utils . kodi_sql ('texture' )
313
314
cursor = connection .cursor ()
314
315
try :
315
316
cursor .execute ("SELECT cachedurl FROM texture WHERE url=? LIMIT 1" ,
@@ -323,7 +324,7 @@ def delete_cached_artwork(url):
323
324
path = xbmc .translatePath ("special://thumbnails/%s" % cachedurl )
324
325
LOG .debug ("Deleting cached thumbnail: %s" , path )
325
326
if exists (path ):
326
- rmtree (try_decode (path ), ignore_errors = True )
327
+ rmtree (utils . try_decode (path ), ignore_errors = True )
327
328
cursor .execute ("DELETE FROM texture WHERE url = ?" , (url ,))
328
329
connection .commit ()
329
330
finally :
@@ -336,8 +337,8 @@ def restore_cache_directories():
336
337
"a" , "b" , "c" , "d" , "e" , "f" ,
337
338
"Video" , "plex" )
338
339
for path in paths :
339
- makedirs (try_decode (xbmc . translatePath ( "special://thumbnails/%s"
340
- % path )))
340
+ makedirs (utils . try_decode (
341
+ xbmc . translatePath ( "special://thumbnails/%s" % path )))
341
342
342
343
343
344
class ArtworkSyncMessage (object ):
0 commit comments