Skip to content

Instantly share code, notes, and snippets.

@farktronix
Created March 25, 2013 23:34
Show Gist options
  • Save farktronix/5241882 to your computer and use it in GitHub Desktop.
Save farktronix/5241882 to your computer and use it in GitHub Desktop.
Replace an iTunes Library with one song. Use at your own risk!
#!/usr/bin/ruby
require 'fileutils'
include FileUtils::Verbose
$rickRollFile="/Volumes/Media/.RickRoll.mp3"
def rickRollDir(sourceDir, destDir)
for filename in Dir.entries(sourceDir)
next if filename=~/\.\.?$/
sourcePath = File.join(sourceDir, filename)
destPath = File.join(destDir, filename)
fstat = File.stat(sourcePath)
case fstat.ftype
when "file"
if (filename=~/\.xml$/ || filename=~/iTunes Library$/)
copy(sourcePath, destPath)
next
end
if filename=~/\.m(p3|4a)$/
sourcePath = $rickRollFile
end
printf("Linking %s to %s\n", sourcePath, destPath)
begin
File.symlink(sourcePath, destPath)
rescue SystemCallError
end
when "directory"
printf("Creating dir: %s\n", destPath)
makedirs(destPath)
rickRollDir(sourcePath, destPath)
end
end
end
rickRollDir("/Users/sucker/Music", "/Users/sucker/RRMusic")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment