From 1258bc106d0875fb545b5ea7b6cc513d44f04c2f Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Mon, 23 Feb 2026 18:08:58 -0800 Subject: allow for a local .radio file to be used (newline seperated list of urls) --- yt_radio.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/yt_radio.py b/yt_radio.py index 80b6178..145ad68 100644 --- a/yt_radio.py +++ b/yt_radio.py @@ -56,7 +56,34 @@ def _save_cache(): logger.exception("Failed to save cache to %s", CACHE_FILE) +def load_urls_from_file(path: str): + urls = [] + if not path: + logger.debug("No path provided to load_urls_from_file") + return urls + try: + with open(path, "r", encoding="utf-8") as f: + for raw in f: + line = raw.strip() + if not line: + continue + if line.startswith("#"): + continue + if " #" in line: + line = line.split(" #", 1)[0].strip() + urls.append(line) + logger.info("Loaded %d URLs from %s", len(urls), path) + except FileNotFoundError: + logger.warning("URL file not found: %s", path) + except Exception: + logger.exception("Failed to read URL file: %s", path) + return urls + + def convert_playlist_to_links(link: str): + if link.endswith(".radio"): + logger.info(".radio file specified, loading from local file") + return load_urls_from_file(link) ydl_opts = { "quiet": True, "extract_flat": True, -- cgit v1.2.3