From e08dcaabd6b6839a24d7e2d9bd64f1cb11a9c06b Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Wed, 22 Mar 2017 20:23:31 +0200 Subject: [PATCH] REFACTOR: Pull if statements outside for loop --- youtube_dl_gui/downloadmanager.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/youtube_dl_gui/downloadmanager.py b/youtube_dl_gui/downloadmanager.py index db7cf94..cf3ecef 100644 --- a/youtube_dl_gui/downloadmanager.py +++ b/youtube_dl_gui/downloadmanager.py @@ -168,18 +168,15 @@ class DownloadItem(object): else: self.progress_stats[key] = value - # Extract extra stuff - if key == "filename": - self.filenames.append(stats_dict[key]) + # Extract extra stuff + if "filename" in stats_dict: + self.filenames.append(stats_dict["filename"]) - if key == "extension": - self.extensions.append(stats_dict[key]) + if "extension" in stats_dict: + self.extensions.append(stats_dict["extension"]) - if key == "path": - self.path = stats_dict[key] - - if key == "status": - self._set_stage(stats_dict[key]) + if "path" in stats_dict: + self.path = stats_dict["path"] if "filesize" in stats_dict: if stats_dict["percent"] == "100%" and len(self.filesizes) < len(self.filenames): @@ -195,6 +192,8 @@ class DownloadItem(object): self.filesizes.append(post_proc_filesize) self.progress_stats["filesize"] = format_bytes(post_proc_filesize) + self._set_stage(stats_dict["status"]) + def _set_stage(self, status): if status in self.ACTIVE_STAGES: self._stage = self.STAGES[1]