From be4c76fafcc46a8f25c73ed2aac39d277639d70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Fri, 24 Nov 2017 21:45:57 -0500 Subject: [PATCH] Path replacement improvement --- bazarr.py | 2 +- get_general_settings.py | 40 ++++++++++++++++++---------------------- list_subtitles.py | 4 ++-- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/bazarr.py b/bazarr.py index 0ff570c50..390b0ec80 100644 --- a/bazarr.py +++ b/bazarr.py @@ -1,7 +1,7 @@ # coding: utf-8 from __future__ import unicode_literals -bazarr_version = '0.1.3' +bazarr_version = '0.1.4' from bottle import route, run, template, static_file, request, redirect import bottle diff --git a/get_general_settings.py b/get_general_settings.py index cbe6d6aef..a517e63cb 100644 --- a/get_general_settings.py +++ b/get_general_settings.py @@ -30,27 +30,23 @@ branch = general_settings[5] automatic = general_settings[6] def path_replace(path): - for path_mapping in path_mappings: - path = path.replace(path_mapping[0], path_mapping[1], 1) - - if '\\' in path: - path = path.replace('/', '\\') - - return path + for path_mapping in path_mappings: + if path_mapping[0] in path: + path = path.replace(path_mapping[0], path_mapping[1]) + if path.startswith('\\\\'): + path = path.replace('/', '\\') + elif path.startswith('/'): + path = path.replace('\\', '/') + break + return path def path_replace_reverse(path): - for path_mapping in path_mappings: - if path.startswith('\\\\\\\\'): - if '\\\\' in path: - path = path.replace('\\\\', '\\') - elif '\\' in path: - path = path.replace('\\\\', '\\') - - path = path.replace(path_mapping[1], path_mapping[0], 1) - elif path.startswith('\\\\'): - path = path.replace(path_mapping[1], path_mapping[0], 1) - - if '\\' in path: - path = path.replace('\\', '/') - - return path + for path_mapping in path_mappings: + if path_mapping[1] in path: + path = path.replace(path_mapping[1], path_mapping[0]) + if path.startswith('\\\\'): + path = path.replace('/', '\\') + elif path.startswith('/'): + path = path.replace('\\', '/') + break + return path diff --git a/list_subtitles.py b/list_subtitles.py index e5c20d2d0..1535137f4 100644 --- a/list_subtitles.py +++ b/list_subtitles.py @@ -109,7 +109,7 @@ def full_scan_subtitles(): c_db.close() for episode in episodes: - store_subtitles(path_replace(episode[0].encode('utf-8'))) + store_subtitles(path_replace(episode[0])) def series_scan_subtitles(no): conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) @@ -129,4 +129,4 @@ def new_scan_subtitles(): c_db.close() for episode in episodes: - store_subtitles(path_replace(episode[0].encode('utf-8'))) + store_subtitles(path_replace(episode[0]))