From 219cc4bc5320b95ac27c76663762a2b42c6be530 Mon Sep 17 00:00:00 2001 From: Cooper Hammond Date: Fri, 14 Jun 2019 11:39:51 -0700 Subject: [PATCH] tagger based off of ffmpeg created --- shard.lock | 10 ++++++--- shard.yml | 4 ++-- src/interact/tagger.cr | 46 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 src/interact/tagger.cr diff --git a/shard.lock b/shard.lock index de2e9e8..8226e24 100644 --- a/shard.lock +++ b/shard.lock @@ -1,6 +1,10 @@ version: 1.0 shards: - spotify: - github: marceloboeira/spotify.cr - commit: 347727a4ebe4f3f4e55f6032de17cdd554a676bd + cr-taglib: + github: teknomunk/cr-taglib + commit: 5bfca75aaac31c0e4eee4c6e0d72c624af773c09 + + ydl_binaries: + github: cooperhammond/ydl-binaries + commit: 8a622bf9d2c0b848db8d8db2f46f09334a1f03f8 diff --git a/shard.yml b/shard.yml index 2862560..2064a6d 100644 --- a/shard.yml +++ b/shard.yml @@ -13,5 +13,5 @@ crystal: 0.28.0 license: MIT dependencies: - ydl_binaries: - github: cooperhammond/ydl-binaries \ No newline at end of file + ydl_binaries: + github: cooperhammond/ydl-binaries \ No newline at end of file diff --git a/src/interact/tagger.cr b/src/interact/tagger.cr new file mode 100644 index 0000000..ae4adfa --- /dev/null +++ b/src/interact/tagger.cr @@ -0,0 +1,46 @@ +# TODO: write comments/documentation + +class Tags + + @BIN_LOC = Path["~/.irs/bin".sub("~", Path.home)] + @query_args = [] of String + + + def initialize(@filename : String) + if !File.exists?(@filename) + raise "MP3 not found at location: #{@filename}" + end + + @query_args.push(%(-i "#{@filename}")) + + end + + def add_text_tag(key : String, value : String) + @query_args.push(%(-metadata #{key}="#{value}")) + end + + def add_album_art(image_location : String) + if !File.exists?(image_location) + raise "Image file not found at location: #{image_location}" + end + + @query_args.push(%(-i "#{image_location}")) + @query_args.push("-map 0:0 -map 1:0") + @query_args.push("-c copy") + @query_args.push("-id3v2_version 3") + @query_args.push(%(-metadata:s:v title="Album cover")) + @query_args.push(%(-metadata:s:v comment="Cover (front)")) + @query_args.push(%(-metadata:s:v title="Album cover")) + end + + def save + @query_args.push(%("#{@filename}")) + command = @BIN_LOC.to_s + "/ffmpeg " + @query_args.join(" ") + puts command + end +end + +# a = Tags.new("test.mp3") +# a.add_text_tag("title", "Warwick Avenue") +# a.add_album_art("file.png") +# a.save() \ No newline at end of file