Commit 44977d45 authored by echel0n's avatar echel0n

Refactored code for getting subtitles path, strips leading slashes from

store custom subs path in settings to ensure proper path joining and
confirms custom subs path does exist if absolute.
parent d52005c6
......@@ -91,11 +91,7 @@ class Logger(logging.getLoggerClass()):
def start(self):
# remove all handlers
self.handlers = []
# sentry log handler
sentry_client = raven.Client('https://[email protected]/2?verify_ssl=0',
release=sickrage.version(), repos={'sickrage': {'name': 'sickrage/sickrage'}})
self.handlers.clear()
sentry_ignore_exceptions = [
'KeyboardInterrupt',
......@@ -103,6 +99,14 @@ class Logger(logging.getLoggerClass()):
'FileNotFoundError',
]
# sentry log handler
sentry_client = raven.Client(
'https://[email protected]/2?verify_ssl=0',
release=sickrage.version(),
repos={'sickrage': {'name': 'sickrage/sickrage'}},
ignore_exceptions=sentry_ignore_exceptions
)
sentry_tags = {
'platform': platform.platform(),
'locale': sys.getdefaultencoding(),
......
......@@ -23,6 +23,7 @@
import os
import re
import subprocess
from pathlib import Path
import subliminal
from babelfish import language_converters, Language
......@@ -209,8 +210,7 @@ class Subtitles(object):
# external subtitles
if subtitles:
video.subtitle_languages |= \
set(subliminal.core.search_external_subtitles(video_path, directory=subtitles_path).values())
video.subtitle_languages |= set(subliminal.core.search_external_subtitles(video_path, directory=subtitles_path).values())
if embedded_subtitles is None:
embedded_subtitles = bool(
......@@ -228,17 +228,17 @@ class Subtitles(object):
return video
def get_subtitles_path(self, video_path):
if os.path.isabs(sickrage.app.config.subtitles_dir):
if Path(sickrage.app.config.subtitles_dir).is_absolute() and Path(sickrage.app.config.subtitles_dir).exists():
new_subtitles_path = sickrage.app.config.subtitles_dir
elif sickrage.app.config.subtitles_dir:
new_subtitles_path = os.path.join(os.path.dirname(video_path), sickrage.app.config.subtitles_dir)
new_subtitles_path = Path(os.path.dirname(video_path)).joinpath(sickrage.app.config.subtitles_dir.strip('/'))
dir_exists = make_dir(new_subtitles_path)
if not dir_exists:
sickrage.app.log.warning('Unable to create subtitles folder {}'.format(new_subtitles_path))
else:
chmod_as_parent(new_subtitles_path)
else:
new_subtitles_path = os.path.dirname(video_path)
new_subtitles_path = Path(video_path).parent
return new_subtitles_path
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment