ruby pastebin

Posted by Anonymous on Mon 25th Jan 05:10 (modification of post by view diff)
download | new post

  1. #!/usr/bin/ruby
  2. #
  3. # copy a playlist to a dir
  4.  
  5. unless ARGV.size == 2
  6.         $stderr.puts "usage: #{$0} file.pls dest"
  7.         exit -1
  8. end
  9. pls, dst = ARGV[0,1]
  10.  
  11. fd=File.open(pls)
  12. args={}
  13. $stderr.puts fd.readline # header
  14. while (arg=fd.readline) !~ /^NumberOfEntries=/
  15.         name, value = arg.split(/=/)
  16.         args[name]=value
  17. end
  18. p args
  19. pls_size = arg[/=(.*)/,1].to_i
  20. files=[]
  21. fd.each_line do |line|
  22.         name=line[/File\d+=(.*)$/,1]
  23.         files << name
  24. end
  25. if files.size != pls_size
  26.         $stderr.puts "warning: playlist size was #{files.size}, but expected #{pls_size}"
  27. end
  28. File.open("/tmp/foo","w") do |of|
  29.         of.print files.join(0.chr)
  30. end
  31. dst="/tmp/bar"
  32. IO.popen("rsync --files-from=- -0 -PnavzS --stats /home/irish/ #{dst}","w") do |of|
  33.         of.print files.join(0.chr)
  34. end

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


I'm Human
Remember me



Captcha required for posting