From 4f9c16f821af54110889c01eed0cb6bbf9eb9ce2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 12 Jul 2020 17:51:46 +0200 Subject: Revert torrent finish logic --- automedia.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/automedia.py b/automedia.py index e514dea..c13ef26 100755 --- a/automedia.py +++ b/automedia.py @@ -201,19 +201,20 @@ def get_finished_torrents(torrents): filtered_torrents.append(torrent) return filtered_torrents -def get_non_matching_torrents_by_name(torrents1, torrents2): - non_matching_torrents = [] +def get_unfinished_torrents(torrents): + filtered_torrents = [] + for torrent in torrents: + if abs(100.0 - torrent.progress) > 0.001: + filtered_torrents.append(torrent) + return filtered_torrents + +def get_matching_torrents_by_name(torrents1, torrents2): + matching_torrents = [] for torrent1 in torrents1: - found_match = False for torrent2 in torrents2: if torrent1.id == torrent2.id: - found_match = True - break - - if not found_match: - non_matching_torrents.append(torrent1.name) - - return non_matching_torrents + matching_torrents.append(torrent1.name) + return matching_torrents def get_rss_from_episode_info(episode_name_raw, episode_info): submitter_query_text = '' @@ -584,7 +585,7 @@ def sync(rss_config_dir, html_config_dir, download_dir, sync_rate_sec): html_tracked_dir = os.path.join(html_config_dir, "tracked") # This is also check rate for html items check_torrent_status_rate_sec = 15 - prev_finished_torrents = [] + unfinished_torrents = [] # TODO: Remove this and keep a list of "in progress" html items in memory instead. session_id = uuid.uuid4().hex @@ -627,10 +628,10 @@ def sync(rss_config_dir, html_config_dir, download_dir, sync_rate_sec): while count < sync_rate_sec/check_torrent_status_rate_sec: torrents = get_torrent_progress(tc) finished_torrents = get_finished_torrents(torrents) - newly_finished_torrents = get_non_matching_torrents_by_name(prev_finished_torrents, finished_torrents) + newly_finished_torrents = get_matching_torrents_by_name(finished_torrents, unfinished_torrents) for newly_finished_torrent in newly_finished_torrents: show_notification("Download finished", newly_finished_torrent) - prev_finished_torrents = finished_torrents + unfinished_torrents = get_unfinished_torrents(torrents) time.sleep(check_torrent_status_rate_sec) count += 1 -- cgit v1.2.3