aural 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ data/**
6
+ .idea/**
7
+ *.flv
8
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in aural.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "aural/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "aural"
7
+ s.version = Aural::VERSION
8
+ s.authors = ["ian asaff"]
9
+ s.email = ["ian.asaff@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{flv to music}
12
+ s.description = %q{flv to music}
13
+
14
+ s.rubyforge_project = "aural"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "mechanize"
24
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'aural'
4
+
5
+ if ARGV.empty?
6
+ puts "you need to enter a full youtube url (including the 'http://' part) in quotes."
7
+ puts "for example: http://www.youtube.com/watch?v=oHg5SJYRHA0"
8
+ else
9
+ Aural::Grabber.grab ARGV.shift
10
+ end
@@ -0,0 +1,65 @@
1
+ require 'cgi'
2
+ require 'mechanize'
3
+ require 'benchmark'
4
+ require 'tempfile'
5
+ require "aural/version"
6
+
7
+ module Aural
8
+ class Grabber
9
+ class << self
10
+
11
+ def temp_file
12
+ file = Tempfile.new('foo')
13
+ begin
14
+ yield file
15
+ ensure
16
+ file.close
17
+ file.unlink
18
+ end
19
+ end
20
+
21
+ def grab(url)
22
+ agent = Mechanize.new
23
+ page = agent.get url
24
+ title = page.title.strip.split("\n").first
25
+ filename = "#{title}.mp3"
26
+
27
+ regex = /,url=(http%3A%2F%2F.*?\.youtube.com%2Fvideoplayback%3Fsparams.*?id%3D.*?)\\u0026/
28
+
29
+ page.content.scan(regex) do |m|
30
+ m = m.first
31
+ next unless m =~ /algorithm/
32
+ next if @written
33
+
34
+ puts "looking for your video. this might take a minute or two."
35
+ response = agent.get(CGI.unescape(m))
36
+ if response.is_a?(Mechanize::File) && response.header["content-type"] == "video/x-flv"
37
+ puts "ok found it. creating the mp3 now."
38
+ temp_file do |file|
39
+ file.write(response.content)
40
+ transcode(file.path, filename)
41
+ end
42
+ exit
43
+ end
44
+ end
45
+ end
46
+
47
+ def transcode(path,filename)
48
+ cmd = "ffmpeg -i \"#{path}\" -acodec libmp3lame -ac 2 -ab 128K \"#{filename}\""
49
+ announce cmd
50
+ if system cmd
51
+ puts "done! enjoy your shiny new mp3: #{filename}"
52
+ else
53
+ puts "shit. something broke. ask ian to fix this."
54
+ end
55
+ end
56
+
57
+ # debug function
58
+ def announce(s)
59
+ puts "*"*100
60
+ puts s
61
+ puts "*"*100
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,62 @@
1
+ require 'cgi'
2
+ require 'mechanize'
3
+ require 'benchmark'
4
+ require 'tempfile'
5
+
6
+
7
+ def temp_file
8
+ file = Tempfile.new('foo')
9
+ begin
10
+ yield file
11
+ ensure
12
+ file.close
13
+ file.unlink
14
+ end
15
+ end
16
+
17
+ def grab(url)
18
+ agent = Mechanize.new
19
+ page = agent.get url
20
+ title = page.title.strip.split("\n").first
21
+ filename = "#{title}.mp3"
22
+
23
+ regex = /,url=(http%3A%2F%2F.*?\.youtube.com%2Fvideoplayback%3Fsparams.*?id%3D.*?)\\u0026/
24
+
25
+ page.content.scan(regex) do |m|
26
+ m = m.first
27
+ next unless m =~ /algorithm/
28
+ next if @written
29
+
30
+ puts "looking for your video. this might take a minute or two."
31
+ response = agent.get(CGI.unescape(m))
32
+ if response.is_a?(Mechanize::File) && response.header["content-type"] == "video/x-flv"
33
+ puts "ok found it. creating the mp3 now."
34
+ temp_file do |file|
35
+ file.write(response.content)
36
+ transcode(file.path, filename)
37
+ end
38
+ exit
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+
45
+ def transcode(path,filename)
46
+ cmd = "ffmpeg -i \"#{path}\" -acodec libmp3lame -ac 2 -ab 128K \"#{filename}\""
47
+ announce cmd
48
+ if system cmd
49
+ puts "done! enjoy your shiny new mp3: #{filename}"
50
+ else
51
+ puts "shit. something broke. ask ian to fix this."
52
+ end
53
+ end
54
+
55
+ def announce(s)
56
+ puts "*"*100
57
+ puts s
58
+ puts "*"*100
59
+ end
60
+
61
+
62
+ grab ARGV.shift
@@ -0,0 +1,3 @@
1
+ module Aural
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aural
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ian asaff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: &70203933333880 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70203933333880
25
+ description: flv to music
26
+ email:
27
+ - ian.asaff@gmail.com
28
+ executables:
29
+ - grab
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - Rakefile
36
+ - aural.gemspec
37
+ - bin/grab
38
+ - lib/aural.rb
39
+ - lib/aural/hacking.rb
40
+ - lib/aural/version.rb
41
+ homepage: ''
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project: aural
61
+ rubygems_version: 1.8.16
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: flv to music
65
+ test_files: []