Path replacement improvement

pull/26/head
Louis Vézina 7 years ago
parent bbd509e98f
commit be4c76fafc

@ -1,7 +1,7 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals 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 from bottle import route, run, template, static_file, request, redirect
import bottle import bottle

@ -30,27 +30,23 @@ branch = general_settings[5]
automatic = general_settings[6] automatic = general_settings[6]
def path_replace(path): def path_replace(path):
for path_mapping in path_mappings: for path_mapping in path_mappings:
path = path.replace(path_mapping[0], path_mapping[1], 1) if path_mapping[0] in path:
path = path.replace(path_mapping[0], path_mapping[1])
if '\\' in path: if path.startswith('\\\\'):
path = path.replace('/', '\\') path = path.replace('/', '\\')
elif path.startswith('/'):
return path path = path.replace('\\', '/')
break
return path
def path_replace_reverse(path): def path_replace_reverse(path):
for path_mapping in path_mappings: for path_mapping in path_mappings:
if path.startswith('\\\\\\\\'): if path_mapping[1] in path:
if '\\\\' in path: path = path.replace(path_mapping[1], path_mapping[0])
path = path.replace('\\\\', '\\') if path.startswith('\\\\'):
elif '\\' in path: path = path.replace('/', '\\')
path = path.replace('\\\\', '\\') elif path.startswith('/'):
path = path.replace('\\', '/')
path = path.replace(path_mapping[1], path_mapping[0], 1) break
elif path.startswith('\\\\'): return path
path = path.replace(path_mapping[1], path_mapping[0], 1)
if '\\' in path:
path = path.replace('\\', '/')
return path

@ -109,7 +109,7 @@ def full_scan_subtitles():
c_db.close() c_db.close()
for episode in episodes: for episode in episodes:
store_subtitles(path_replace(episode[0].encode('utf-8'))) store_subtitles(path_replace(episode[0]))
def series_scan_subtitles(no): def series_scan_subtitles(no):
conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) 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() c_db.close()
for episode in episodes: for episode in episodes:
store_subtitles(path_replace(episode[0].encode('utf-8'))) store_subtitles(path_replace(episode[0]))

Loading…
Cancel
Save