Skip to content

Commit d2b93ef

Browse files
committed
Add support to treat URL's passed in lists as URL's by ytmdl
The URL's passed in a list were earlier treat as a song. Added some changes to detect if the passed entry is a Youtube URL and accordingly treat it as one. Should fix #205
2 parents a8803d3 + 6259dea commit d2b93ef

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

bin/ytmdl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ from ytmdl.utils.archive import (
3939
is_present_in_archive,
4040
add_song_to_archive
4141
)
42+
from ytmdl.yt import is_yt_url
4243
from ytmdl.__version__ import __version__
4344

4445
# init colorama for windows
@@ -514,7 +515,15 @@ def extract_data():
514515
logger.info("Downloading songs in {}".format(args.list))
515516
for song_name in songs:
516517
logger.debug(song_name)
517-
args.SONG_NAME = [song_name]
518+
519+
# Set the song name if an URL is not passed, else
520+
# pass it as an URL
521+
if is_yt_url(song_name):
522+
logger.debug("Detected passed song as URL")
523+
args.url = song_name
524+
else:
525+
args.SONG_NAME = [song_name]
526+
518527
main(args)
519528
else:
520529
logger.info("{}: is empty".format(args.list))

ytmdl/yt.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ def is_playlist(url):
257257
return match(playlist_part, url)
258258

259259

260+
def is_yt_url(url):
261+
"""
262+
Check if the passed URL is a valid youtube URL.
263+
"""
264+
yt_url = r"https?://(www\.|music\.)?youtube\.com/watch\?v=.*?$"
265+
return match(yt_url, url)
266+
267+
260268
def get_playlist(
261269
url,
262270
proxy,

0 commit comments

Comments
 (0)