aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/utils/url_helper.py
blob: eac06f1cadb79fb6399a00f980a400ab3e8cbbc8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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