Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #!/usr/bin/env ruby -w
  2.  
  3. require 'pathname'
  4. require 'fileutils'
  5.  
  6. unless ARGV.size == 2
  7. abort 'Usage: ruby music.rb google_folder_route new_folder'
  8. end
  9.  
  10.  
  11. def copy(path = @from)
  12. if path.file?
  13. copy_song(path)
  14. return true
  15. end
  16.  
  17. path.children.each do |directory|
  18. copy(directory)
  19. end
  20. end
  21.  
  22. def copy_song(song_path)
  23. destination = @to.realpath + song_name(song_path)
  24. FileUtils.copy(song_path, destination)
  25. puts "Copied: #{destination}"
  26. end
  27.  
  28. def song_name(path)
  29. "#{author(path)} - #{title_song(path)}"
  30. end
  31.  
  32. def author(path)
  33. author = path.parent.sub("#{@from}/", "")
  34. author.dirname.to_s == "." ? author : author.dirname
  35. end
  36.  
  37. def title_song(path)
  38. title = path.basename.to_s
  39. title[3, title.size]
  40. end
  41.  
  42. begin
  43. @from = Pathname.new(ARGV[0])
  44. @to = Pathname.new(ARGV[1])
  45.  
  46. copy
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement