Skip to content

Commit adea1b2

Browse files
committed
cleanup
1 parent 93d31c6 commit adea1b2

File tree

6 files changed

+49
-58
lines changed

6 files changed

+49
-58
lines changed

plugin/process.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _process_path(self, subfile, current_encoding=None):
103103
size = getFileSize(subfile)
104104
if size and size > SUBTITLES_FILE_MAX_SIZE:
105105
self.log.error("<%s> not supported subtitles size ({%d}KB > {%d}KB)!", filename, size // 1024, SUBTITLES_FILE_MAX_SIZE // 1024)
106-
raise LoadError('"%s" - not supported subtitles size: "%dKB"' % (toString(os.path.basename(subfile)), size // 1024))
106+
raise LoadError('"%s" - not supported subtitles size: "%dKB"' % (os.path.basename(subfile), size // 1024))
107107
try:
108108
text = load(subfile)
109109
except (URLError, HTTPError, IOError) as e:

plugin/seek.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ class SubsSeeker(object):
9999

100100
def __init__(self, download_path, tmp_path, captcha_cb, delay_cb, message_cb, settings=None, settings_provider_cls=None, settings_provider_args=None, debug=False, providers=None):
101101
self.log = SimpleLogger(self.__class__.__name__, log_level=debug and SimpleLogger.LOG_DEBUG or SimpleLogger.LOG_INFO)
102-
self.download_path = toString(download_path)
103-
self.tmp_path = toString(tmp_path)
102+
self.download_path = download_path
103+
self.tmp_path = tmp_path
104104
self.seekers = []
105105
providers = providers or SUBTITLES_SEEKERS
106106
for seeker in providers:
@@ -138,7 +138,7 @@ def getSubtitlesSimple(self, updateCB=None, title=None, filepath=None, langs=Non
138138

139139
def getSubtitles(self, providers, updateCB=None, title=None, filepath=None, langs=None, year=None, tvshow=None, season=None, episode=None, timeout=10):
140140
self.log.info('getting subtitles list - title: %s, filepath: %s, year: %s, tvshow: %s, season: %s, episode: %s' % (
141-
toString(title), toString(filepath), toString(year), toString(tvshow), toString(season), toString(episode)))
141+
title, filepath, year, tvshow, season, episode))
142142
subtitlesDict = {}
143143
threads = []
144144
socket.setdefaulttimeout(timeout)
@@ -215,7 +215,7 @@ def sortLangs(x):
215215
return subtitles_list
216216

217217
def downloadSubtitle(self, selected_subtitle, subtitles_dict, choosefile_cb, path=None, fname=None, overwrite_cb=None, settings=None):
218-
self.log.info('downloading subtitle "%s" with settings "%s"' % (selected_subtitle['filename'], toString(settings) or {}))
218+
self.log.info('downloading subtitle "%s" with settings "%s"' % (selected_subtitle['filename'], settings or {}))
219219
if settings is None:
220220
settings = {}
221221
seeker = None
@@ -231,7 +231,7 @@ def downloadSubtitle(self, selected_subtitle, subtitles_dict, choosefile_cb, pat
231231
subfiles = self._unpack_subtitles(filepath, self.tmp_path)
232232
else:
233233
subfiles = [filepath]
234-
subfiles = [toString(s) for s in subfiles]
234+
subfiles = [s for s in subfiles]
235235
if len(subfiles) == 0:
236236
self.log.error("no subtitles were downloaded!")
237237
raise SubtitlesDownloadError(msg="[error] no subtitles were downloaded")
@@ -247,38 +247,38 @@ def downloadSubtitle(self, selected_subtitle, subtitles_dict, choosefile_cb, pat
247247
self.log.debug('selected subtitle: "%s"', subfile)
248248
ext = os.path.splitext(subfile)[1]
249249
if ext not in self.SUBTILES_EXTENSIONS:
250-
ext = os.path.splitext(toString(selected_subtitle['filename']))[1]
250+
ext = os.path.splitext(selected_subtitle['filename'])[1]
251251
if ext not in self.SUBTILES_EXTENSIONS:
252252
ext = '.srt'
253253
if fname is None:
254254
filename = os.path.basename(subfile)
255255
save_as = settings.get('save_as', 'default')
256256
if save_as == 'version':
257257
self.log.debug('filename creating by "version" setting')
258-
filename = toString(selected_subtitle['filename'])
258+
filename = selected_subtitle['filename']
259259
# Sanitize the filename to remove slashes and double dots
260260
filename = sub(r'[\\/]', '_', filename) # Replace slashes with underscores
261261
filename = sub(r'\.\.', '.', filename) # Replace double dots with a single dot
262262
if os.path.splitext(filename)[1] not in self.SUBTILES_EXTENSIONS:
263263
filename = os.path.splitext(filename)[0] + ext
264264
elif save_as == 'video':
265265
self.log.debug('filename creating by "video" setting')
266-
videopath = toString(subtitles_dict[seeker.id]['params'].get('filepath'))
266+
videopath = subtitles_dict[seeker.id]['params'].get('filepath')
267267
filename = os.path.splitext(os.path.basename(videopath))[0] + ext
268268

269269
if settings.get('lang_to_filename', False):
270-
lang_iso639_1_2 = toString(languageTranslate(lang, 0, 2))
270+
lang_iso639_1_2 = languageTranslate(lang, 0, 2)
271271
self.log.debug('appending language "%s" to filename', lang_iso639_1_2)
272272
filename, ext = os.path.splitext(filename)
273273
filename = "%s.%s%s" % (filename, lang_iso639_1_2, ext)
274274
else:
275275
self.log.debug('using provided filename')
276-
filename = toString(fname) + ext
276+
filename = fname + ext
277277
self.log.debug('filename: "%s"', filename)
278-
download_path = os.path.join(toString(self.download_path), filename)
278+
download_path = os.path.join(self.download_path, filename)
279279
if path is not None:
280280
self.log.debug('using custom download path: "%s"', path)
281-
download_path = os.path.join(toString(path), filename)
281+
download_path = os.path.join(path, filename)
282282
self.log.debug('download path: "%s"', download_path)
283283

284284
# Ensure the destination directory exists

plugin/seekers/seeker.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def download(self, subtitles, selected_subtitle, path=None):
176176
177177
raises SubtitlesDownloadError
178178
"""
179-
self.log.info("download - selected_subtitle: %s, path: %s" % (toString(selected_subtitle['filename']), toString(path)))
179+
self.log.info("download - selected_subtitle: %s, path: %s" % (selected_subtitle['filename'], path))
180180
try:
181-
compressed, lang, filepath = self._download(subtitles, selected_subtitle, toString(path))
181+
compressed, lang, filepath = self._download(subtitles, selected_subtitle, path)
182182
except SubtitlesDownloadError as e:
183183
self.log.error("download error occured: %s" % str(e))
184184
e.provider = self.id
@@ -192,7 +192,7 @@ def download(self, subtitles, selected_subtitle, path=None):
192192
err.wrapped_error = exc_value
193193
raise err
194194

195-
self.log.info("download finished, compressed: %s, lang: %s, filepath:%s" % (toString(compressed), toString(lang), toString(filepath)))
195+
self.log.info("download finished, compressed: %s, lang: %s, filepath:%s" % (compressed, lang, filepath))
196196
return compressed, lang, filepath
197197

198198
def _download(self, subtitles, selected_subtitle, path):

plugin/seekers/utilities.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -443,37 +443,33 @@ def set_log_level(self, level):
443443
def error(self, text, *args):
444444
if self.log_level >= self.LOG_ERROR:
445445
text = self._eval_message(text, args)
446-
text = "[error] {0}".format(toString(text))
446+
text = "[error] {0}".format(text)
447447
out = self._format_output(text)
448448
self._out_fnc(out)
449449

450450
def info(self, text, *args):
451451
if self.log_level >= self.LOG_INFO:
452452
text = self._eval_message(text, args)
453-
text = "[info] {0}".format(toString(text))
453+
text = "[info] {0}".format(text)
454454
out = self._format_output(text)
455455
self._out_fnc(out)
456456

457457
def debug(self, text, *args):
458458
if self.log_level == self.LOG_DEBUG:
459459
text = self._eval_message(text, args)
460-
text = "[debug] {0}".format(toString(text))
460+
text = "[debug] {0}".format(text)
461461
out = self._format_output(text)
462462
self._out_fnc(out)
463463

464464
def _eval_message(self, text, *args):
465465
if len(args) == 1 and isinstance(args[0], tuple):
466-
text = text % toString(args[0])
466+
text = text % args[0]
467467
elif len(args) >= 1:
468-
text = text % tuple([toString(a) for a in args])
468+
text = text % tuple([a for a in args])
469469
return text
470470

471471
def _format_output(self, text):
472472
return self.LOG_FORMAT.format(self.prefix_name, text)
473473

474474
def _out_fnc(self, text):
475475
print(text)
476-
477-
478-
def toString(text):
479-
return text

plugin/subtitles.py

+23-24
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,9 @@ def __init__(self, session=None, subsPath=None, defaultPath=None, forceDefaultPa
769769

770770
self.onClose.append(self.exitSubs)
771771

772-
if defaultPath is not None and os.path.isdir(toString(defaultPath)):
773-
self.__defaultPath = toString(defaultPath)
774-
self.__subsDir = toString(defaultPath)
772+
if defaultPath is not None and os.path.isdir(defaultPath):
773+
self.__defaultPath = defaultPath
774+
self.__subsDir = defaultPath
775775

776776
if subsPath is not None and self.__autoLoad:
777777
self.loadSubs(subsPath)
@@ -791,7 +791,6 @@ def loadSubs(self, subsPath, newService=True):
791791
self.__subsDir = None
792792

793793
if subsPath is not None:
794-
subsPath = toString(subsPath)
795794
if not subsPath.startswith('http'):
796795
if self.__defaultPath is not None and self.__forceDefaultPath:
797796
self.__subsDir = self.__defaultPath
@@ -1458,7 +1457,7 @@ def setSubtitle(self, sub):
14581457
if color == "default":
14591458
color = self.font[sub['style']]['color']
14601459
self.setColor(color)
1461-
self["subtitles"].setText(toString(sub['text']))
1460+
self["subtitles"].setText(sub['text'])
14621461
self.subShown = True
14631462

14641463
def hideSubtitle(self):
@@ -1910,7 +1909,7 @@ def initSubInfo(self):
19101909
self["subfile_label"].setText(_("Embedded Subtitles"))
19111910
self["subfile_label"].instance.setForegroundColor(parseColor("#ffff00"))
19121911
elif self.subfile is not None:
1913-
self["subfile_label"].setText(toString(os.path.split(self.subfile)[1]))
1912+
self["subfile_label"].setText(os.path.split(self.subfile)[1])
19141913
self["subfile_label"].instance.setForegroundColor(parseColor("#DAA520"))
19151914

19161915
if self.newSelection:
@@ -2244,9 +2243,9 @@ def buildMenu(self):
22442243
def FileEntryComponent(name, absolute=None, isDir=False):
22452244
res = [(absolute, isDir)]
22462245
if isFullHD():
2247-
res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 770, 30, 1, RT_HALIGN_LEFT, toString(name)))
2246+
res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 770, 30, 1, RT_HALIGN_LEFT, name))
22482247
else:
2249-
res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 570, 30, 0, RT_HALIGN_LEFT, toString(name)))
2248+
res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 570, 30, 0, RT_HALIGN_LEFT, name))
22502249
if isDir:
22512250
png = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "extensions/directory.png"))
22522251
else:
@@ -2579,7 +2578,7 @@ class InfoScreen(Screen):
25792578

25802579
def __init__(self, session, subtitle):
25812580
Screen.__init__(self, session)
2582-
self["path"] = StaticText(_(toString(subtitle['fpath'])))
2581+
self["path"] = StaticText(_(subtitle['fpath']))
25832582

25842583
skin = """
25852584
<screen position="center,center" size="700,520" zPosition="3" resolution="1280,720">
@@ -2662,14 +2661,14 @@ def updateSubsList(self):
26622661
imgDict = {'unk': loadPNG(os.path.join(os.path.dirname(__file__), 'img', 'countries', 'UNK.png'))}
26632662
subtitleListGUI = []
26642663
for sub in self.subtitles[:]:
2665-
fpath = toString(sub['fpath'])
2664+
fpath = sub['fpath']
26662665
if not os.path.isfile(fpath):
26672666
self.subtitles.remove(sub)
26682667
continue
26692668
if sub.get('country', 'unk') not in imgDict:
26702669
countryImgPath = os.path.join(os.path.dirname(__file__), 'img', 'countries', sub['country'] + '.png')
26712670
if os.path.isfile(countryImgPath):
2672-
imgDict[sub['country']] = loadPNG(toString(countryImgPath))
2671+
imgDict[sub['country']] = loadPNG(countryImgPath)
26732672
countryPng = imgDict[sub['country']]
26742673
else:
26752674
countryPng = imgDict['unk']
@@ -2679,7 +2678,7 @@ def updateSubsList(self):
26792678
color = 0xffffff
26802679
date = datetime.fromtimestamp(os.path.getctime(fpath)).strftime("%d-%m-%Y %H:%M")
26812680
name = os.path.splitext(os.path.basename(fpath))[0]
2682-
subtitleListGUI.append((countryPng, toString(name), toString(sub['provider']), date, color),)
2681+
subtitleListGUI.append((countryPng, name, sub['provider'], date, color),)
26832682
imgDict = None
26842683
self['subtitles'].list = subtitleListGUI
26852684

@@ -2719,14 +2718,14 @@ def removeEntryCB(doRemove=False):
27192718
subtitle = self.subtitles[self["subtitles"].index]
27202719
if self.historySettings.removeAction.value == 'file':
27212720
if self.historySettings.removeActionAsk.value:
2722-
message = _("Subtitle") + " '" + toString(subtitle['name']) + "' " + _("will be removed from file system")
2721+
message = _("Subtitle") + " '" + subtitle['name'] + "' " + _("will be removed from file system")
27232722
message += "\n\n" + _("Do you want to proceed?")
27242723
self.session.openWithCallback(removeEntryCB, MessageBox, message, type=MessageBox.TYPE_YESNO)
27252724
else:
27262725
removeEntryCB(True)
27272726
else:
27282727
if self.historySettings.removeActionAsk.value:
2729-
message = _("Subtitle") + " '" + toString(subtitle['name']) + "' " + _("will be removed from list")
2728+
message = _("Subtitle") + " '" + subtitle['name'] + "' " + _("will be removed from list")
27302729
message += "\n\n" + _("Do you want to proceed?")
27312730
self.session.openWithCallback(removeEntryCB, MessageBox, message, type=MessageBox.TYPE_YESNO)
27322731
else:
@@ -3115,7 +3114,7 @@ def __init__(self, session, title, configTextWithSuggestions, positionX, titleCo
31153114
Screen.__init__(self, session)
31163115
self.list = []
31173116
self["suggestionslist"] = List(self.list)
3118-
self["suggestionstitle"] = StaticText(toString(title))
3117+
self["suggestionstitle"] = StaticText(title)
31193118
self.configTextWithSuggestion = configTextWithSuggestions
31203119

31213120
def update(self, suggestions):
@@ -3126,7 +3125,7 @@ def update(self, suggestions):
31263125
suggestions.reverse()
31273126
self.list = []
31283127
for s in suggestions:
3129-
self.list.append((toString(s['name']),))
3128+
self.list.append((s['name'],))
31303129
self["suggestionslist"].setList(self.list)
31313130
self["suggestionslist"].setIndex(0)
31323131
print(suggestions)
@@ -3570,15 +3569,15 @@ def editFnameCB(callback=None):
35703569
self.buildMenu()
35713570
self.updateFName()
35723571
from Screens.VirtualKeyBoard import VirtualKeyBoard
3573-
self.session.openWithCallback(editFnameCB, VirtualKeyBoard, _("Edit Filename"), text=toString(self.fname.strip()))
3572+
self.session.openWithCallback(editFnameCB, VirtualKeyBoard, _("Edit Filename"), text=self.fname.strip())
35743573

35753574
def editDPath(self):
35763575
def editDPathCB(callback=None):
35773576
if callback is not None and len(callback):
35783577
self.dpath = callback
35793578
self.configSaveTo.value = "custom"
35803579
self["config"].invalidate(self.configSaveTo)
3581-
self.session.openWithCallback(editDPathCB, LocationBox, _("Edit download path"), currDir=toString(self.dpath.strip()))
3580+
self.session.openWithCallback(editDPathCB, LocationBox, _("Edit download path"), currDir=self.dpath.strip())
35823581

35833582
def confirm(self):
35843583
if not self.fname.strip():
@@ -3670,7 +3669,7 @@ def left(self):
36703669
self["context_menu"].selectPrevious()
36713670

36723671
def updateGUI(self, subtitle, options):
3673-
self["subtitle_release"].text = toString(subtitle['filename'])
3672+
self["subtitle_release"].text = subtitle['filename']
36743673
self["context_menu"].list = [(o[0],) for o in options]
36753674
self.options = options
36763675

@@ -3933,8 +3932,8 @@ def updateSubsList(self): # TODO get country imgages from default skin
39333932
else:
39343933
countryPng = imgDict['unk']
39353934
syncPng = sync and imgDict['sync'] or None
3936-
subtitleListGUI.append((countryPng, _(toString(sub['language_name'])),
3937-
toString(sub['filename']), toString(sub['provider']), syncPng),)
3935+
subtitleListGUI.append((countryPng, _(sub['language_name']),
3936+
sub['filename'], sub['provider'], syncPng),)
39383937
imgDict = None
39393938
self['subtitles'].list = subtitleListGUI
39403939

@@ -4194,7 +4193,7 @@ def delayCB(seconds, resultCB):
41944193
SubsSearchProcess().start(params, callbacks)
41954194

41964195
def downloadSubsSuccess(self, subFile):
4197-
print('[SubsSearch] download success %s' % toString(subFile))
4196+
print('[SubsSearch] download success %s' % subFile)
41984197
dsubtitle = {
41994198
"name": toUnicode(os.path.basename(subFile)),
42004199
"country": toUnicode(self.__downloadingSubtitle['country']),
@@ -4509,7 +4508,7 @@ def updateProvidersList(self):
45094508
else:
45104509
providerState = _("disabled")
45114510
providerStateColor = 0xffff00
4512-
providerListGUI.append((toString(providerName), providerLangs, providerState, providerStateColor))
4511+
providerListGUI.append((providerName, providerLangs, providerState, providerStateColor))
45134512
self['providers'].list = providerListGUI
45144513

45154514
def setConfigFocus(self):
@@ -4938,7 +4937,7 @@ def removeSuggestionWindows(self):
49384937

49394938
class SubsSearchProviderMenu(BaseMenuScreen):
49404939
def __init__(self, session, provider):
4941-
title = toString(provider.provider_name) + " " + _("settings")
4940+
title = provider.provider_name + " " + _("settings")
49424941
BaseMenuScreen.__init__(self, session, title)
49434942
self.provider = provider
49444943

plugin/utils.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ def load(subpath):
2424
return ""
2525

2626

27-
def toString(text):
28-
return text
29-
30-
3127
def toUnicode(text):
3228
if isinstance(text, bytes):
3329
text = text.decode("UTF-8", errors='ignore')
@@ -106,29 +102,29 @@ def set_log_level(self, level):
106102
def error(self, text, *args):
107103
if self.log_level >= self.LOG_ERROR:
108104
text = self._eval_message(text, args)
109-
text = "[error] {0}".format(toString(text))
105+
text = "[error] {0}".format(text)
110106
out = self._format_output(text)
111107
self._out_fnc(out)
112108

113109
def info(self, text, *args):
114110
if self.log_level >= self.LOG_INFO:
115111
text = self._eval_message(text, args)
116-
text = "[info] {0}".format(toString(text))
112+
text = "[info] {0}".format(text)
117113
out = self._format_output(text)
118114
self._out_fnc(out)
119115

120116
def debug(self, text, *args):
121117
if self.log_level == self.LOG_DEBUG:
122118
text = self._eval_message(text, args)
123-
text = "[debug] {0}".format(toString(text))
119+
text = "[debug] {0}".format(text)
124120
out = self._format_output(text)
125121
self._out_fnc(out)
126122

127123
def _eval_message(self, text, *args):
128124
if len(args) == 1 and isinstance(args[0], tuple):
129-
text = text % toString(args[0])
125+
text = text % args[0]
130126
elif len(args) >= 1:
131-
text = text % tuple([toString(a) for a in args])
127+
text = text % tuple([a for a in args])
132128
return text
133129

134130
def _format_output(self, text):

0 commit comments

Comments
 (0)