Get more accurate when search artist name
This commit is contained in:
parent
1a0948d52b
commit
fdd95d73f3
Binary file not shown.
@ -8,10 +8,13 @@ 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:
|
||||
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
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user