Top Level Namespace

Defined Under Namespace

Modules: Aural

Instance Method Summary collapse

Instance Method Details

#announce(s) ⇒ Object



55
56
57
58
59
# File 'lib/aural/hacking.rb', line 55

def announce(s)
  puts "*"*100
  puts s
  puts "*"*100
end

#grab(url) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/aural/hacking.rb', line 17

def grab(url)
  agent = Mechanize.new
  page = agent.get url
  title = page.title.strip.split("\n").first
  filename = "#{title}.mp3"

  regex = /,url=(http%3A%2F%2F.*?\.youtube.com%2Fvideoplayback%3Fsparams.*?id%3D.*?)\\u0026/

  page.content.scan(regex) do |m|
    m = m.first
    next unless m =~ /algorithm/
    next if @written

    puts "looking for your video. this might take a minute or two."
    response = agent.get(CGI.unescape(m))
    if response.is_a?(Mechanize::File) && response.header["content-type"] == "video/x-flv"
      puts "ok found it. creating the mp3 now."
      temp_file do |file|
        file.write(response.content)
        transcode(file.path, filename)
      end
      exit
    end
  end
end

#temp_fileObject



7
8
9
10
11
12
13
14
15
# File 'lib/aural/hacking.rb', line 7

def temp_file
  file = Tempfile.new('foo')
  begin
    yield file
  ensure
    file.close
    file.unlink
  end
end

#transcode(path, filename) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/aural/hacking.rb', line 45

def transcode(path,filename)
  cmd = "ffmpeg -i \"#{path}\" -acodec libmp3lame -ac 2 -ab 128K \"#{filename}\""
  announce cmd
  if system cmd
    puts "done! enjoy your shiny new mp3: #{filename}"
  else
    puts "shit. something broke. ask ian to fix this."
  end
end