yt_mp3 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 +17 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +8 -0
- data/bin/yt_mp3 +28 -0
- data/lib/yt_mp3/version.rb +4 -0
- data/lib/yt_mp3/youtube_mp3.rb +39 -0
- data/lib/yt_mp3.rb +17 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/youtube_mp3_spec.rb +23 -0
- data/yt_mp3.gemspec +21 -0
- metadata +93 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Jakub Kaflik
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# YtMp3
|
|
2
|
+
|
|
3
|
+
Easily download YouTube videos as Mp3 with commandline tool!
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
$ gem install yt_mp3
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
$ yt_mp3 http://www.youtube.com/watch?v=DYyWVlh8NLM
|
|
11
|
+
|
|
12
|
+
## YouTube MP3 API:
|
|
13
|
+
This gem was build on top of [YouTube-Mp3.org](http://youtube-mp3.org). Every MP3 file convertion are made by them. There I've described an API:
|
|
14
|
+
|
|
15
|
+
### Request a video to mp3 convert:
|
|
16
|
+
GET: http://www.youtube-mp3.org/api/pushItem/?item=#{video_url}&xy=yx&bf=false&r=#{Time.now.to_i}
|
|
17
|
+
RESPONSE: video_id
|
|
18
|
+
|
|
19
|
+
HTTParty.get("http://www.youtube-mp3.org/api/pushItem/?item=http%3A//www.youtube.com/watch%3Fv%3D41L3a0QUzwY%26feature%3Dg-all-u&xy=yx&bf=false&r=#{Time.now.to_i}").body
|
|
20
|
+
=> "41L3a0QUzwY"
|
|
21
|
+
|
|
22
|
+
### Get video info (we need it to get a hash). Repeat until status is "serving".
|
|
23
|
+
GET: http://www.youtube-mp3.org/api/itemInfo/?video_id=#{video_id}&ac=www&r=#{Time.now.to_i}
|
|
24
|
+
RESPONSE: info JSON fetched by response.body.match(/\Ainfo = (.*?);\z/)[1]
|
|
25
|
+
|
|
26
|
+
HTTParty.get()
|
|
27
|
+
|
|
28
|
+
## Contributing
|
|
29
|
+
|
|
30
|
+
1. Fork it
|
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
32
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/yt_mp3
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'trollop'
|
|
4
|
+
|
|
5
|
+
$:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
|
|
6
|
+
require "yt_mp3"
|
|
7
|
+
|
|
8
|
+
opts = Trollop::options do
|
|
9
|
+
version "yt_mp3 #{YTMp3::VERSION} (c) 2012 #{YTMp3::AUTHORS.join(', ')}"
|
|
10
|
+
banner <<-EOS
|
|
11
|
+
USAGE: #{$0} [url]
|
|
12
|
+
EOS
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
if ARGV.empty?
|
|
16
|
+
STDERR.puts "You need to provide a URL"
|
|
17
|
+
STDERR.puts "USAGE: #{$0} [url]"
|
|
18
|
+
else
|
|
19
|
+
mp3 = YTMp3::YouTubeMP3.new ARGV.first
|
|
20
|
+
puts "Converting #{mp3.url}..."
|
|
21
|
+
begin
|
|
22
|
+
mp3.convert
|
|
23
|
+
rescue Exception => e
|
|
24
|
+
STDERR.puts e
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
system "curl --progress-bar -L \"#{mp3.downloadable}\" > \"#{mp3.title}\".mp3"
|
|
28
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'timeout'
|
|
2
|
+
require 'httparty'
|
|
3
|
+
require 'uri'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
module YTMp3
|
|
7
|
+
class YouTubeMP3
|
|
8
|
+
|
|
9
|
+
attr_reader :url, :downloadable, :title
|
|
10
|
+
|
|
11
|
+
def initialize( url_or_id )
|
|
12
|
+
@url = YTMp3::uri?(url_or_id) ? url_or_id : "http://youtube.com/watch?v=#{url_or_id}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def convert
|
|
16
|
+
r = HTTParty.get "http://www.youtube-mp3.org/api/pushItem/?item=#{URI.escape(@url)}&xy=yx&bf=false&r#{Time.now.to_i}"
|
|
17
|
+
|
|
18
|
+
raise RequestFailed, "YouTubeMP3 service responsed: #{r.body}" unless r.response.class == Net::HTTPOK
|
|
19
|
+
|
|
20
|
+
video_id = r.body
|
|
21
|
+
|
|
22
|
+
Timeout::timeout(YOUTUBE_MP3_TIMEOUT) do
|
|
23
|
+
while true
|
|
24
|
+
r = HTTParty.get "http://www.youtube-mp3.org/api/itemInfo/?video_id=#{video_id}&ac=www&r=#{Time.now.to_i}"
|
|
25
|
+
|
|
26
|
+
raise RequestFailed, "YouTubeMP3 service responsed: #{r.body}" unless r.response.class == Net::HTTPOK
|
|
27
|
+
|
|
28
|
+
info = JSON.parse(r.body.match(/\Ainfo = (.*?);\z/)[1])
|
|
29
|
+
|
|
30
|
+
if info["status"] == "serving"
|
|
31
|
+
@downloadable = "http://www.youtube-mp3.org/get?video_id=#{video_id}&h=#{info['h']}&r=#{Time.now.to_i}"
|
|
32
|
+
@title = info["title"]
|
|
33
|
+
break
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/yt_mp3.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require "yt_mp3/version"
|
|
2
|
+
require "yt_mp3/youtube_mp3"
|
|
3
|
+
|
|
4
|
+
module YTMp3
|
|
5
|
+
def self.uri?(string)
|
|
6
|
+
uri = URI.parse(string)
|
|
7
|
+
%w( http https ).include?(uri.scheme)
|
|
8
|
+
rescue URI::BadURIError
|
|
9
|
+
false
|
|
10
|
+
rescue URI::InvalidURIError
|
|
11
|
+
false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class RequestFailed < StandardError; end
|
|
15
|
+
|
|
16
|
+
YOUTUBE_MP3_TIMEOUT = 90
|
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe YTMp3::YouTubeMP3 do
|
|
4
|
+
it "initialize by URL" do
|
|
5
|
+
YTMp3::YouTubeMP3.new("http://www.youtube.com/watch?v=KlJy_Cb21Lw").url.should eq "http://www.youtube.com/watch?v=KlJy_Cb21Lw"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "initialize by video_id" do
|
|
9
|
+
YTMp3::YouTubeMP3.new("KlJy_Cb21Lw").url.should eq "http://youtube.com/watch?v=KlJy_Cb21Lw"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "convert's video" do
|
|
13
|
+
mp3 = YTMp3::YouTubeMP3.new("KlJy_Cb21Lw")
|
|
14
|
+
mp3.convert
|
|
15
|
+
mp3.downloadable.should include "http://www.youtube-mp3.org/get?video_id=KlJy_Cb21Lw"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "has title" do
|
|
19
|
+
mp3 = YTMp3::YouTubeMP3.new("KlJy_Cb21Lw")
|
|
20
|
+
mp3.convert
|
|
21
|
+
mp3.title.should eq "Lady Antebellum - Need You Now (HQ) [Lyrics]"
|
|
22
|
+
end
|
|
23
|
+
end
|
data/yt_mp3.gemspec
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/yt_mp3/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = YTMp3::AUTHORS
|
|
6
|
+
gem.email = ["kofels@gmail.com"]
|
|
7
|
+
gem.description = %q{Simply download YT videos as mp3!}
|
|
8
|
+
gem.summary = gem.description
|
|
9
|
+
gem.homepage = "http://kofel.github.com/yt_mp3/"
|
|
10
|
+
|
|
11
|
+
gem.rubyforge_project = "yt_mp3"
|
|
12
|
+
gem.add_dependency "httparty"
|
|
13
|
+
gem.add_dependency "trollop"
|
|
14
|
+
|
|
15
|
+
gem.files = `git ls-files`.split($\)
|
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
18
|
+
gem.name = "yt_mp3"
|
|
19
|
+
gem.require_paths = ["lib"]
|
|
20
|
+
gem.version = YTMp3::VERSION
|
|
21
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: yt_mp3
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Jakub Kaflik
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-05-29 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: httparty
|
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: trollop
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
description: Simply download YT videos as mp3!
|
|
47
|
+
email:
|
|
48
|
+
- kofels@gmail.com
|
|
49
|
+
executables:
|
|
50
|
+
- yt_mp3
|
|
51
|
+
extensions: []
|
|
52
|
+
extra_rdoc_files: []
|
|
53
|
+
files:
|
|
54
|
+
- .gitignore
|
|
55
|
+
- .rspec
|
|
56
|
+
- Gemfile
|
|
57
|
+
- LICENSE
|
|
58
|
+
- README.md
|
|
59
|
+
- Rakefile
|
|
60
|
+
- bin/yt_mp3
|
|
61
|
+
- lib/yt_mp3.rb
|
|
62
|
+
- lib/yt_mp3/version.rb
|
|
63
|
+
- lib/yt_mp3/youtube_mp3.rb
|
|
64
|
+
- spec/spec_helper.rb
|
|
65
|
+
- spec/youtube_mp3_spec.rb
|
|
66
|
+
- yt_mp3.gemspec
|
|
67
|
+
homepage: http://kofel.github.com/yt_mp3/
|
|
68
|
+
licenses: []
|
|
69
|
+
post_install_message:
|
|
70
|
+
rdoc_options: []
|
|
71
|
+
require_paths:
|
|
72
|
+
- lib
|
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
|
+
none: false
|
|
75
|
+
requirements:
|
|
76
|
+
- - ! '>='
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
none: false
|
|
81
|
+
requirements:
|
|
82
|
+
- - ! '>='
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubyforge_project: yt_mp3
|
|
87
|
+
rubygems_version: 1.8.22
|
|
88
|
+
signing_key:
|
|
89
|
+
specification_version: 3
|
|
90
|
+
summary: Simply download YT videos as mp3!
|
|
91
|
+
test_files:
|
|
92
|
+
- spec/spec_helper.rb
|
|
93
|
+
- spec/youtube_mp3_spec.rb
|