Created
June 9, 2010 16:39
-
-
Save UserAd/431768 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'mp3info' | |
require 'logger' | |
require 'gdata' | |
#ARGV[0] - directory | |
#cover.jpg - cover | |
#description.txt - description for tracks | |
#tags.txt - tags | |
LOGIN = '' | |
PASSWORD = '' | |
API_KEY = '' | |
SOURCE = '' | |
DIR = ARGV[0] | |
description = File.read("#{DIR}/description.txt") | |
tags = File.read("#{DIR}/tags.txt") | |
log = Logger.new STDOUT | |
log.level = Logger::DEBUG | |
require 'gdata' | |
yt = GData::Client::YouTube.new | |
yt.source = SOURCE | |
yt.clientlogin(LOGIN,PASSWORD) | |
yt.client_id = SOURCE | |
yt.developer_key = API_KEY | |
feed = yt.get('http://gdata.youtube.com/feeds/api/users/default/uploads').to_xml | |
Dir.glob("#{DIR}/*.mp3").each do |f| | |
log.info "processing #{f}" | |
log.debug "Stage 1 - mp3 info" | |
info = Mp3Info.open(f) | |
new_title = "#{info.tag.artist} - #{info.tag.album} - #{info.tag.title}" | |
fps = 1.to_f / info.length | |
log.debug "Stage 2 - convert" | |
`mencoder mf://#{DIR}/cover.jpg -mf fps=#{fps} -ovc lavc -lavcopts vcodec=mpeg4 -audiofile "#{f}" -oac mp3lame -lameopts abr:br=160 -srate 44100 -ofps 25 -o output.avi` | |
log.debug "Stage 3 - upload" | |
mime_type = 'video/mpeg' | |
feed = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads' | |
entry = <<-EOF | |
<entry xmlns="http://www.w3.org/2005/Atom" | |
xmlns:media="http://search.yahoo.com/mrss/" | |
xmlns:yt="http://gdata.youtube.com/schemas/2007"> | |
<media:group> | |
<media:title type="plain">#{new_title}</media:title> | |
<media:description type="plain">#{description.gsub('[TITLE]', info.tag.title)}</media:description> | |
<media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Music</media:category> | |
<media:keywords>#{tags}</media:keywords> | |
</media:group> | |
</entry> | |
EOF | |
response = yt.post_file(feed, "output.avi", mime_type, entry).to_xml | |
File.delete(f) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment