From 2ef8823c2dc084407244626baa0ec5c624cd5c65 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 16 Mar 2022 12:09:50 +0700 Subject: [PATCH] better channel overwrite update form --- tubearchivist/home/src/index/channel.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tubearchivist/home/src/index/channel.py b/tubearchivist/home/src/index/channel.py index ccbdacc..97b6212 100644 --- a/tubearchivist/home/src/index/channel.py +++ b/tubearchivist/home/src/index/channel.py @@ -275,14 +275,18 @@ class YoutubeChannel(YouTubeItem): def set_overwrites(self, overwrites): """set per channel overwrites""" valid_keys = ["download_format", "autodelete_days"] - for key in overwrites: + + to_write = self.json_data.get("channel_overwrites", {}) + for key, value in overwrites.items(): if key not in valid_keys: raise ValueError(f"invalid overwrite key: {key}") + if value in [0, "0"]: + del to_write[key] + continue + if value: + to_write.update({key: value}) - if "channel_overwrites" in self.json_data.keys(): - self.json_data["channel_overwrites"].update(overwrites) - else: - self.json_data["channel_overwrites"] = overwrites + self.json_data["channel_overwrites"] = to_write def channel_overwrites(channel_id, overwrites):