From cb6315b1cc7bc7ed936cdb7c70514013c2fdc159 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Fri, 26 Jun 2026 17:23:22 -0700 Subject: fix: pass empty existing song list if output points to empty file --- playlist_generator/playlist_generator.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/playlist_generator/playlist_generator.py b/playlist_generator/playlist_generator.py index a02881a..0620c71 100644 --- a/playlist_generator/playlist_generator.py +++ b/playlist_generator/playlist_generator.py @@ -81,10 +81,16 @@ def main(): parser.add_argument("urls_file") parser.add_argument("output_file", default="../server/data/songs.ts") args = parser.parse_args() - with open(args.output_file, "r", encoding="utf-8") as f: - text = f.read() - array_text = re.search(r"\[.*\]", text, re.S).group(0) - songs = json5.loads(array_text) + songs = [] + try: + with open(args.output_file, "r", encoding="utf-8") as f: + text = f.read() + + if text.strip(): + array_text = re.search(r"\[.*\]", text, re.S).group(0) + songs = json5.loads(array_text) + except (AttributeError, json5.JSON5DecodeError): + songs = [] generator = PlaylistGenerator(songs) urls = generator.get_urls_from_file(args.urls_file) video_info = generator.extract(urls) -- cgit v1.2.3