pull/997/head
Louis Vézina 4 years ago
parent 34711665bb
commit f908f0d04a

@ -18,7 +18,7 @@ from config import settings, base_url, save_settings
from init import *
import logging
from database import database
from helper import path_replace, path_replace_reverse, path_replace_movie, path_replace_reverse_movie
from helper import path_mappings
from get_languages import language_from_alpha3, language_from_alpha2, alpha2_from_alpha3, alpha2_from_language, \
alpha3_from_language, alpha3_from_alpha2
from get_subtitle import download_subtitle, series_download_subtitles, movies_download_subtitles, \
@ -278,7 +278,7 @@ class Series(Resource):
item.update({"alternateTitles": ast.literal_eval(item['alternateTitles'])})
# Provide mapped path
mapped_path = path_replace(item['path'])
mapped_path = path_mappings.path_replace(item['path'])
item.update({"mapped_path": mapped_path})
# Confirm if path exist
@ -429,7 +429,7 @@ class Episodes(Resource):
item.update({"missing_subtitles": []})
# Provide mapped path
mapped_path = path_replace(item['path'])
mapped_path = path_mappings.path_replace(item['path'])
item.update({"mapped_path": mapped_path})
# Confirm if path exist
@ -450,15 +450,15 @@ class EpisodesSubtitlesDelete(Resource):
sonarrEpisodeId = request.form.get('sonarrEpisodeId')
try:
os.remove(path_replace(subtitlesPath))
os.remove(path_mappings.path_replace(subtitlesPath))
result = language_from_alpha3(language) + " subtitles deleted from disk."
history_log(0, sonarrSeriesId, sonarrEpisodeId, result, language=alpha2_from_alpha3(language))
store_subtitles(path_replace_reverse(episodePath), episodePath)
store_subtitles(path_mappings.path_replace_reverse(episodePath), episodePath)
return result, 202
except OSError as e:
logging.exception('BAZARR cannot delete subtitles file: ' + subtitlesPath)
store_subtitles(path_replace_reverse(episodePath), episodePath)
store_subtitles(path_mappings.path_replace_reverse(episodePath), episodePath)
return '', 204
@ -719,7 +719,7 @@ class Movies(Resource):
item.update({"missing_subtitles": []})
# Provide mapped path
mapped_path = path_replace_movie(item['path'])
mapped_path = path_mappings.path_replace_movie(item['path'])
item.update({"mapped_path": mapped_path})
# Confirm if path exist
@ -808,15 +808,15 @@ class MovieSubtitlesDelete(Resource):
radarrId = request.form.get('radarrId')
try:
os.remove(path_replace_movie(subtitlesPath))
os.remove(path_mappings.path_replace_movie(subtitlesPath))
result = language_from_alpha3(language) + " subtitles deleted from disk."
history_log_movie(0, radarrId, result, language=alpha2_from_alpha3(language))
store_subtitles_movie(path_replace_reverse_movie(moviePath), moviePath)
store_subtitles_movie(path_mappings.path_replace_reverse_movie(moviePath), moviePath)
return result, 202
except OSError as e:
logging.exception('BAZARR cannot delete subtitles file: ' + subtitlesPath)
store_subtitles_movie(path_replace_reverse_movie(moviePath), moviePath)
store_subtitles_movie(path_mappings.path_replace_reverse_movie(moviePath), moviePath)
return '', 204
@ -1079,7 +1079,7 @@ class HistorySeries(Resource):
item['timestamp'] = pretty.date(int(item['timestamp']))
# Provide mapped path
mapped_path = path_replace(item['path'])
mapped_path = path_mappings.path_replace(item['path'])
item.update({"mapped_path": mapped_path})
# Confirm if path exist
@ -1159,7 +1159,7 @@ class HistoryMovies(Resource):
if item['video_path']:
# Provide mapped path
mapped_path = path_replace_movie(item['video_path'])
mapped_path = path_mappings.path_replace_movie(item['video_path'])
item.update({"mapped_path": mapped_path})
# Confirm if path exist
@ -1209,7 +1209,7 @@ class WantedSeries(Resource):
item.update({"missing_subtitles": []})
# Provide mapped path
mapped_path = path_replace(item['path'])
mapped_path = path_mappings.path_replace(item['path'])
item.update({"mapped_path": mapped_path})
# Confirm if path exist
@ -1251,7 +1251,7 @@ class WantedMovies(Resource):
item.update({"missing_subtitles": []})
# Provide mapped path
mapped_path = path_replace_movie(item['path'])
mapped_path = path_mappings.path_replace_movie(item['path'])
item.update({"mapped_path": mapped_path})
# Confirm if path exist

@ -166,6 +166,7 @@ def save_settings(settings_items):
configure_debug = False
configure_captcha = False
update_schedule = False
update_path_map = False
configure_proxy = False
for key, value in settings_items:
@ -206,6 +207,9 @@ def save_settings(settings_items):
'settings-general-auto_update', 'settings-general-upgrade_subs']:
update_schedule = True
if key in ['settings-general-path_mappings', 'settings-general-path_mappings_movie']:
update_path_map = True
if key in ['settings-proxy-type', 'settings-proxy-url', 'settings-proxy-port', 'settings-proxy-username',
'settings-proxy-password']:
configure_proxy = True
@ -228,6 +232,10 @@ def save_settings(settings_items):
from api import scheduler
scheduler.update_configurable_tasks()
if update_path_map:
from helper import path_mappings
path_mappings.update()
if configure_proxy:
configure_proxy_func()
@ -308,6 +316,7 @@ def configure_captcha_func():
else:
os.environ["ANTICAPTCHA_CLASS"] = ''
def configure_proxy_func():
if settings.proxy.type != 'None':
if settings.proxy.username != '' and settings.proxy.password != '':
@ -317,4 +326,4 @@ def configure_proxy_func():
proxy = settings.proxy.type + '://' + settings.proxy.url + ':' + settings.proxy.port
os.environ['HTTP_PROXY'] = str(proxy)
os.environ['HTTPS_PROXY'] = str(proxy)
os.environ['NO_PROXY'] = str(settings.proxy.exclude)
os.environ['NO_PROXY'] = str(settings.proxy.exclude)

@ -2,7 +2,7 @@ import os
from sqlite3worker import Sqlite3Worker
from get_args import args
from helper import path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie
from helper import path_mappings
def db_init():
@ -69,20 +69,20 @@ class SqliteDictPathMapper:
def path_replace(self, values_dict):
if type(values_dict) is list:
for item in values_dict:
item['path'] = path_replace(item['path'])
item['path'] = path_mappings.path_replace(item['path'])
elif type(values_dict) is dict:
values_dict['path'] = path_replace(values_dict['path'])
values_dict['path'] = path_mappings.path_replace(values_dict['path'])
else:
return path_replace(values_dict)
return path_mappings.path_replace(values_dict)
def path_replace_movie(self, values_dict):
if type(values_dict) is list:
for item in values_dict:
item['path'] = path_replace_movie(item['path'])
item['path'] = path_mappings.path_replace_movie(item['path'])
elif type(values_dict) is dict:
values_dict['path'] = path_replace_movie(values_dict['path'])
values_dict['path'] = path_mappings.path_replace_movie(values_dict['path'])
else:
return path_replace(values_dict)
return path_mappings.path_replace_movie(values_dict)
dict_mapper = SqliteDictPathMapper()

@ -4,7 +4,7 @@ import logging
from database import database, dict_converter
from config import settings, url_sonarr
from helper import path_replace
from helper import path_mappings
from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles
from get_subtitle import episode_download_subtitles
from event_handler import event_stream

@ -5,7 +5,7 @@ import requests
import logging
from config import settings, url_radarr
from helper import path_replace_movie
from helper import path_mappings
from utils import get_radarr_version
from list_subtitles import store_subtitles_movie, list_missing_subtitles_movies, movies_full_scan_subtitles
@ -226,11 +226,11 @@ def update_movies():
added_movie['monitored']])
else:
logging.debug('BAZARR unable to insert this movie into the database:',
path_replace_movie(added_movie['path']))
path_mappings.path_replace_movie(added_movie['path']))
# Store subtitles for added or modified movies
for i, altered_movie in enumerate(altered_movies, 1):
store_subtitles_movie(altered_movie[1], path_replace_movie(altered_movie[1]))
store_subtitles_movie(altered_movie[1], path_mappings.path_replace_movie(altered_movie[1]))
logging.debug('BAZARR All movies synced from Radarr into database.')

@ -8,7 +8,7 @@ from config import settings, url_sonarr
from list_subtitles import list_missing_subtitles
from database import database, dict_converter
from utils import get_sonarr_version
from helper import path_replace
from helper import path_mappings
from event_handler import event_stream
@ -143,7 +143,7 @@ def update_series():
list_missing_subtitles(no=added_series['sonarrSeriesId'])
else:
logging.debug('BAZARR unable to insert this series into the database:',
path_replace(added_series['path']))
path_mappings.path_replace(added_series['path']))
event_stream(type='series', action='insert', series=added_series['sonarrSeriesId'])

@ -21,8 +21,7 @@ from subliminal_patch.score import compute_score
from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2, language_from_alpha2, \
alpha2_from_language, alpha3_from_language
from config import settings
from helper import path_replace, path_replace_movie, path_replace_reverse, \
path_replace_reverse_movie, pp_replace, get_target_folder, force_unicode
from helper import path_mappings, pp_replace, get_target_folder, force_unicode
from list_subtitles import store_subtitles, list_missing_subtitles, store_subtitles_movie, list_missing_subtitles_movies
from utils import history_log, history_log_movie, get_binary
from notifier import send_notifications, send_notifications_movie
@ -241,9 +240,9 @@ def download_subtitle(path, language, audio_language, hi, forced, providers, pro
# fixme: support multiple languages at once
if media_type == 'series':
reversed_path = path_replace_reverse(path)
reversed_path = path_mappings.path_replace_reverse(path)
else:
reversed_path = path_replace_reverse_movie(path)
reversed_path = path_mappings.path_replace_reverse_movie(path)
track_event(category=downloaded_provider, action=action, label=downloaded_language)
@ -464,9 +463,9 @@ def manual_download_subtitle(path, language, audio_language, hi, forced, subtitl
"threshold value: " + pp_threshold + "%")
if media_type == 'series':
reversed_path = path_replace_reverse(path)
reversed_path = path_mappings.path_replace_reverse(path)
else:
reversed_path = path_replace_reverse_movie(path)
reversed_path = path_mappings.path_replace_reverse_movie(path)
track_event(category=downloaded_provider, action="manually_downloaded", label=downloaded_language)
@ -568,9 +567,9 @@ def manual_upload_subtitle(path, language, forced, title, scene_name, media_type
if media_type == 'series':
reversed_path = path_replace_reverse(path)
reversed_path = path_mappings.path_replace_reverse(path)
else:
reversed_path = path_replace_reverse_movie(path)
reversed_path = path_mappings.path_replace_reverse_movie(path)
return message, reversed_path
@ -603,7 +602,7 @@ def series_download_subtitles(no):
if providers_list:
for language in ast.literal_eval(episode['missing_subtitles']):
if language is not None:
result = download_subtitle(path_replace(episode['path']),
result = download_subtitle(path_mappings.path_replace(episode['path']),
str(alpha3_from_alpha2(language.split(':')[0])),
series_details['audio_language'],
series_details['hearing_impaired'],
@ -620,7 +619,7 @@ def series_download_subtitles(no):
language_code = result[2] + ":forced" if forced else result[2]
provider = result[3]
score = result[4]
store_subtitles(episode['path'], path_replace(episode['path']))
store_subtitles(episode['path'], path_mappings.path_replace(episode['path']))
history_log(1, no, episode['sonarrEpisodeId'], message, path, language_code, provider, score)
send_notifications(no, episode['sonarrEpisodeId'], message)
else:
@ -652,7 +651,7 @@ def episode_download_subtitles(no):
if providers_list:
for language in ast.literal_eval(episode['missing_subtitles']):
if language is not None:
result = download_subtitle(path_replace(episode['path']),
result = download_subtitle(path_mappings.path_replace(episode['path']),
str(alpha3_from_alpha2(language.split(':')[0])),
episode['audio_language'],
episode['hearing_impaired'],
@ -669,7 +668,7 @@ def episode_download_subtitles(no):
language_code = result[2] + ":forced" if forced else result[2]
provider = result[3]
score = result[4]
store_subtitles(episode['path'], path_replace(episode['path']))
store_subtitles(episode['path'], path_mappings.path_replace(episode['path']))
history_log(1, episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message, path, language_code, provider, score)
send_notifications(episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message)
else:
@ -701,7 +700,7 @@ def movies_download_subtitles(no):
for i, language in enumerate(ast.literal_eval(movie['missing_subtitles']), 1):
if providers_list:
if language is not None:
result = download_subtitle(path_replace_movie(movie['path']),
result = download_subtitle(path_mappings.path_replace_movie(movie['path']),
str(alpha3_from_alpha2(language.split(':')[0])),
movie['audio_language'],
movie['hearing_impaired'],
@ -718,7 +717,7 @@ def movies_download_subtitles(no):
language_code = result[2] + ":forced" if forced else result[2]
provider = result[3]
score = result[4]
store_subtitles_movie(movie['path'], path_replace_movie(movie['path']))
store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']))
history_log_movie(1, no, message, path, language_code, provider, score)
send_notifications_movie(no, message)
else:
@ -734,7 +733,7 @@ def wanted_download_subtitles(path, l, count_episodes):
"FROM table_episodes LEFT JOIN table_shows on "
"table_episodes.sonarrSeriesId = table_shows.sonarrSeriesId "
"WHERE table_episodes.path=? and table_episodes.missing_subtitles!='[]'",
(path_replace_reverse(path),))
(path_mappings.path_replace_reverse(path),))
providers_list = get_providers()
providers_auth = get_providers_auth()
@ -758,7 +757,7 @@ def wanted_download_subtitles(path, l, count_episodes):
for i in range(len(attempt)):
if attempt[i][0] == language:
if search_active(attempt[i][1]):
result = download_subtitle(path_replace(episode['path']),
result = download_subtitle(path_mappings.path_replace(episode['path']),
str(alpha3_from_alpha2(language.split(':')[0])),
episode['audio_language'],
episode['hearing_impaired'],
@ -775,7 +774,7 @@ def wanted_download_subtitles(path, l, count_episodes):
language_code = result[2] + ":forced" if forced else result[2]
provider = result[3]
score = result[4]
store_subtitles(episode['path'], path_replace(episode['path']))
store_subtitles(episode['path'], path_mappings.path_replace(episode['path']))
history_log(1, episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message, path, language_code, provider, score)
send_notifications(episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message)
else:
@ -786,7 +785,7 @@ def wanted_download_subtitles(path, l, count_episodes):
def wanted_download_subtitles_movie(path, l, count_movies):
movies_details = database.execute("SELECT path, missing_subtitles, radarrId, hearing_impaired, audio_language, sceneName, "
"failedAttempts, title, forced FROM table_movies WHERE path = ? "
"AND missing_subtitles != '[]'", (path_replace_reverse_movie(path),))
"AND missing_subtitles != '[]'", (path_mappings.path_replace_reverse_movie(path),))
providers_list = get_providers()
providers_auth = get_providers_auth()
@ -810,7 +809,7 @@ def wanted_download_subtitles_movie(path, l, count_movies):
for i in range(len(attempt)):
if attempt[i][0] == language:
if search_active(attempt[i][1]) is True:
result = download_subtitle(path_replace_movie(movie['path']),
result = download_subtitle(path_mappings.path_replace_movie(movie['path']),
str(alpha3_from_alpha2(language.split(':')[0])),
movie['audio_language'],
movie['hearing_impaired'],
@ -827,7 +826,7 @@ def wanted_download_subtitles_movie(path, l, count_movies):
language_code = result[2] + ":forced" if forced else result[2]
provider = result[3]
score = result[4]
store_subtitles_movie(movie['path'], path_replace_movie(movie['path']))
store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']))
history_log_movie(1, movie['radarrId'], message, path, language_code, provider, score)
send_notifications_movie(movie['radarrId'], message)
else:
@ -843,8 +842,8 @@ def wanted_search_missing_subtitles_series():
episodes = database.execute("SELECT path FROM table_episodes WHERE missing_subtitles != '[]'" +
monitored_only_query_string_sonarr)
# path_replace
dict_mapper.path_replace(episodes)
# path_mappings.path_replace
dict_mapper.path_mappings.path_replace(episodes)
count_episodes = len(episodes)
for i, episode in enumerate(episodes, 1):
@ -866,8 +865,8 @@ def wanted_search_missing_subtitles_movies():
movies = database.execute("SELECT path FROM table_movies WHERE missing_subtitles != '[]'" +
monitored_only_query_string_radarr)
# path_replace
dict_mapper.path_replace_movie(movies)
# path_mappings.path_replace
dict_mapper.path_mappings.path_replace_movie(movies)
count_movies = len(movies)
for i, movie in enumerate(movies, 1):
@ -908,7 +907,7 @@ def refine_from_db(path, video):
"table_episodes.video_codec, table_episodes.audio_codec, table_episodes.path "
"FROM table_episodes INNER JOIN table_shows on "
"table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId "
"WHERE table_episodes.path = ?", (path_replace_reverse(path),), only_one=True)
"WHERE table_episodes.path = ?", (path_mappings.path_replace_reverse(path),), only_one=True)
if data:
video.series = data['seriesTitle']
@ -930,7 +929,7 @@ def refine_from_db(path, video):
elif isinstance(video, Movie):
data = database.execute("SELECT title, year, alternativeTitles, format, resolution, video_codec, audio_codec, "
"imdbId FROM table_movies WHERE path = ?",
(path_replace_reverse_movie(path),), only_one=True)
(path_mappings.path_replace_reverse_movie(path),), only_one=True)
if data:
video.title = re.sub(r'(\(\d\d\d\d\))', '', data['title'])
@ -1036,7 +1035,7 @@ def upgrade_subtitles():
episodes_to_upgrade = []
for episode in upgradable_episodes_not_perfect:
if os.path.exists(path_replace(episode['video_path'])) and int(episode['score']) < 357:
if os.path.exists(path_mappings.path_replace(episode['video_path'])) and int(episode['score']) < 357:
episodes_to_upgrade.append(episode)
count_episode_to_upgrade = len(episodes_to_upgrade)
@ -1067,7 +1066,7 @@ def upgrade_subtitles():
movies_to_upgrade = []
for movie in upgradable_movies_not_perfect:
if os.path.exists(path_replace_movie(movie['video_path'])) and int(movie['score']) < 117:
if os.path.exists(path_mappings.path_replace_movie(movie['video_path'])) and int(movie['score']) < 117:
movies_to_upgrade.append(movie)
count_movie_to_upgrade = len(movies_to_upgrade)
@ -1100,7 +1099,7 @@ def upgrade_subtitles():
language = episode['language']
is_forced = "False"
result = download_subtitle(path_replace(episode['video_path']),
result = download_subtitle(path_mappings.path_replace(episode['video_path']),
str(alpha3_from_alpha2(language)),
episode['audio_language'],
episode['hearing_impaired'],
@ -1119,7 +1118,7 @@ def upgrade_subtitles():
language_code = result[2] + ":forced" if forced else result[2]
provider = result[3]
score = result[4]
store_subtitles(episode['video_path'], path_replace(episode['video_path']))
store_subtitles(episode['video_path'], path_mappings.path_replace(episode['video_path']))
history_log(3, episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message, path, language_code, provider, score)
send_notifications(episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message)
@ -1148,7 +1147,7 @@ def upgrade_subtitles():
language = movie['language']
is_forced = "False"
result = download_subtitle(path_replace_movie(movie['video_path']),
result = download_subtitle(path_mappings.path_replace_movie(movie['video_path']),
str(alpha3_from_alpha2(language)),
movie['audio_language'],
movie['hearing_impaired'],
@ -1167,7 +1166,7 @@ def upgrade_subtitles():
language_code = result[2] + ":forced" if forced else result[2]
provider = result[3]
score = result[4]
store_subtitles_movie(movie['video_path'], path_replace_movie(movie['video_path']))
store_subtitles_movie(movie['video_path'], path_mappings.path_replace_movie(movie['video_path']))
history_log_movie(3, movie['radarrId'], message, path, language_code, provider, score)
send_notifications_movie(movie['radarrId'], message)

@ -10,88 +10,89 @@ from bs4 import UnicodeDammit
from config import settings
def create_path_mapping_dict():
global path_mapping_series
path_mapping_series = ast.literal_eval(settings.general.path_mappings)
global path_mapping_movies
path_mapping_movies = ast.literal_eval(settings.general.path_mappings_movie)
def path_replace(path):
if path is None:
return None
for path_mapping in path_mapping_series:
if path_mapping[0] == path_mapping[1]:
continue
if '' in path_mapping:
continue
if path_mapping[0] in path:
path = path.replace(path_mapping[0], path_mapping[1])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
def path_replace_reverse(path):
if path is None:
return None
for path_mapping in path_mapping_series:
if path_mapping[0] == path_mapping[1]:
continue
if '' in path_mapping:
continue
if path_mapping[1] in path:
path = path.replace(path_mapping[1], path_mapping[0])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
def path_replace_movie(path):
if path is None:
return None
for path_mapping in path_mapping_movies:
if path_mapping[0] == path_mapping[1]:
continue
if '' in path_mapping:
continue
if path_mapping[0] in path:
path = path.replace(path_mapping[0], path_mapping[1])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
def path_replace_reverse_movie(path):
if path is None:
return None
for path_mapping in path_mapping_movies:
if path_mapping[0] == path_mapping[1]:
continue
if '' in path_mapping:
continue
if path_mapping[1] in path:
path = path.replace(path_mapping[1], path_mapping[0])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
class PathMappings:
def __init__(self):
self.path_mapping_series = []
self.path_mapping_movies = []
def update(self):
self.path_mapping_series = ast.literal_eval(settings.general.path_mappings)
self.path_mapping_movies = ast.literal_eval(settings.general.path_mappings_movie)
def path_replace(self, path):
if path is None:
return None
for path_mapping in self.path_mapping_series:
if path_mapping[0] == path_mapping[1]:
continue
if '' in path_mapping:
continue
if path_mapping[0] in path:
path = path.replace(path_mapping[0], path_mapping[1])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
def path_replace_reverse(self, path):
if path is None:
return None
for path_mapping in self.path_mapping_series:
if path_mapping[0] == path_mapping[1]:
continue
if '' in path_mapping:
continue
if path_mapping[1] in path:
path = path.replace(path_mapping[1], path_mapping[0])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
def path_replace_movie(self, path):
if path is None:
return None
for path_mapping in self.path_mapping_movies:
if path_mapping[0] == path_mapping[1]:
continue
if '' in path_mapping:
continue
if path_mapping[0] in path:
path = path.replace(path_mapping[0], path_mapping[1])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
def path_replace_reverse_movie(self, path):
if path is None:
return None
for path_mapping in self.path_mapping_movies:
if path_mapping[0] == path_mapping[1]:
continue
if '' in path_mapping:
continue
if path_mapping[1] in path:
path = path.replace(path_mapping[1], path_mapping[0])
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
break
return path
path_mappings = PathMappings()
def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3, episode_language, episode_language_code2, episode_language_code3, forced):

@ -8,7 +8,7 @@ import hashlib
from config import settings, configure_captcha_func
from get_args import args
from logger import configure_logging
from helper import create_path_mapping_dict
from helper import path_mappings
from dogpile.cache.region import register_backend as register_cache_backend
import subliminal
@ -132,4 +132,4 @@ def init_binaries():
init_binaries()
create_path_mapping_dict()
path_mappings.update()

@ -13,8 +13,7 @@ from subzero.language import Language
from database import database
from get_languages import alpha2_from_alpha3, get_language_set
from config import settings
from helper import path_replace, path_replace_movie, path_replace_reverse, \
path_replace_reverse_movie, get_subtitle_destination_folder
from helper import path_mappings, get_subtitle_destination_folder
from embedded_subs_reader import embedded_subs_reader
from event_handler import event_stream
@ -68,17 +67,17 @@ def store_subtitles(original_path, reversed_path):
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)):
logging.debug("BAZARR external subtitles detected: " + "pb")
actual_subtitles.append(
[str("pb"), path_replace_reverse(subtitle_path)])
[str("pb"), path_mappings.path_replace_reverse(subtitle_path)])
elif str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese_forced)):
logging.debug("BAZARR external subtitles detected: " + "pb:forced")
actual_subtitles.append(
[str("pb:forced"), path_replace_reverse(subtitle_path)])
[str("pb:forced"), path_mappings.path_replace_reverse(subtitle_path)])
elif not language:
continue
elif str(language) != 'und':
logging.debug("BAZARR external subtitles detected: " + str(language))
actual_subtitles.append(
[str(language), path_replace_reverse(subtitle_path)])
[str(language), path_mappings.path_replace_reverse(subtitle_path)])
database.execute("UPDATE table_episodes SET subtitles=? WHERE path=?",
(str(actual_subtitles), original_path))
@ -142,15 +141,15 @@ def store_subtitles_movie(original_path, reversed_path):
subtitle_path = get_external_subtitles_path(reversed_path, subtitle)
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)):
logging.debug("BAZARR external subtitles detected: " + "pb")
actual_subtitles.append([str("pb"), path_replace_reverse_movie(subtitle_path)])
actual_subtitles.append([str("pb"), path_mappings.path_replace_reverse_movie(subtitle_path)])
elif str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese_forced)):
logging.debug("BAZARR external subtitles detected: " + "pb:forced")
actual_subtitles.append([str("pb:forced"), path_replace_reverse_movie(subtitle_path)])
actual_subtitles.append([str("pb:forced"), path_mappings.path_replace_reverse_movie(subtitle_path)])
elif not language:
continue
elif str(language) != 'und':
logging.debug("BAZARR external subtitles detected: " + str(language))
actual_subtitles.append([str(language), path_replace_reverse_movie(subtitle_path)])
actual_subtitles.append([str(language), path_mappings.path_replace_reverse_movie(subtitle_path)])
database.execute("UPDATE table_movies SET subtitles=? WHERE path=?",
(str(actual_subtitles), original_path))
@ -301,7 +300,7 @@ def series_full_scan_subtitles():
episodes = database.execute("SELECT path FROM table_episodes")
for i, episode in enumerate(episodes, 1):
store_subtitles(episode['path'], path_replace(episode['path']))
store_subtitles(episode['path'], path_mappings.path_replace(episode['path']))
gc.collect()
@ -310,7 +309,7 @@ def movies_full_scan_subtitles():
movies = database.execute("SELECT path FROM table_movies")
for i, movie in enumerate(movies, 1):
store_subtitles_movie(movie['path'], path_replace_movie(movie['path']))
store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']))
gc.collect()
@ -320,14 +319,14 @@ def series_scan_subtitles(no):
(no,))
for episode in episodes:
store_subtitles(episode['path'], path_replace(episode['path']))
store_subtitles(episode['path'], path_mappings.path_replace(episode['path']))
def movies_scan_subtitles(no):
movies = database.execute("SELECT path FROM table_movies WHERE radarrId=? ORDER BY radarrId", (no,))
for movie in movies:
store_subtitles_movie(movie['path'], path_replace_movie(movie['path']))
store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']))
def get_external_subtitles_path(file, subtitle):

@ -369,18 +369,21 @@
$('#add_path_radarr').val('');
$('#add_path_bazarr').val('');
$('#addModal').modal('hide');
$('#settings_form').trigger('change');
});
$('#edit_save_button').on('click', function(e) {
e.preventDefault();
table.row( { selected: true } ).data([ $('#edit_path_radarr').val(), $('#edit_path_bazarr').val()]);
$('#editModal').modal('hide');
$('#settings_form').trigger('change');
});
$('#delete_yes_button').on('click', function(e) {
e.preventDefault();
table.row( { selected: true } ).remove().draw();
$('#deleteModal').modal('hide');
$('#settings_form').trigger('change');
});
$('#test_radarr_connection').on('click', function() {

@ -369,18 +369,21 @@
$('#add_path_sonarr').val('');
$('#add_path_bazarr').val('');
$('#addModal').modal('hide');
$('#settings_form').trigger('change');
});
$('#edit_save_button').on('click', function(e) {
e.preventDefault();
table.row( { selected: true } ).data([ $('#edit_path_sonarr').val(), $('#edit_path_bazarr').val()]);
$('#editModal').modal('hide');
$('#settings_form').trigger('change');
});
$('#delete_yes_button').on('click', function(e) {
e.preventDefault();
table.row( { selected: true } ).remove().draw();
$('#deleteModal').modal('hide');
$('#settings_form').trigger('change');
});
$('#test_sonarr_connection').on('click', function() {

Loading…
Cancel
Save