Skip to content

Instantly share code, notes, and snippets.

@mjacobus
Created July 30, 2020 13:18
Show Gist options
  • Select an option

  • Save mjacobus/cf097999460b66b0aefa8cb31e0fe8f4 to your computer and use it in GitHub Desktop.

Select an option

Save mjacobus/cf097999460b66b0aefa8cb31e0fe8f4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
begin
require 'taglib'
rescue LoadError
puts "Cannot load taglib: https://robinst.github.io/taglib-ruby/"
end
number = 0
Dir['_arquivos/cantico_*.mp4'].each do |file|
print "Remove #{file}? "
a = gets.chomp.downcase
if a == 'y'
FileUtils.rm(file)
end
end
while true
number += 1
print "Song #{number}: "
song_number = gets.chomp
if song_number.downcase == 'q'
exit
end
song_number = song_number.to_s.rjust(3, '0')
source_file = "canticos/sjjm_T_#{song_number}_r480P.mp4"
target_file = "_arquivos/cantico_#{number}_#{song_number}.mp4"
if defined?(TagLib)
TagLib::FileRef.open(source_file) do |fileref|
unless fileref.null?
title = fileref.tag.title
puts title
target_file = "_arquivos/cantico_#{number} - #{title}.mp4"
end
end
end
FileUtils.copy(source_file, target_file)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment