Skip to content

Commit

Permalink
Added frontend notification during automatic syncing of subtitles. #2724
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheus65535 authored Dec 7, 2024
1 parent 1cc5c42 commit f4ca0f9
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 30 deletions.
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
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
6 changes: 5 additions & 1 deletion bazarr/subtitles/mass_download/movies.py
Original file line number Diff line number Diff line change
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)
12 changes: 10 additions & 2 deletions bazarr/subtitles/mass_download/series.py
Original file line number Diff line number Diff line change
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")
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
6 changes: 5 additions & 1 deletion bazarr/subtitles/wanted/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def wanted_search_missing_subtitles_movies():
logging.info("BAZARR All providers are throttled")
break

hide_progress(id='wanted_movies_progress')
show_progress(id='wanted_movies_progress',
header='Searching subtitles...',
name="",
value=count_movies,
count=count_movies)

logging.info('BAZARR Finished searching for missing Movies Subtitles. Check History for more information.')
6 changes: 5 additions & 1 deletion bazarr/subtitles/wanted/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ def wanted_search_missing_subtitles_series():
logging.info("BAZARR All providers are throttled")
break

hide_progress(id='wanted_episodes_progress')
show_progress(id='wanted_episodes_progress',
header='Searching subtitles...',
name='',
value=count_episodes,
count=count_episodes)

logging.info('BAZARR Finished searching for missing Series Subtitles. Check History for more information.')
39 changes: 22 additions & 17 deletions frontend/src/modules/task/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,32 @@ class TaskDispatcher {

public updateProgress(items: Site.Progress[]) {
items.forEach((item) => {
// TODO: FIX ME!
item.value += 1;

if (item.value >= item.count && this.progress[item.id]) {
updateNotification(notification.progress.end(item.id, item.header));
delete this.progress[item.id];
} else if (item.value > 1 && this.progress[item.id]) {
updateNotification(
notification.progress.update(
item.id,
item.header,
item.name,
item.value,
item.count,
),
);
} else if (item.value > 1 && this.progress[item.id] === undefined) {
if (this.progress[item.id] === undefined) {
showNotification(notification.progress.pending(item.id, item.header));
this.progress[item.id] = true;
setTimeout(() => this.updateProgress([item]), 1000);

return;
}

if (item.value >= item.count) {
updateNotification(notification.progress.end(item.id, item.header));
delete this.progress[item.id];

return;
}

item.value += 1;

updateNotification(
notification.progress.update(
item.id,
item.header,
item.name,
item.value,
item.count,
),
);
});
}

Expand Down

0 comments on commit f4ca0f9

Please sign in to comment.