Skip to content

Commit

Permalink
Encapsulate filebot string decodes in single spot
Browse files Browse the repository at this point in the history
  • Loading branch information
Laharah committed May 12, 2021
1 parent fc72645 commit eb6e384
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion filebottool/gtkui/rename_dialog_gtk3.py
Expand Up @@ -101,7 +101,7 @@ def __init__(self, dialog_settings, server_plugin_version):

if self.server_filebot_version:
self.builder.get_object("filebot_version").set_text(
self.server_filebot_version.decode("utf8")
self.server_filebot_version
)
else:

Expand Down
6 changes: 3 additions & 3 deletions filebottool/gtkui/user_messenger_gtk3.py
Expand Up @@ -41,7 +41,7 @@ def dialog_response_cb(dialog, response_id):
if not self.modal:
self.set_modal(True)
self.connect('response', dialog_response_cb)
self.show()
self.show_all()


class ResponseDialog(Gtk.Dialog):
Expand Down Expand Up @@ -84,7 +84,7 @@ def show_new_files(self, files):
files = [' => '.join(f) if isinstance(f, tuple) else f for f in files]
files = pprint.pformat(files)
text_view = Gtk.TextView()
text_view.get_buffer().set_text(files.decode('utf8'))
text_view.get_buffer().set_text(files)
text_view.set_editable(False)
text_view.set_cursor_visible(False)
text_view.show()
Expand Down Expand Up @@ -172,7 +172,7 @@ def _show_details(_):
def display_text(self, title, text, parent=None, modal=False):
dialog = InfoDialog(title, None, parent, modal)
text_view = Gtk.TextView()
text_view.get_buffer().set_text(text.decode('utf8'))
text_view.get_buffer().set_text(text)
text_view.set_editable(False)
text_view.set_cursor_visible(False)
sw = Gtk.ScrolledWindow()
Expand Down
30 changes: 12 additions & 18 deletions filebottool/pyfilebot.py
Expand Up @@ -201,7 +201,7 @@ def rename(
exit_code, data, filebot_error = _execute(filebot_arguments, workaround)

if exit_code != 0:
if u"License Error: UNREGISTERED" in filebot_error.decode("utf8", "ignore"):
if u"License Error: UNREGISTERED" in filebot_error:
raise FilebotLicenseError(
"Filebot is unregistered, cannot rename.\n"
"FILEBOT OUTPUT DUMP:\n{0}".format(data)
Expand All @@ -221,7 +221,7 @@ def rename(
if parse_error or (rename_action == "test" and results[0] == 0):
raise FilebotRuntimeError(
"FILEBOT OUTPUT DUMP:\n{0}\nstderr:\n{1}".format(
data.decode("utf8"), filebot_error
data, filebot_error
)
)
return results
Expand All @@ -241,13 +241,6 @@ def parse_filebot(data):
a tuple in format (num processed files, list of movement tuples,
skipped/failed files)
"""
try:
data = data.decode("utf8")
except UnicodeDecodeError:
warnings.warn(
"DECODING ERROR WARNING: UNVALID UNICODE DETECTED!", UnicodeWarning
)
data = data.decode("utf8", errors="ignore")
data = data.splitlines()

skipped_files = []
Expand Down Expand Up @@ -377,13 +370,6 @@ def get_history(targets):

def parse_history(data):
""" Helper function to parse history script return values """
try:
data = data.decode("utf8")
except UnicodeDecodeError:
warnings.warn(
"DECODING ERROR WARNING: UNVALID UNICODE DETECTED!", UnicodeWarning
)
data = data.decode("utf8", errors="ignore")
data = data.splitlines()[:-1]
return [
tuple(reversed(l.split("\t")))
Expand Down Expand Up @@ -431,7 +417,7 @@ def license(license_path):
if exit_code != 0 or error:
raise FilebotLicenseError(error)

return data.decode("utf8", "ignore")
return data


def _order_is_valid(order_string):
Expand All @@ -441,7 +427,7 @@ def _order_is_valid(order_string):
Args:
order_string: valid orders:(None | 'airdate' | 'dvd' | 'absolute')
.decode('utf8')
Returns:
True or False based on success
"""
Expand Down Expand Up @@ -729,6 +715,14 @@ def _execute(process_arguments, workaround=False):
data = stdout

os.remove(file_temp.name)
try:
data = data.decode('utf8', errors="ignore")
except AttributeError:
pass
try:
error = error.decode('utf8', errors="ignore")
except AttributeError:
pass

return exit_code, data, error

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -42,7 +42,7 @@
__plugin_name__ = "FileBotTool"
__author__ = "laharah"
__author_email__ = "laharah+fbt@gmail.com"
__version__ = "2.0.0"
__version__ = "2.0.1"
__url__ = "https://github.com/Laharah/deluge-FileBotTool"
__license__ = "GPLv3"
__description__ = "Integrates FileBot functionality to Deluge"
Expand Down

0 comments on commit eb6e384

Please sign in to comment.