Created
August 20, 2014 02:14
-
-
Save yuumi3/0cf898f7458642dd82fe to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'taglib' | |
MP_FILE_CLASSES = {'.mp3' => TagLib::MPEG::File, '.m4a' => TagLib::MP4::File} | |
def set_mp_audio_file_to_title(path, title) | |
MP_FILE_CLASSES[File.extname(path)].open(path) {|mp| mp.tag.title = title; mp.save} | |
puts " set #{path} title=#{title}" | |
rescue | |
puts " error: #{$!}" | |
exit(-1) | |
end | |
if ARGV.count < 2 | |
puts "Usage: #{$0} MPEG_AUDIO_FILE TITLE or" | |
puts " #{$0} -f FILE_AND_TITLE_LIST" | |
elsif ARGV[0] == '-f' | |
IO.readlines(ARGV[1]).each do |line| | |
path_title = line.split("\t") | |
set_mp_audio_file_to_title(*path_title) if path_title.length == 2 | |
end | |
else | |
set_mp_audio_file_to_title(ARGV[0], ARGV[1]) | |
end | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment