From dba3388567818cb5c60be9d406d3e1cccc84b3ea Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 29 Apr 2026 14:22:03 +0200 Subject: Refactor database connections and add integration tests - Use context managers for sqlite3 connections in cron, vclogs, and database utils - Add URL helper utility for yt-dlp with clean_url_for_ytdlp function - Add slow integration test markers and new integration test files - Fix test imports to use conftest directly instead of tests.conftest - Improve downloader error handling and use COPYPARTY_URL_UPLOAD env var - Update pytest.ini with slow test markers and warning filters - Document slow test usage in AGENTS.md --- cogs/utils/url_helper.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cogs/utils/url_helper.py (limited to 'cogs/utils/url_helper.py') diff --git a/cogs/utils/url_helper.py b/cogs/utils/url_helper.py new file mode 100644 index 0000000..eac06f1 --- /dev/null +++ b/cogs/utils/url_helper.py @@ -0,0 +1,21 @@ +# This file is part of Senator Sperma +# Licensed under the GPL-3.0 License +# Copyright (C) 2026 Salmonik @ salmonik@tuta.io +# https://codeberg.org/salmonik/senator-sperma + + +def clean_url_for_ytdlp(url: str) -> str: + """Clean URL by removing everything after the first '&'. + + This prevents yt-dlp from interpreting additional query parameters + (like &list=...) as playlist URLs. + + Example: + Input: https://www.youtube.com/watch?v=lPGipwoJiOM&list=RDlPGipwoJiOM& + Output: https://www.youtube.com/watch?v=lPGipwoJiOM + """ + # Find the first '&' and truncate + first_ampersand = url.find('&') + if first_ampersand != -1: + return url[:first_ampersand] + return url -- cgit v1.2.3