Last active
February 8, 2016 21:43
-
-
Save AlexLarra/6891560770d5eff7a2c2 to your computer and use it in GitHub Desktop.
pass downloaded folders from google music to a uniq folder
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 -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