From 8cfb59a36835527bd4a5dd450f8a372f127a07bb Mon Sep 17 00:00:00 2001 From: Cooper Hammond Date: Fri, 21 Jun 2019 16:30:14 -0700 Subject: [PATCH] logging for individual song done! --- src/glue/song.cr | 35 +++++++++++++++++++---------------- src/interact/ripper.cr | 6 +++++- src/interact/tagger.cr | 4 +++- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/glue/song.cr b/src/glue/song.cr index 33be62c..848e33d 100644 --- a/src/glue/song.cr +++ b/src/glue/song.cr @@ -58,26 +58,29 @@ class Song "Check your input and try again.") end - puts "Downloading video ..." + puts "Downloading video:" Ripper.download_mp3(url.as(String), filename) - # temp_albumart_filename = ".tempalbumart.jpg" - # HTTP::Client.get(data["album"]["images"][0]["url"].to_s) do |response| - # File.write(temp_albumart_filename, response.body_io) - # end + temp_albumart_filename = ".tempalbumart.jpg" + HTTP::Client.get(data["album"]["images"][0]["url"].to_s) do |response| + File.write(temp_albumart_filename, response.body_io) + end - # tagger = Tags.new(filename) - # tagger.add_album_art(temp_albumart_filename) - # tagger.add_text_tag("title", data["name"].to_s) - # tagger.add_text_tag("artist", data["artists"][0]["name"].to_s) - # tagger.add_text_tag("album", data["album"]["name"].to_s) - # tagger.add_text_tag("genre", - # @spotify_searcher.find_genre(data["artists"][0]["id"].to_s)) - # tagger.add_text_tag("track", data["track_number"].to_s) - # tagger.add_text_tag("disc", data["disc_number"].to_s) + tagger = Tags.new(filename) + tagger.add_album_art(temp_albumart_filename) + tagger.add_text_tag("title", data["name"].to_s) + tagger.add_text_tag("artist", data["artists"][0]["name"].to_s) + tagger.add_text_tag("album", data["album"]["name"].to_s) + tagger.add_text_tag("genre", + @spotify_searcher.find_genre(data["artists"][0]["id"].to_s)) + tagger.add_text_tag("track", data["track_number"].to_s) + tagger.add_text_tag("disc", data["disc_number"].to_s) - # tagger.save() - # File.delete(temp_albumart_filename) + puts "Tagging metadata ..." + tagger.save() + File.delete(temp_albumart_filename) + + puts %("#{data["name"].to_s}" by "#{data["artists"][0]["name"].to_s}" downloaded.) end diff --git a/src/interact/ripper.cr b/src/interact/ripper.cr index 7c760ac..2296e2f 100644 --- a/src/interact/ripper.cr +++ b/src/interact/ripper.cr @@ -55,8 +55,12 @@ module Ripper print "\e[1A" print "\e[0K\r" end - puts line + puts line.sub("[download]", " ") @dl_status_index += 1 + + if line.includes? "100%" + puts "Converting to mp3 ..." + end end end diff --git a/src/interact/tagger.cr b/src/interact/tagger.cr index 50208d1..c441e1d 100644 --- a/src/interact/tagger.cr +++ b/src/interact/tagger.cr @@ -36,8 +36,10 @@ class Tags def save : Nil @query_args.push(%("_#{@filename}")) command = @BIN_LOC.to_s + "/ffmpeg " + @query_args.join(" ") - system(command) + l = Logger.new(command, ".tagger.log") + l.start { |line, start| } + File.delete(@filename) File.rename("_" + @filename, @filename) end