Skip to content

Instantly share code, notes, and snippets.

@syon
Last active August 29, 2015 14:06
Show Gist options
  • Save syon/df144494b7c59ea2e4ff to your computer and use it in GitHub Desktop.
Save syon/df144494b7c59ea2e4ff to your computer and use it in GitHub Desktop.
tracks フォルダに格納した mp3 ファイルの情報を読み取って JSON ファイルに変換し tracks.json に出力します。
$ bundle exec ruby main.rb
source "https://rubygems.org"
gem "ruby-audioinfo"
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