Skip to content

Commit c440dc7

Browse files
committed
Switch to absolute imports
1 parent 657ba47 commit c440dc7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1734
-1695
lines changed

addon.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<requires>
44
<import addon="xbmc.python" version="2.1.0"/>
55
<import addon="script.module.requests" version="2.9.1" />
6-
<import addon="plugin.video.plexkodiconnect.movies" version="2.0.4" />
7-
<import addon="plugin.video.plexkodiconnect.tvshows" version="2.0.4" />
6+
<import addon="plugin.video.plexkodiconnect.movies" version="2.0.5" />
7+
<import addon="plugin.video.plexkodiconnect.tvshows" version="2.0.5" />
88
</requires>
99
<extension point="xbmc.python.pluginsource" library="default.py">
1010
<provides>video audio image</provides>

default.py

+26-54
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,19 @@
11
# -*- coding: utf-8 -*-
22

33
###############################################################################
4-
from __future__ import unicode_literals # nice to fix os.walk unicode
4+
from __future__ import absolute_import, division, unicode_literals
55
import logging
6-
from os import path as os_path
7-
from sys import path as sys_path, argv
6+
from sys import argv
87
from urlparse import parse_qsl
9-
10-
from xbmc import translatePath, sleep, executebuiltin
11-
from xbmcaddon import Addon
8+
from xbmc import sleep, executebuiltin
129
from xbmcgui import ListItem
1310
from xbmcplugin import setResolvedUrl
1411

15-
_addon = Addon(id='plugin.video.plexkodiconnect')
16-
try:
17-
_addon_path = _addon.getAddonInfo('path').decode('utf-8')
18-
except TypeError:
19-
_addon_path = _addon.getAddonInfo('path').decode()
20-
try:
21-
_base_resource = translatePath(os_path.join(
22-
_addon_path,
23-
'resources',
24-
'lib')).decode('utf-8')
25-
except TypeError:
26-
_base_resource = translatePath(os_path.join(
27-
_addon_path,
28-
'resources',
29-
'lib')).decode()
30-
sys_path.append(_base_resource)
12+
from resources.lib import entrypoint, utils, pickler, pkc_listitem, \
13+
variables as v, loghandler
3114

3215
###############################################################################
3316

34-
import entrypoint
35-
from utils import window, reset, passwords_xml, language as lang, dialog, \
36-
plex_command
37-
from pickler import unpickle_me, pickl_window
38-
from PKC_listitem import convert_PKC_to_listitem
39-
import variables as v
40-
41-
###############################################################################
42-
43-
import loghandler
44-
4517
loghandler.config()
4618
log = logging.getLogger('PLEX.default')
4719

@@ -104,7 +76,7 @@ def __init__(self):
10476
entrypoint.create_new_pms()
10577

10678
elif mode == 'reset':
107-
reset()
79+
utils.reset()
10880

10981
elif mode == 'togglePlexTV':
11082
entrypoint.toggle_plex_tv_sign_in()
@@ -113,41 +85,41 @@ def __init__(self):
11385
entrypoint.reset_authorization()
11486

11587
elif mode == 'passwords':
116-
passwords_xml()
88+
utils.passwords_xml()
11789

11890
elif mode == 'switchuser':
11991
entrypoint.switch_plex_user()
12092

12193
elif mode in ('manualsync', 'repair'):
122-
if window('plex_online') != 'true':
94+
if pickler.pickl_window('plex_online') != 'true':
12395
# Server is not online, do not run the sync
124-
dialog('ok', lang(29999), lang(39205))
96+
utils.dialog('ok', utils.lang(29999), utils.lang(39205))
12597
log.error('Not connected to a PMS.')
12698
else:
12799
if mode == 'repair':
128100
log.info('Requesting repair lib sync')
129-
plex_command('RUN_LIB_SCAN', 'repair')
101+
utils.plex_command('RUN_LIB_SCAN', 'repair')
130102
elif mode == 'manualsync':
131103
log.info('Requesting full library scan')
132-
plex_command('RUN_LIB_SCAN', 'full')
104+
utils.plex_command('RUN_LIB_SCAN', 'full')
133105

134106
elif mode == 'texturecache':
135107
log.info('Requesting texture caching of all textures')
136-
plex_command('RUN_LIB_SCAN', 'textures')
108+
utils.plex_command('RUN_LIB_SCAN', 'textures')
137109

138110
elif mode == 'chooseServer':
139111
entrypoint.choose_pms_server()
140112

141113
elif mode == 'refreshplaylist':
142114
log.info('Requesting playlist/nodes refresh')
143-
plex_command('RUN_LIB_SCAN', 'views')
115+
utils.plex_command('RUN_LIB_SCAN', 'views')
144116

145117
elif mode == 'deviceid':
146118
self.deviceid()
147119

148120
elif mode == 'fanart':
149121
log.info('User requested fanarttv refresh')
150-
plex_command('RUN_LIB_SCAN', 'fanart')
122+
utils.plex_command('RUN_LIB_SCAN', 'fanart')
151123

152124
elif '/extrafanart' in argv[0]:
153125
plexpath = argv[2][1:]
@@ -171,40 +143,40 @@ def play():
171143
"""
172144
request = '%s&handle=%s' % (argv[2], HANDLE)
173145
# Put the request into the 'queue'
174-
plex_command('PLAY', request)
146+
utils.plex_command('PLAY', request)
175147
if HANDLE == -1:
176148
# Handle -1 received, not waiting for main thread
177149
return
178150
# Wait for the result
179-
while not pickl_window('plex_result'):
151+
while not pickler.pickl_window('plex_result'):
180152
sleep(50)
181-
result = unpickle_me()
153+
result = pickler.unpickle_me()
182154
if result is None:
183155
log.error('Error encountered, aborting')
184-
dialog('notification',
185-
heading='{plex}',
186-
message=lang(30128),
187-
icon='{error}',
188-
time=3000)
156+
utils.dialog('notification',
157+
heading='{plex}',
158+
message=utils.lang(30128),
159+
icon='{error}',
160+
time=3000)
189161
setResolvedUrl(HANDLE, False, ListItem())
190162
elif result.listitem:
191-
listitem = convert_PKC_to_listitem(result.listitem)
163+
listitem = pkc_listitem.convert_pkc_to_listitem(result.listitem)
192164
setResolvedUrl(HANDLE, True, listitem)
193165

194166
@staticmethod
195167
def deviceid():
196-
deviceId_old = window('plex_client_Id')
168+
deviceId_old = pickler.pickl_window('plex_client_Id')
197169
from clientinfo import getDeviceId
198170
try:
199171
deviceId = getDeviceId(reset=True)
200172
except Exception as e:
201173
log.error('Failed to generate a new device Id: %s' % e)
202-
dialog('ok', lang(29999), lang(33032))
174+
utils.dialog('ok', utils.lang(29999), utils.lang(33032))
203175
else:
204176
log.info('Successfully removed old device ID: %s New deviceId:'
205177
'%s' % (deviceId_old, deviceId))
206178
# 'Kodi will now restart to apply the changes'
207-
dialog('ok', lang(29999), lang(33033))
179+
utils.dialog('ok', utils.lang(29999), utils.lang(33033))
208180
executebuiltin('RestartApp')
209181

210182

resources/lib/PKC_listitem.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from xbmcgui import ListItem
44

55

6-
def convert_PKC_to_listitem(PKC_listitem):
6+
def convert_pkc_to_listitem(pkc_listitem):
77
"""
8-
Insert a PKC_listitem and you will receive a valid XBMC listitem
8+
Insert a PKCListItem() and you will receive a valid XBMC listitem
99
"""
10-
data = PKC_listitem.data
10+
data = pkc_listitem.data
1111
listitem = ListItem(label=data.get('label'),
1212
label2=data.get('label2'),
1313
path=data.get('path'))
@@ -26,7 +26,7 @@ def convert_PKC_to_listitem(PKC_listitem):
2626
return listitem
2727

2828

29-
class PKC_ListItem(object):
29+
class PKCListItem(object):
3030
"""
3131
Imitates xbmcgui.ListItem and its functions. Pass along PKC_Listitem().data
3232
when pickling!

resources/lib/artwork.py

+33-32
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
import xbmc
1313
from xbmcvfs import exists
1414

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
1817

1918
###############################################################################
20-
LOG = getLogger("PLEX." + __name__)
19+
LOG = getLogger('PLEX.artwork')
2120

2221
# Disable annoying requests warnings
2322
requests.packages.urllib3.disable_warnings()
2423
ARTWORK_QUEUE = Queue()
2524
IMAGE_CACHING_SUSPENDS = ['SUSPEND_LIBRARY_THREAD', 'DB_SCAN', 'STOP_SYNC']
26-
if not settings('imageSyncDuringPlayback') == 'true':
25+
if not utils.settings('imageSyncDuringPlayback') == 'true':
2726
IMAGE_CACHING_SUSPENDS.append('SUSPEND_SYNC')
2827

2928
###############################################################################
@@ -37,7 +36,7 @@ def double_urldecode(text):
3736
return unquote(unquote(text))
3837

3938

40-
@thread_methods(add_suspends=IMAGE_CACHING_SUSPENDS)
39+
@utils.thread_methods(add_suspends=IMAGE_CACHING_SUSPENDS)
4140
class Image_Cache_Thread(Thread):
4241
sleep_between = 50
4342
# Potentially issues with limited number of threads
@@ -73,20 +72,20 @@ def run(self):
7372
'Window.IsVisible(DialogAddonSettings.xml)'):
7473
# Avoid saving '0' all the time
7574
set_zero = True
76-
settings('caching_artwork_count', value='0')
75+
utils.settings('caching_artwork_count', value='0')
7776
xbmc.sleep(1000)
7877
continue
7978
set_zero = False
8079
if isinstance(url, ArtworkSyncMessage):
8180
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)
8786
queue.task_done()
8887
continue
89-
url = double_urlencode(try_encode(url))
88+
url = double_urlencode(utils.try_encode(url))
9089
sleeptime = 0
9190
while True:
9291
try:
@@ -133,14 +132,15 @@ def run(self):
133132
if (counter > 20 and not xbmc.getCondVisibility(
134133
'Window.IsVisible(DialogAddonSettings.xml)')):
135134
counter = 0
136-
settings('caching_artwork_count', value=str(queue.qsize()))
135+
utils.settings('caching_artwork_count',
136+
value=str(queue.qsize()))
137137
# Sleep for a bit to reduce CPU strain
138138
xbmc.sleep(sleep_between)
139139
LOG.info("---===### Stopped Image_Cache_Thread ###===---")
140140

141141

142142
class Artwork():
143-
enableTextureCache = settings('enableTextureCache') == "true"
143+
enableTextureCache = utils.settings('enableTextureCache') == "true"
144144
if enableTextureCache:
145145
queue = ARTWORK_QUEUE
146146

@@ -156,15 +156,15 @@ def cache_major_artwork(self):
156156
artworks = list()
157157
# Get all posters and fanart/background for video and music
158158
for kind in ('video', 'music'):
159-
connection = kodi_sql(kind)
159+
connection = utils.kodi_sql(kind)
160160
cursor = connection.cursor()
161161
for typus in ('poster', 'fanart'):
162162
cursor.execute('SELECT url FROM art WHERE type == ?',
163163
(typus, ))
164164
artworks.extend(cursor.fetchall())
165165
connection.close()
166166
artworks_to_cache = list()
167-
connection = kodi_sql('texture')
167+
connection = utils.kodi_sql('texture')
168168
cursor = connection.cursor()
169169
for url in artworks:
170170
query = 'SELECT url FROM texture WHERE url == ? LIMIT 1'
@@ -175,40 +175,41 @@ def cache_major_artwork(self):
175175
if not artworks_to_cache:
176176
LOG.info('Caching of major images to Kodi texture cache done')
177177
# Set to "None"
178-
settings('caching_artwork_count', value=lang(30069))
178+
utils.settings('caching_artwork_count', value=utils.lang(30069))
179179
return
180180
length = len(artworks_to_cache)
181181
LOG.info('Caching has not been completed - caching %s major images',
182182
length)
183-
settings('caching_artwork_count', value=str(length))
183+
utils.settings('caching_artwork_count', value=str(length))
184184
# Caching %s Plex images
185-
self.queue.put(ArtworkSyncMessage(lang(30006) % length))
185+
self.queue.put(ArtworkSyncMessage(utils.lang(30006) % length))
186186
for i, url in enumerate(artworks_to_cache):
187187
self.queue.put(url[0])
188188
# Plex image caching done
189-
self.queue.put(ArtworkSyncMessage(lang(30007)))
189+
self.queue.put(ArtworkSyncMessage(utils.lang(30007)))
190190

191191
def fullTextureCacheSync(self):
192192
"""
193193
This method will sync all Kodi artwork to textures13.db
194194
and cache them locally. This takes diskspace!
195195
"""
196-
if not dialog('yesno', "Image Texture Cache", lang(39250)):
196+
if not utils.dialog('yesno', "Image Texture Cache", utils.lang(39250)):
197197
return
198198

199199
LOG.info("Doing Image Cache Sync")
200200

201201
# 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)):
203203
LOG.info("Resetting all cache data first")
204204
# 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):
207208
rmtree(path, ignore_errors=True)
208209
self.restore_cache_directories()
209210

210211
# remove all existing data from texture DB
211-
connection = kodi_sql('texture')
212+
connection = utils.kodi_sql('texture')
212213
cursor = connection.cursor()
213214
query = 'SELECT tbl_name FROM sqlite_master WHERE type=?'
214215
cursor.execute(query, ('table', ))
@@ -221,7 +222,7 @@ def fullTextureCacheSync(self):
221222
connection.close()
222223

223224
# Cache all entries in video DB
224-
connection = kodi_sql('video')
225+
connection = utils.kodi_sql('video')
225226
cursor = connection.cursor()
226227
# dont include actors
227228
query = "SELECT url FROM art WHERE media_type != ?"
@@ -234,7 +235,7 @@ def fullTextureCacheSync(self):
234235
for url in result:
235236
self.cache_texture(url[0])
236237
# Cache all entries in music DB
237-
connection = kodi_sql('music')
238+
connection = utils.kodi_sql('music')
238239
cursor = connection.cursor()
239240
cursor.execute("SELECT url FROM art")
240241
result = cursor.fetchall()
@@ -309,7 +310,7 @@ def delete_cached_artwork(url):
309310
"""
310311
Deleted the cached artwork with path url (if it exists)
311312
"""
312-
connection = kodi_sql('texture')
313+
connection = utils.kodi_sql('texture')
313314
cursor = connection.cursor()
314315
try:
315316
cursor.execute("SELECT cachedurl FROM texture WHERE url=? LIMIT 1",
@@ -323,7 +324,7 @@ def delete_cached_artwork(url):
323324
path = xbmc.translatePath("special://thumbnails/%s" % cachedurl)
324325
LOG.debug("Deleting cached thumbnail: %s", path)
325326
if exists(path):
326-
rmtree(try_decode(path), ignore_errors=True)
327+
rmtree(utils.try_decode(path), ignore_errors=True)
327328
cursor.execute("DELETE FROM texture WHERE url = ?", (url,))
328329
connection.commit()
329330
finally:
@@ -336,8 +337,8 @@ def restore_cache_directories():
336337
"a", "b", "c", "d", "e", "f",
337338
"Video", "plex")
338339
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)))
341342

342343

343344
class ArtworkSyncMessage(object):

0 commit comments

Comments
 (0)