$ bundle exec ruby main.rb
Last active
August 29, 2015 14:06
-
-
Save syon/df144494b7c59ea2e4ff to your computer and use it in GitHub Desktop.
tracks フォルダに格納した mp3 ファイルの情報を読み取って JSON ファイルに変換し tracks.json に出力します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "ruby-audioinfo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "audioinfo" | |
require "json" | |
tracks = [] | |
Dir::glob("tracks/*.mp3").each do |path, idx| | |
filename = path.sub /tracks\//, '' | |
AudioInfo.open(path) do |info| | |
#time = "#{info.length / 60}:#{info.length % 60}" | |
tracks.push({artist: info.artist, title: info.title, time: info.length, filename: filename}) | |
end | |
end | |
open("tracks.json", "w"){|f| f.write(JSON.pretty_generate(tracks))} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment