diff --git a/backend/__pycache__/downloader.cpython-310.pyc b/backend/__pycache__/downloader.cpython-310.pyc index d0dbdb1..665b4d1 100644 Binary files a/backend/__pycache__/downloader.cpython-310.pyc and b/backend/__pycache__/downloader.cpython-310.pyc differ diff --git a/backend/downloader.py b/backend/downloader.py index 2c4884e..d846808 100644 --- a/backend/downloader.py +++ b/backend/downloader.py @@ -8,11 +8,14 @@ def is_playlist(query: str) -> bool: def is_youtube_url(query: str) -> bool: return query.startswith("http") -def max_duration_filter(max_seconds): +def duration_range_filter(min_seconds, max_seconds): def _filter(info, *, incomplete): duration = info.get('duration') - if duration and duration > max_seconds: - return f"Skipping: {info.get('title')} is longer than {max_seconds//60} minutes" + if duration: + if duration < min_seconds: + return f"Skipping: {info.get('title')} is shorter than {min_seconds//60} minutes" + if duration > max_seconds: + return f"Skipping: {info.get('title')} is longer than {max_seconds//60} minutes" return _filter def download_song(query: str): @@ -24,11 +27,8 @@ def download_song(query: str): elif is_playlist(query): yt_query = query noplaylist = False - elif len(query.split()) == 1: - yt_query = f"ytsearch50:{query}" - noplaylist = True else: - yt_query = f"ytsearch1:{query}" + yt_query = f"ytsearch10:{query}" # Always search for 10 results for any artist/song query noplaylist = True ydl_opts = { @@ -40,7 +40,7 @@ def download_song(query: str): }, { 'key': 'FFmpegMetadata', }], - 'match_filter': max_duration_filter(10 * 60), # 5 minutes in seconds + 'match_filter': duration_range_filter(2 * 60, 9 * 60), # 2 to 9 minutes 'noplaylist': noplaylist, 'quiet': False, 'verbose': True,