Skip to content

Instantly share code, notes, and snippets.

@karthiks
Created September 1, 2014 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthiks/30d8606eab562e81e83f to your computer and use it in GitHub Desktop.
Save karthiks/30d8606eab562e81e83f to your computer and use it in GitHub Desktop.
To set the title metadata tag of a media file to that of its base_file_name
#!/usr/bin/env ruby
puts "Starting.."
require 'taglib'
#Dir['path/to/dir/*'].select { |e| File.file?(e) }
Dir.glob("./*.wma").each do |filename|
puts "File name: #{filename}"
TagLib::FileRef.open(filename) do |f|
title = File.basename(filename, ".*")
tag = f.tag
print "\t BEFORE: Title: #{tag.title} \n"
f.tag.title = title
f.save
print "\t AFTER: Title: #{title} \n"
end
end
puts "The End!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment