aural 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/aural.gemspec +24 -0
- data/bin/grab +10 -0
- data/lib/aural.rb +65 -0
- data/lib/aural/hacking.rb +62 -0
- data/lib/aural/version.rb +3 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/aural.gemspec
ADDED
@@ -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
|
data/bin/grab
ADDED
data/lib/aural.rb
ADDED
@@ -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
|
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: []
|