Merge pull request #84 from imsamuka/master

add option to apply metadata in existing file.

Apologies for the late merge, you sent this pull request right as school was beginning to pick up in earnest and I forgot about it in that rush. Thanks for the great work!
This commit is contained in:
Cooper Hammond 2022-01-27 11:18:58 -07:00 committed by GitHub
commit 3bbb0e767a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 29 deletions

View file

@ -22,7 +22,8 @@ class CLI
[["-p", "--playlist"], "playlist", "string"], [["-p", "--playlist"], "playlist", "string"],
[["-u", "--url"], "url", "string"], [["-u", "--url"], "url", "string"],
[["-S", "--select"], "select", "bool"], [["-S", "--select"], "select", "bool"],
[["--ask-skip"], "ask_skip", "bool"] [["--ask-skip"], "ask_skip", "bool"],
[["--apply"], "apply_file", "string"]
] ]
@args : Hash(String, String) @args : Hash(String, String)
@ -56,6 +57,7 @@ class CLI
#{Style.blue " "} argument is ignored, and it should be '') #{Style.blue " "} argument is ignored, and it should be '')
#{Style.blue "-S, --select"} Use a menu to choose each song's video source #{Style.blue "-S, --select"} Use a menu to choose each song's video source
#{Style.blue "--ask-skip"} Before every playlist/album song, ask to skip #{Style.blue "--ask-skip"} Before every playlist/album song, ask to skip
#{Style.blue "--apply <file>"} Apply metadata to a existing file
#{Style.bold "Examples:"} #{Style.bold "Examples:"}
$ #{Style.green %(irs --song "Bohemian Rhapsody" --artist "Queen")} $ #{Style.green %(irs --song "Bohemian Rhapsody" --artist "Queen")}

View file

@ -59,6 +59,7 @@ class Song
# ``` # ```
def grab_it(url : (String | Nil) = nil, flags = {} of String => String) def grab_it(url : (String | Nil) = nil, flags = {} of String => String)
passed_url : (String | Nil) = flags["url"]? passed_url : (String | Nil) = flags["url"]?
passed_file : (String | Nil) = flags["apply_file"]?
select_link = flags["select"]? select_link = flags["select"]?
outputter("intro", 0) outputter("intro", 0)
@ -92,40 +93,45 @@ class Song
@artist_name = data["artists"][0]["name"].as_s @artist_name = data["artists"][0]["name"].as_s
@filename = "#{Pattern.parse(Config.filename_pattern, data)}.mp3" @filename = "#{Pattern.parse(Config.filename_pattern, data)}.mp3"
if passed_url if passed_file
if passed_url.strip != "" puts Style.green(" +") + Style.dim(" Moving file: ") + passed_file
url = passed_url File.rename(passed_file, @filename)
else else
outputter("url", 4) if passed_url
url = gets if passed_url.strip != ""
if !url.nil? && url.strip == "" url = passed_url
url = nil else
outputter("url", 4)
url = gets
if !url.nil? && url.strip == ""
url = nil
end
end end
end end
end
if !url
outputter("url", 0)
url = Youtube.find_url(data, flags: flags)
if !url if !url
raise("There was no url found on youtube for " + outputter("url", 0)
%("#{@song_name}" by "#{@artist_name}. ) + url = Youtube.find_url(data, flags: flags)
"Check your input and try again.") if !url
raise("There was no url found on youtube for " +
%("#{@song_name}" by "#{@artist_name}. ) +
"Check your input and try again.")
end
outputter("url", 1)
else
outputter("url", 2)
url = Youtube.validate_url(url)
if !url
raise("The url is an invalid youtube URL " +
"Check the URL and try again")
end
outputter("url", 3)
end end
outputter("url", 1)
else
outputter("url", 2)
url = Youtube.validate_url(url)
if !url
raise("The url is an invalid youtube URL " +
"Check the URL and try again")
end
outputter("url", 3)
end
outputter("download", 0) outputter("download", 0)
Ripper.download_mp3(url.as(String), @filename) Ripper.download_mp3(url.as(String), @filename)
outputter("download", 1) outputter("download", 1)
end
outputter("albumart", 0) outputter("albumart", 0)
temp_albumart_filename = ".tempalbumart.jpg" temp_albumart_filename = ".tempalbumart.jpg"