Skip to content

Instantly share code, notes, and snippets.

@AlexLarra
Last active February 8, 2016 21:43
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 AlexLarra/6891560770d5eff7a2c2 to your computer and use it in GitHub Desktop.
Save AlexLarra/6891560770d5eff7a2c2 to your computer and use it in GitHub Desktop.
pass downloaded folders from google music to a uniq folder
#!/usr/bin/env ruby -w
require 'pathname'
require 'fileutils'
unless ARGV.size == 2
abort 'Usage: ruby music.rb google_folder_route new_folder'
end
def copy(path = @from)
if path.file?
copy_song(path)
return true
end
path.children.each do |directory|
copy(directory)
end
end
def copy_song(song_path)
destination = @to.realpath + song_name(song_path)
FileUtils.copy(song_path, destination)
puts "Copied: #{destination}"
end
def song_name(path)
"#{author(path)} - #{title_song(path)}"
end
def author(path)
author = path.parent.sub("#{@from}/", "")
author.dirname.to_s == "." ? author : author.dirname
end
def title_song(path)
title = path.basename.to_s
title[3, title.size]
end
begin
@from = Pathname.new(ARGV[0])
@to = Pathname.new(ARGV[1])
copy
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment