fix --url ignoring argument on song.cr

This commit is contained in:
imsamuka 2022-01-02 16:57:10 -03:00
parent 289f1d8c63
commit bdc63b4c35
No known key found for this signature in database
GPG key ID: AF9ACFEF1FD372EE
2 changed files with 15 additions and 11 deletions

View file

@ -50,9 +50,9 @@ class CLI
#{Style.blue "-s, --song <song>"} Specify song name to download
#{Style.blue "-A, --album <album>"} Specify the album name to download
#{Style.blue "-p, --playlist <playlist>"} Specify the playlist name to download
#{Style.blue "-u, --url [<url>]"} Specify the youtube url to download from
#{Style.blue " "} (for single songs, include as an command-line
#{Style.blue " "} argument, for albums or playlists do not)
#{Style.blue "-u, --url <url>"} Specify the youtube url to download from
#{Style.blue " "} (for albums and playlists, the command-line
#{Style.blue " "} argument is ignored, and it should be '')
#{Style.blue "-S, --select"} Use a menu to choose each song's video source
#{Style.bold "Examples:"}

View file

@ -53,12 +53,12 @@ class Song
# Find, downloads, and tags the mp3 song that this class represents.
# Optionally takes a youtube URL to download from
#
#
# ```
# Song.new("Bohemian Rhapsody", "Queen").grab_it
# ```
def grab_it(url : (String | Nil) = nil, flags = {} of String => String)
ask_url = flags["url"]?
passed_url : (String | Nil) = flags["url"]
select_link = flags["select"]?
outputter("intro", 0)
@ -92,11 +92,15 @@ class Song
@artist_name = data["artists"][0]["name"].as_s
@filename = "#{Pattern.parse(Config.filename_pattern, data)}.mp3"
if ask_url
outputter("url", 4)
url = gets
if !url.nil? && url.strip == ""
url = nil
if passed_url
if passed_url.strip != ""
url = passed_url
else
outputter("url", 4)
url = gets
if !url.nil? && url.strip == ""
url = nil
end
end
end
@ -130,7 +134,7 @@ class Song
outputter("albumart", 0)
# check if song's metadata has been modded in playlist, update artist accordingly
if data["artists"][-1]["owner"]?
if data["artists"][-1]["owner"]?
@artist = data["artists"][-1]["name"].as_s
else
@artist = data["artists"][0]["name"].as_s