-
Notifications
You must be signed in to change notification settings - Fork 1
/
mp3.rb
39 lines (33 loc) · 949 Bytes
/
mp3.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Encoding: utf-8
# Raw script to iterate through folders and set the musics' tag
# artist and title based on the filename
# http://robinst.github.io/taglib-ruby/
require 'taglib'
path = '/home/miguelgraz/Music/'
folders = []
folders << 'Classica'
folders << 'Dance'
folders << 'Funk Pagode Rap Samba Sertanejo'
folders << 'Gauchas'
folders << 'Grooveshark'
folders << 'Metal'
folders << 'MPB'
folders << 'Outros'
folders << 'Pop'
folders << 'Rock Internacional'
folders << 'Rock Nacional'
folders.each do |folder|
Dir.entries("#{path}#{folder}").each do |f|
next if ['.', '..'].include?(f)
TagLib::MPEG::File.open("#{path}#{folder}/#{f}") do |file|
artist, title = f.gsub(folder, '').gsub('.mp3', '').split(' - ', 2)
tag = file.id3v2_tag(true)
tag.artist = artist
tag.title = title
file.save
puts tag.artist
puts tag.title
puts '==================================='
end
end
end