Created
December 23, 2011 18:56
-
-
Save katsuma/1515069 to your computer and use it in GitHub Desktop.
taifu will add youtube sound to your iTunes library silently
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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