|
|
|
@ -24,14 +24,14 @@ global hi_regex
|
|
|
|
|
hi_regex = re.compile(r'[*¶♫♪].{3,}[*¶♫♪]|[\[\(\{].{3,}[\]\)\}](?<!{\\an\d})')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def store_subtitles(original_path, reversed_path, record_type=None, record_id=None):
|
|
|
|
|
def store_subtitles(original_path, reversed_path):
|
|
|
|
|
logging.debug('BAZARR started subtitles indexing for this file: ' + reversed_path)
|
|
|
|
|
actual_subtitles = []
|
|
|
|
|
if os.path.exists(reversed_path):
|
|
|
|
|
if settings.general.getboolean('use_embedded_subs'):
|
|
|
|
|
logging.debug("BAZARR is trying to index embedded subtitles.")
|
|
|
|
|
try:
|
|
|
|
|
subtitle_languages = embedded_subs_reader.list_languages(reversed_path, original_path, record_type, record_id)
|
|
|
|
|
subtitle_languages = embedded_subs_reader.list_languages(reversed_path)
|
|
|
|
|
for subtitle_language, subtitle_forced, subtitle_hi, subtitle_codec in subtitle_languages:
|
|
|
|
|
try:
|
|
|
|
|
if (settings.general.getboolean("ignore_pgs_subs") and subtitle_codec.lower() == "pgs") or \
|
|
|
|
@ -59,10 +59,10 @@ def store_subtitles(original_path, reversed_path, record_type=None, record_id=No
|
|
|
|
|
brazilian_portuguese = [".pt-br", ".pob", "pb"]
|
|
|
|
|
brazilian_portuguese_forced = [".pt-br.forced", ".pob.forced", "pb.forced"]
|
|
|
|
|
simplified_chinese_fuzzy = [u"简", u"双语"]
|
|
|
|
|
simplified_chinese = [".chs", ".sc", ".zhs", ".zh-hans", ".hans", ".zh_hans", ".zhhans", ".gb", ".simplified"]
|
|
|
|
|
simplified_chinese = [".chs", ".sc", ".zhs",".zh-hans",".hans",".zh_hans",".zhhans",".gb",".simplified"]
|
|
|
|
|
simplified_chinese_forced = [".chs.forced", ".sc.forced", ".zhs.forced", "hans.forced", ".gb.forced", u"简体中文.forced", u"双语.forced"]
|
|
|
|
|
traditional_chinese_fuzzy = [u"繁", u"雙語"]
|
|
|
|
|
traditional_chinese = [".cht", ".tc", ".zh-tw", ".zht", ".zh-hant", ".zhhant", ".zh_hant", ".hant", ".big5", ".traditional"]
|
|
|
|
|
traditional_chinese = [".cht", ".tc", ".zh-tw", ".zht",".zh-hant",".zhhant",".zh_hant",".hant", ".big5", ".traditional"]
|
|
|
|
|
traditional_chinese_forced = [".cht.forced", ".tc.forced", ".zht.forced", "hant.forced", ".big5.forced", u"繁體中文.forced", u"雙語.forced", "zh-tw.forced"]
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -138,14 +138,14 @@ def store_subtitles(original_path, reversed_path, record_type=None, record_id=No
|
|
|
|
|
return actual_subtitles
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def store_subtitles_movie(original_path, reversed_path, record_type=None, record_id=None):
|
|
|
|
|
def store_subtitles_movie(original_path, reversed_path):
|
|
|
|
|
logging.debug('BAZARR started subtitles indexing for this file: ' + reversed_path)
|
|
|
|
|
actual_subtitles = []
|
|
|
|
|
if os.path.exists(reversed_path):
|
|
|
|
|
if settings.general.getboolean('use_embedded_subs'):
|
|
|
|
|
logging.debug("BAZARR is trying to index embedded subtitles.")
|
|
|
|
|
try:
|
|
|
|
|
subtitle_languages = embedded_subs_reader.list_languages(reversed_path, original_path, record_type, record_id)
|
|
|
|
|
subtitle_languages = embedded_subs_reader.list_languages(reversed_path)
|
|
|
|
|
for subtitle_language, subtitle_forced, subtitle_hi, subtitle_codec in subtitle_languages:
|
|
|
|
|
try:
|
|
|
|
|
if (settings.general.getboolean("ignore_pgs_subs") and subtitle_codec.lower() == "pgs") or \
|
|
|
|
@ -173,10 +173,10 @@ def store_subtitles_movie(original_path, reversed_path, record_type=None, record
|
|
|
|
|
brazilian_portuguese = [".pt-br", ".pob", "pb"]
|
|
|
|
|
brazilian_portuguese_forced = [".pt-br.forced", ".pob.forced", "pb.forced"]
|
|
|
|
|
simplified_chinese_fuzzy = [u"简", u"双语"]
|
|
|
|
|
simplified_chinese = [".chs", ".sc", ".zhs", ".zh-hans", ".hans", ".zh_hans", ".zhhans", ".gb", ".simplified"]
|
|
|
|
|
simplified_chinese = [".chs", ".sc", ".zhs",".zh-hans",".hans",".zh_hans",".zhhans",".gb",".simplified"]
|
|
|
|
|
simplified_chinese_forced = [".chs.forced", ".sc.forced", ".zhs.forced", "hans.forced", ".gb.forced", u"简体中文.forced", u"双语.forced"]
|
|
|
|
|
traditional_chinese_fuzzy = [u"繁", u"雙語"]
|
|
|
|
|
traditional_chinese = [".cht", ".tc", ".zh-tw", ".zht", ".zh-hant", ".zhhant", ".zh_hant", ".hant", ".big5", ".traditional"]
|
|
|
|
|
traditional_chinese = [".cht", ".tc", ".zh-tw", ".zht",".zh-hant",".zhhant",".zh_hant",".hant", ".big5", ".traditional"]
|
|
|
|
|
traditional_chinese_forced = [".cht.forced", ".tc.forced", ".zht.forced", "hant.forced", ".big5.forced", u"繁體中文.forced", u"雙語.forced", "zh-tw.forced"]
|
|
|
|
|
try:
|
|
|
|
|
dest_folder = get_subtitle_destination_folder() or ''
|
|
|
|
@ -370,6 +370,7 @@ def list_missing_subtitles_movies(no=None, epno=None, send_event=True):
|
|
|
|
|
logging.error("BAZARR list missing subtitles query to DB returned this instead of rows: " + movies_subtitles)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use_embedded_subs = settings.general.getboolean('use_embedded_subs')
|
|
|
|
|
|
|
|
|
|
for movie_subtitles in movies_subtitles:
|
|
|
|
@ -467,38 +468,36 @@ def list_missing_subtitles_movies(no=None, epno=None, send_event=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def series_full_scan_subtitles():
|
|
|
|
|
episodes = database.execute("SELECT sonarrEpisodeId, path FROM table_episodes")
|
|
|
|
|
episodes = database.execute("SELECT path FROM table_episodes")
|
|
|
|
|
|
|
|
|
|
for i, episode in enumerate(episodes, 1):
|
|
|
|
|
store_subtitles(episode['path'], path_mappings.path_replace(episode['path']),
|
|
|
|
|
'episode', episode['sonarrEpisodeId'])
|
|
|
|
|
store_subtitles(episode['path'], path_mappings.path_replace(episode['path']))
|
|
|
|
|
|
|
|
|
|
gc.collect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def movies_full_scan_subtitles():
|
|
|
|
|
movies = database.execute("SELECT radarrId, path FROM table_movies")
|
|
|
|
|
movies = database.execute("SELECT path FROM table_movies")
|
|
|
|
|
|
|
|
|
|
for i, movie in enumerate(movies, 1):
|
|
|
|
|
store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']),
|
|
|
|
|
'movie', movie['radarrId'])
|
|
|
|
|
store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']))
|
|
|
|
|
|
|
|
|
|
gc.collect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def series_scan_subtitles(no):
|
|
|
|
|
episodes = database.execute("SELECT sonarrEpisodeId, path FROM table_episodes WHERE sonarrSeriesId=? ORDER BY sonarrEpisodeId",
|
|
|
|
|
episodes = database.execute("SELECT path FROM table_episodes WHERE sonarrSeriesId=? ORDER BY sonarrEpisodeId",
|
|
|
|
|
(no,))
|
|
|
|
|
|
|
|
|
|
for episode in episodes:
|
|
|
|
|
store_subtitles(episode['path'], path_mappings.path_replace(episode['path']), 'episode', episode['sonarrEpisodeId'])
|
|
|
|
|
store_subtitles(episode['path'], path_mappings.path_replace(episode['path']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def movies_scan_subtitles(no):
|
|
|
|
|
movies = database.execute("SELECT radarrId, path FROM table_movies WHERE radarrId=? ORDER BY radarrId", (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_mappings.path_replace_movie(movie['path']), 'movie', movie['radarrId'])
|
|
|
|
|
store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_external_subtitles_path(file, subtitle):
|
|
|
|
@ -537,7 +536,7 @@ def guess_external_subtitles(dest_folder, subtitles):
|
|
|
|
|
detected_language = None
|
|
|
|
|
|
|
|
|
|
# to improve performance, skip detection of files larger that 1M
|
|
|
|
|
if os.path.getsize(subtitle_path) > 1 * 1024 * 1024:
|
|
|
|
|
if os.path.getsize(subtitle_path) > 1*1024*1024:
|
|
|
|
|
logging.debug("BAZARR subtitles file is too large to be text based. Skipping this file: " +
|
|
|
|
|
subtitle_path)
|
|
|
|
|
continue
|
|
|
|
@ -548,10 +547,10 @@ def guess_external_subtitles(dest_folder, subtitles):
|
|
|
|
|
try:
|
|
|
|
|
text = text.decode('utf-8')
|
|
|
|
|
detected_language = guess_language(text)
|
|
|
|
|
# add simplified and traditional chinese detection
|
|
|
|
|
#add simplified and traditional chinese detection
|
|
|
|
|
if detected_language == 'zh':
|
|
|
|
|
traditional_chinese_fuzzy = [u"繁", u"雙語"]
|
|
|
|
|
traditional_chinese = [".cht", ".tc", ".zh-tw", ".zht", ".zh-hant", ".zhhant", ".zh_hant", ".hant", ".big5", ".traditional"]
|
|
|
|
|
traditional_chinese = [".cht", ".tc", ".zh-tw", ".zht",".zh-hant",".zhhant",".zh_hant",".hant", ".big5", ".traditional"]
|
|
|
|
|
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(traditional_chinese)) or (str(subtitle_path).lower())[:-5] in traditional_chinese_fuzzy:
|
|
|
|
|
detected_language == 'zt'
|
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
|