Create a gist now

Instantly share code, notes, and snippets.

@katsuma /taifu
Created Dec 23, 2011

What would you like to do?
taifu will add youtube sound to your iTunes library silently
#!/usr/bin/env ruby
# usage:
# taifu http://www.youtube.com/watch?v=KPWfBfFFrwsx
# taifu depends on VLC.app and rb-appscript gem
require 'rubygems'
require 'appscript'
require 'fileutils'
include Appscript
VLC = "/Applications/VLC.app/Contents/MacOS/VLC"
DOWNLOAD = "./"
youtube_url = ARGV.first || STDIN.read
raise "no Youtube URL is given" unless youtube_url
youtube_url = youtube_url.split('&').first
wav = "#{DOWNLOAD}/taifu_#{Time.now.strftime("%Y%m%d%H%M%s")}.wav"
system "#{VLC} -I dummy #{youtube_url} --sout='#transcode{acodec=s16l,channels=2,samplerate=44100}:std{access=file,mux=wav,dst=#{wav}}' vlc://quit 2>/dev/null"
its = app "iTunes.app"
org_track = its.add(MacTypes::FileURL.path(File.expand_path("#{wav}")))
current_track = org_track.convert.first
current_track.name.set "TAIFU_NAME"
current_track.album.set "TAIFU_ALBUM"
current_track.artist.set "TAIFU_ARTIST"
org_track.delete
FileUtils.rm_f wav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment