Skip to content

Instantly share code, notes, and snippets.

@katsuma
Created December 23, 2011 18:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save katsuma/1515069 to your computer and use it in GitHub Desktop.
Save katsuma/1515069 to your computer and use it in GitHub Desktop.
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