Last active
June 27, 2020 19:06
-
-
Save djadriano/b3414ff7fa3d54251f7eca656712f05d to your computer and use it in GitHub Desktop.
Script to copy and rename mp3 files
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
require 'fileutils' | |
# ------------------------------------------------------------------------------------- | |
# To execute the script use: | |
# ruby organize-files.rb url_of_folder_to_find_mp3 url_of_folder_to_copy_files | |
# ------------------------------------------------------------------------------------- | |
dirToFind = "#{ARGV[0]}/**/*.mp3" | |
dirToFindFlac = "#{ARGV[0]}/**/*.flac" | |
dirToCopy = ARGV[1] | |
dirToRename = "#{ARGV[1]}/**/*" | |
arrItemsToFind = [ | |
'(Full)', | |
' [Hq + Hd Full]', | |
' [Hd+Hq][Full]', | |
' [Hd]', | |
' [Hd+Hq]', | |
' [Full Hq + Hd]', | |
' [Hq Hd]', | |
' [Hd + Hq]', | |
' [Hqhd]', | |
'-Ukhx', | |
' [Hq + Hd Free Download]', | |
' [Hd + Hq] [ Free Release]', | |
' [Hqhd]', | |
' [Hd + Hq][Full]', | |
' [Hq Original]', | |
' [Full][Tbt]', | |
' [Full Version] + [Hd] + [320kbps]', | |
' [Tbt]', | |
'[Free Release]', | |
' [Free Release]', | |
' [Hq Hd]', | |
' (Full Hq)', | |
' [Full Hq + Hd Version]', | |
' Full Hd[Www.mp3fiber.Com]', | |
' [Out Now!]', | |
' [Hd & Hq]', | |
' [Free]', | |
' [Full Hq + Hd Upcoming Free Release]', | |
' (Hd)', | |
' [Hqihd]', | |
' [Hq Free]', | |
' + [Hd] + [320kbps]', | |
' (Lyrics)', | |
' [Hd]', | |
' [HQ Edit]', | |
'-ukhx', | |
'01-', | |
'01_', | |
'02-', | |
'02_', | |
'03-', | |
'03_', | |
'04-', | |
'04_' | |
] | |
def adjust_file_name(str) | |
newEntry = str.downcase.gsub(/\w+/, &:capitalize) | |
newEntry = newEntry.gsub('.Mp3', '.mp3') | |
return newEntry | |
end | |
def copy_files(dirToFind, dirToCopy) | |
Dir[dirToFind].each do |old| | |
# Copy Files | |
if File.basename(old).include?('(radio') | |
puts '-----------------------------------------' | |
puts 'have a radio version' | |
puts old | |
puts '-----------------------------------------' | |
File.delete(old) if File.exist?(old) | |
else | |
puts '-----------------------------------' | |
puts 'Copying Files' | |
puts '-----------------------------------' | |
puts old | |
FileUtils.cp(old, dirToCopy) | |
end | |
end | |
end | |
def rename_files(dirToRename, arrItemsToFind) | |
puts '-----------------------------------' | |
Dir[dirToRename].each do |old| | |
if File.basename(old).include?('.mp3') || File.basename(old).include?('.flac') | |
newEntry = old | |
puts "Rename file: #{newEntry}" | |
puts '-----------------------------------' | |
arrItemsToFind.each {|a| | |
if File.basename(old).include?(a) | |
newEntry = newEntry.gsub(a, '') | |
end | |
} | |
if File.basename(old).include?('_') | |
newEntry = newEntry.gsub('_', ' ') | |
end | |
newEntry = adjust_file_name(newEntry) | |
File.rename(old, newEntry) | |
end | |
end | |
end | |
copy_files(dirToFind, dirToCopy) | |
copy_files(dirToFindFlac, dirToCopy) | |
rename_files(dirToRename, arrItemsToFind) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment