Skip to content

Commit

Permalink
Merge pull request #2 from morpheus65535/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
destpstrzy authored Dec 18, 2024
2 parents c45b3b1 + c8e2894 commit 87f32dc
Show file tree
Hide file tree
Showing 41 changed files with 450 additions and 234 deletions.
4 changes: 2 additions & 2 deletions bazarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def check_python_version():
print("Python " + minimum_py3_str + " or greater required. "
"Current version is " + platform.python_version() + ". Please upgrade Python.")
exit_program(EXIT_PYTHON_UPGRADE_NEEDED)
elif int(python_version[0]) == 3 and int(python_version[1]) > 11:
print("Python version greater than 3.11.x is unsupported. Current version is " + platform.python_version() +
elif int(python_version[0]) == 3 and int(python_version[1]) > 12:
print("Python version greater than 3.12.x is unsupported. Current version is " + platform.python_version() +
". Keep in mind that even if it works, you're on your own.")
elif (int(python_version[0]) == minimum_py3_tuple[0] and int(python_version[1]) < minimum_py3_tuple[1]) or \
(int(python_version[0]) != minimum_py3_tuple[0]):
Expand Down
4 changes: 2 additions & 2 deletions bazarr/api/badges/badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Badges(Resource):
def get(self):
"""Get badges count to update the UI"""
episodes_conditions = [(TableEpisodes.missing_subtitles.is_not(None)),
(TableEpisodes.missing_subtitles.is_not('[]'))]
(TableEpisodes.missing_subtitles != '[]')]
episodes_conditions += get_exclusion_clause('series')
missing_episodes = database.execute(
select(TableEpisodes.missing_subtitles)
Expand All @@ -49,7 +49,7 @@ def get(self):
missing_episodes_count += len(ast.literal_eval(episode.missing_subtitles))

movies_conditions = [(TableMovies.missing_subtitles.is_not(None)),
(TableMovies.missing_subtitles.is_not('[]'))]
(TableMovies.missing_subtitles != '[]')]
movies_conditions += get_exclusion_clause('movie')
missing_movies = database.execute(
select(TableMovies.missing_subtitles)
Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/episodes/wanted.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get(self):
episodeid = args.get('episodeid[]')

wanted_conditions = [(TableEpisodes.missing_subtitles.is_not(None)),
(TableEpisodes.missing_subtitles.is_not('[]'))]
(TableEpisodes.missing_subtitles != '[]')]
if len(episodeid) > 0:
wanted_conditions.append((TableEpisodes.sonarrEpisodeId in episodeid))
start = 0
Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/movies/wanted.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get(self):
radarrid = args.get("radarrid[]")

wanted_conditions = [(TableMovies.missing_subtitles.is_not(None)),
(TableMovies.missing_subtitles.is_not('[]'))]
(TableMovies.missing_subtitles != '[]')]
if len(radarrid) > 0:
wanted_conditions.append((TableMovies.radarrId.in_(radarrid)))
start = 0
Expand Down
8 changes: 7 additions & 1 deletion bazarr/api/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ class Series(Resource):
'alternativeTitles': fields.List(fields.String),
'audio_language': fields.Nested(get_audio_language_model),
'episodeFileCount': fields.Integer(default=0),
'ended': fields.Boolean(),
'episodeMissingCount': fields.Integer(default=0),
'fanart': fields.String(),
'imdbId': fields.String(),
'lastAired': fields.String(),
'monitored': fields.Boolean(),
'overview': fields.String(),
'path': fields.String(),
Expand Down Expand Up @@ -74,7 +76,7 @@ def get(self):
.subquery()

episodes_missing_conditions = [(TableEpisodes.missing_subtitles.is_not(None)),
(TableEpisodes.missing_subtitles.is_not('[]'))]
(TableEpisodes.missing_subtitles != '[]')]
episodes_missing_conditions += get_exclusion_clause('series')

episodeMissingCount = select(TableShows.sonarrSeriesId,
Expand All @@ -100,6 +102,8 @@ def get(self):
TableShows.tags,
TableShows.title,
TableShows.year,
TableShows.ended,
TableShows.lastAired,
episodeFileCount.c.episodeFileCount,
episodeMissingCount.c.episodeMissingCount) \
.select_from(TableShows) \
Expand Down Expand Up @@ -128,6 +132,8 @@ def get(self):
'tags': x.tags,
'title': x.title,
'year': x.year,
'ended': x.ended,
'lastAired': x.lastAired,
'episodeFileCount': x.episodeFileCount,
'episodeMissingCount': x.episodeMissingCount,
}) for x in database.execute(stmt).all()]
Expand Down
2 changes: 2 additions & 0 deletions bazarr/app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ class TableShows(Base):
alternativeTitles = mapped_column(Text)
audio_language = mapped_column(Text)
created_at_timestamp = mapped_column(DateTime)
ended = mapped_column(Text)
fanart = mapped_column(Text)
imdbId = mapped_column(Text)
lastAired = mapped_column(Text)
monitored = mapped_column(Text)
overview = mapped_column(Text)
path = mapped_column(Text, nullable=False, unique=True)
Expand Down
6 changes: 5 additions & 1 deletion bazarr/radarr/sync/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ def update_movies(send_event=True):
files_missing += 1

if send_event:
hide_progress(id='movies_progress')
show_progress(id='movies_progress',
header='Syncing movies...',
name='',
value=movies_count,
count=movies_count)

trace(f"Skipped {files_missing} file missing movies out of {movies_count}")
if sync_monitored:
Expand Down
40 changes: 24 additions & 16 deletions bazarr/sonarr/sync/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import os

from dateutil import parser

from app.config import settings
from app.database import TableShows, database, select
from constants import MINIMUM_VIDEO_SIZE
Expand Down Expand Up @@ -45,6 +47,10 @@ def seriesParser(show, action, tags_dict, language_profiles, serie_default_profi

imdbId = show['imdbId'] if 'imdbId' in show else None

ended = 'True' if 'ended' in show and show['ended'] else 'False'

lastAired = parser.parse(show['lastAired']).strftime("%Y-%m-%d") if 'lastAired' in show and show['lastAired'] else None

audio_language = []
if not settings.general.parse_embedded_audio_track:
if get_sonarr_info.is_legacy():
Expand All @@ -56,22 +62,24 @@ def seriesParser(show, action, tags_dict, language_profiles, serie_default_profi
audio_language = []

parsed_series = {
'title': show["title"],
'path': show["path"],
'tvdbId': int(show["tvdbId"]),
'sonarrSeriesId': int(show["id"]),
'overview': overview,
'poster': poster,
'fanart': fanart,
'audio_language': str(audio_language),
'sortTitle': show['sortTitle'],
'year': str(show['year']),
'alternativeTitles': str(alternate_titles),
'tags': str(tags),
'seriesType': show['seriesType'],
'imdbId': imdbId,
'monitored': str(bool(show['monitored']))
}
'title': show["title"],
'path': show["path"],
'tvdbId': int(show["tvdbId"]),
'sonarrSeriesId': int(show["id"]),
'overview': overview,
'poster': poster,
'fanart': fanart,
'audio_language': str(audio_language),
'sortTitle': show['sortTitle'],
'year': str(show['year']),
'alternativeTitles': str(alternate_titles),
'tags': str(tags),
'seriesType': show['seriesType'],
'imdbId': imdbId,
'monitored': str(bool(show['monitored'])),
'ended': ended,
'lastAired': lastAired,
}

if action == 'insert':
parsed_series['profileId'] = serie_default_profile
Expand Down
6 changes: 5 additions & 1 deletion bazarr/sonarr/sync/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ def update_series(send_event=True):
event_stream(type='series', action='delete', payload=series)

if send_event:
hide_progress(id='series_progress')
show_progress(id='series_progress',
header='Syncing series...',
name='',
value=series_count,
count=series_count)

if sync_monitored:
trace(f"skipped {skipped_count} unmonitored series out of {i}")
Expand Down
6 changes: 5 additions & 1 deletion bazarr/subtitles/indexer/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ def movies_full_scan_subtitles(use_cache=None):
count=count_movies)
store_subtitles_movie(movie.path, path_mappings.path_replace_movie(movie.path), use_cache=use_cache)

hide_progress(id='movies_disk_scan')
show_progress(id='movies_disk_scan',
header='Full disk scan...',
name='Movies subtitles',
value=count_movies,
count=count_movies)

gc.collect()

Expand Down
6 changes: 5 additions & 1 deletion bazarr/subtitles/indexer/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ def series_full_scan_subtitles(use_cache=None):
count=count_episodes)
store_subtitles(episode.path, path_mappings.path_replace(episode.path), use_cache=use_cache)

hide_progress(id='episodes_disk_scan')
show_progress(id='episodes_disk_scan',
header='Full disk scan...',
name='Episodes subtitles',
value=count_episodes,
count=count_episodes)

gc.collect()

Expand Down
8 changes: 6 additions & 2 deletions bazarr/subtitles/mass_download/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


def movies_download_subtitles(no):
conditions = [(TableMovies.radarrId.is_(no))]
conditions = [(TableMovies.radarrId == no)]
conditions += get_exclusion_clause('movie')
stmt = select(TableMovies.path,
TableMovies.missing_subtitles,
Expand Down Expand Up @@ -99,4 +99,8 @@ def movies_download_subtitles(no):
history_log_movie(1, no, result)
send_notifications_movie(no, result.message)

hide_progress(id=f'movie_search_progress_{no}')
show_progress(id=f'movie_search_progress_{no}',
header='Searching missing subtitles...',
name=movie.title,
value=count_movie,
count=count_movie)
14 changes: 11 additions & 3 deletions bazarr/subtitles/mass_download/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def series_download_subtitles(no):
raise OSError

conditions = [(TableEpisodes.sonarrSeriesId == no),
(TableEpisodes.missing_subtitles.is_not('[]'))]
(TableEpisodes.missing_subtitles != '[]')]
conditions += get_exclusion_clause('series')
episodes_details = database.execute(
select(TableEpisodes.sonarrEpisodeId,
Expand Down Expand Up @@ -64,7 +64,11 @@ def series_download_subtitles(no):
logging.info("BAZARR All providers are throttled")
break

hide_progress(id=f'series_search_progress_{no}')
show_progress(id=f'series_search_progress_{no}',
header='Searching missing subtitles...',
name='',
value=count_episodes_details,
count=count_episodes_details)


def episode_download_subtitles(no, send_progress=False, providers_list=None):
Expand Down Expand Up @@ -145,6 +149,10 @@ def episode_download_subtitles(no, send_progress=False, providers_list=None):
send_notifications(episode.sonarrSeriesId, episode.sonarrEpisodeId, result.message)

if send_progress:
hide_progress(id=f'episode_search_progress_{no}')
show_progress(id=f'episode_search_progress_{no}',
header='Searching missing subtitles...',
name=f'{episode.title} - S{episode.season:02d}E{episode.episode:02d} - {episode.episodeTitle}',
value=1,
count=1)
else:
logging.info("BAZARR All providers are throttled")
4 changes: 2 additions & 2 deletions bazarr/subtitles/refiners/anidb.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_show_information(self, tvdb_series_id, tvdb_series_season, episode):
mapping_list = anime.find('mapping-list')

# Handle mapping list for Specials
if mapping_list:
if mapping_list is not None:
for mapping in mapping_list.findall("mapping"):
if mapping.text is None:
continue
Expand Down Expand Up @@ -176,7 +176,7 @@ def get_episodes(self, series_id):

episode_elements = xml_root.find('episodes')

if not episode_elements:
if episode_elements is None:
raise ValueError

return etree.tostring(episode_elements, encoding='utf8', method='xml')
Expand Down
6 changes: 2 additions & 4 deletions bazarr/subtitles/refiners/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ def refine_from_db(path, video):

if data:
video.series = _TITLE_RE.sub('', data.seriesTitle)
if not video.season and data.season:
video.season = int(data.season)
if not video.episode and data.episode:
video.episode = int(data.episode)
video.season = int(data.season)
video.episode = int(data.episode)
video.title = data.episodeTitle

# Only refine year as a fallback
Expand Down
19 changes: 18 additions & 1 deletion bazarr/subtitles/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

import logging
import gc
import os

from app.config import settings
from app.event_handler import show_progress, hide_progress
from subtitles.tools.subsyncer import SubSyncer


Expand Down Expand Up @@ -40,7 +42,22 @@ def sync_subtitles(video_path, srt_path, srt_lang, forced, hi, percent_score, so
'sonarr_episode_id': sonarr_episode_id,
'radarr_id': radarr_id,
}
subsync.sync(**sync_kwargs)
subtitles_filename = os.path.basename(srt_path)
show_progress(id=f'subsync_{subtitles_filename}',
header='Syncing Subtitle',
name=srt_path,
value=0,
count=1)
try:
subsync.sync(**sync_kwargs)
except Exception:
hide_progress(id=f'subsync_{subtitles_filename}')
else:
show_progress(id=f'subsync_{subtitles_filename}',
header='Syncing Subtitle',
name=srt_path,
value=1,
count=1)
del subsync
gc.collect()
return True
Expand Down
6 changes: 5 additions & 1 deletion bazarr/subtitles/tools/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ def translate_line(id, line, attempt):
for i, line in enumerate(translated_lines):
lines_list[line['id']] = line['line']

hide_progress(id=f'translate_progress_{dest_srt_file}')
show_progress(id=f'translate_progress_{dest_srt_file}',
header=f'Translating subtitles lines to {language_from_alpha3(to_lang)}...',
name='',
value=lines_list_len,
count=lines_list_len)

logging.debug(f'BAZARR saving translated subtitles to {dest_srt_file}')
for i, line in enumerate(subs):
Expand Down
12 changes: 10 additions & 2 deletions bazarr/subtitles/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ def upgrade_subtitles():
upgraded_from_id=episode['original_id'])
send_notifications(episode['sonarrSeriesId'], episode['sonarrEpisodeId'], result.message)

hide_progress(id='upgrade_episodes_progress')
show_progress(id='upgrade_episodes_progress',
header='Upgrading episodes subtitles...',
name='',
value=count_episode_to_upgrade,
count=count_episode_to_upgrade)

if use_radarr:
movies_to_upgrade = get_upgradable_movies_subtitles()
Expand Down Expand Up @@ -231,7 +235,11 @@ def upgrade_subtitles():
history_log_movie(3, movie['radarrId'], result, upgraded_from_id=movie['original_id'])
send_notifications_movie(movie['radarrId'], result.message)

hide_progress(id='upgrade_movies_progress')
show_progress(id='upgrade_movies_progress',
header='Upgrading movies subtitles...',
name='',
value=count_movie_to_upgrade,
count=count_movie_to_upgrade)

logging.info('BAZARR Finished searching for Subtitles to upgrade. Check History for more information.')

Expand Down
7 changes: 3 additions & 4 deletions bazarr/subtitles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ def get_video(path, title, sceneName, providers=None, media_type="movie"):
logging.debug(f'BAZARR guessing video object using scene name: {scenename_with_extension}')
scenename_video = parse_video(scenename_with_extension, hints=hints, dry_run=True)
refine_video_with_scenename(initial_video=video, scenename_video=scenename_video)

video.original_name = os.path.basename(path)
video.original_path = path
logging.debug('BAZARR resulting video object once refined using scene name: %s',
json.dumps(vars(video), cls=GuessitEncoder, indent=4, ensure_ascii=False))

for key, refiner in registered_refiners.items():
logging.debug("Running refiner: %s", key)
Expand Down Expand Up @@ -105,6 +104,6 @@ def _set_forced_providers(pool, also_forced=False, forced_required=False):

def refine_video_with_scenename(initial_video, scenename_video):
for key, value in vars(scenename_video).items():
if value:
if value and getattr(initial_video, key) in [None, (), {}, []]:
setattr(initial_video, key, value)
return initial_video
Loading

0 comments on commit 87f32dc

Please sign in to comment.