Skip to content

Instantly share code, notes, and snippets.

@jacoyutorius
Created September 1, 2017 00:47
Show Gist options
  • Select an option

  • Save jacoyutorius/d247836e6e17a241bb7e3abda748f17f to your computer and use it in GitHub Desktop.

Select an option

Save jacoyutorius/d247836e6e17a241bb7e3abda748f17f to your computer and use it in GitHub Desktop.
# (output sample)
# {"Library Tapes"=>
# [{"A Summer Beneath The Trees"=>
# ["01 The Sound Of Emptiness Part 1.m4p",
# "02 Pieces Of Us Were Left On The Tracks....m4p",
# "03 Above The Flood.m4p",
# "04 A Summer Beneath The Trees.m4p",
# "05 The Fragile Tide.m4p",
# "06 The Modest Triumph.m4p",
# "07 The Sound Of Emptiness Part 2.m4p",
# "09 ...And The Rain Did Fall.m4p"]}]}]
require "pp"
base_dirs = [
"/Users/yuto/Music/iTunes/iTunes\ Media/Music",
"/Users/yuto/Music/iTunes/iTunes\ Media/Apple\ Music"
]
data = []
base_dirs.each do |base_dir|
next unless Dir.exist? base_dir
artist_dirs = Dir.glob("#{base_dir}/*")
artist_dirs.each do |artist_dir|
artist = artist_dir.split("/").last
albums = []
Dir.glob("#{artist_dir}/*").each do |album_dir|
album = album_dir.split("/").last
songs = Dir.glob("#{album_dir}/*").map{|song_path| song_path.split("/").last }
albums << {"#{album}" => songs}
end
data << {"#{artist}" => albums }
end
end
pp data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment