From 61120f21b0a6183973b8bcbaa9c76516d89f5bed Mon Sep 17 00:00:00 2001 From: imsamuka Date: Fri, 7 Jan 2022 22:15:27 -0300 Subject: [PATCH] add option to apply metadata in existing file --- src/bottle/cli.cr | 4 ++- src/glue/song.cr | 62 ++++++++++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/bottle/cli.cr b/src/bottle/cli.cr index c0d22bb..fba8fa7 100755 --- a/src/bottle/cli.cr +++ b/src/bottle/cli.cr @@ -22,7 +22,8 @@ class CLI [["-p", "--playlist"], "playlist", "string"], [["-u", "--url"], "url", "string"], [["-S", "--select"], "select", "bool"], - [["--ask-skip"], "ask_skip", "bool"] + [["--ask-skip"], "ask_skip", "bool"], + [["--apply"], "apply_file", "string"] ] @args : Hash(String, String) @@ -56,6 +57,7 @@ class CLI #{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 "--ask-skip"} Before every playlist/album song, ask to skip + #{Style.blue "--apply "} Apply metadata to a existing file #{Style.bold "Examples:"} $ #{Style.green %(irs --song "Bohemian Rhapsody" --artist "Queen")} diff --git a/src/glue/song.cr b/src/glue/song.cr index 77fbd66..0655f9e 100755 --- a/src/glue/song.cr +++ b/src/glue/song.cr @@ -59,6 +59,7 @@ class Song # ``` def grab_it(url : (String | Nil) = nil, flags = {} of String => String) passed_url : (String | Nil) = flags["url"]? + passed_file : (String | Nil) = flags["apply_file"]? select_link = flags["select"]? outputter("intro", 0) @@ -92,40 +93,45 @@ class Song @artist_name = data["artists"][0]["name"].as_s @filename = "#{Pattern.parse(Config.filename_pattern, data)}.mp3" - if passed_url - if passed_url.strip != "" - url = passed_url - else - outputter("url", 4) - url = gets - if !url.nil? && url.strip == "" - url = nil + if passed_file + puts Style.green(" +") + Style.dim(" Moving file: ") + passed_file + File.rename(passed_file, @filename) + else + 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 - end - if !url - outputter("url", 0) - url = Youtube.find_url(data, flags: flags) if !url - raise("There was no url found on youtube for " + - %("#{@song_name}" by "#{@artist_name}. ) + - "Check your input and try again.") + outputter("url", 0) + url = Youtube.find_url(data, flags: flags) + 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 - 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) - Ripper.download_mp3(url.as(String), @filename) - outputter("download", 1) + outputter("download", 0) + Ripper.download_mp3(url.as(String), @filename) + outputter("download", 1) + end outputter("albumart", 0) temp_albumart_filename = ".tempalbumart.jpg"