Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement