youtube-ripper 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/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/bin/yt_ripper +11 -0
- data/lib/youtube-ripper.rb +12 -0
- data/lib/youtube-ripper/downloader.rb +15 -0
- data/lib/youtube-ripper/ripper.rb +58 -0
- data/lib/youtube-ripper/version.rb +5 -0
- data/youtube-ripper.gemspec +21 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Maurizio De Magnis
|
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,46 @@
|
|
1
|
+
# Youtube::Ripper
|
2
|
+
|
3
|
+
It helps you extract and download a Youtube video.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
It requires the "curl" shell command.
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'youtube-ripper'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install youtube-ripper
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Via shell
|
24
|
+
|
25
|
+
```shell
|
26
|
+
$ yt_ripper "http://www.youtube.com/watch?v=sTSA_sWGM44"
|
27
|
+
```
|
28
|
+
|
29
|
+
This will download the video in your current folder, using the video's title as the filename.
|
30
|
+
|
31
|
+
## TODO
|
32
|
+
|
33
|
+
* test
|
34
|
+
* add command line options
|
35
|
+
* add travis-ci support
|
36
|
+
* handle the quality switch
|
37
|
+
* multi download (via config file)
|
38
|
+
* download a whole youtube playlist
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/yt_ripper
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'youtube-ripper'
|
4
|
+
|
5
|
+
puts "Attempting to download the video available at:\n#{ARGV[0]}"
|
6
|
+
ripper = Youtube::Ripper.new(ARGV[0]).fetch
|
7
|
+
puts "Found title: \"#{ripper.video.title}\""
|
8
|
+
downloader = Youtube::Downloader.new(ripper.video)
|
9
|
+
puts "Now downloading to: #{downloader.filename} .."
|
10
|
+
downloader.perform!
|
11
|
+
puts "Done."
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Youtube
|
2
|
+
class Downloader
|
3
|
+
def initialize(video)
|
4
|
+
@video = video
|
5
|
+
end
|
6
|
+
|
7
|
+
def perform!
|
8
|
+
`curl "#{@video.url}" -L -o #{filename}`
|
9
|
+
end
|
10
|
+
|
11
|
+
def filename
|
12
|
+
@filename ||= @video.title.strip.downcase.gsub(/[^a-z0-9]+/, '_') + ".mp4"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Youtube
|
2
|
+
class Ripper
|
3
|
+
attr_reader :video
|
4
|
+
|
5
|
+
def initialize(page_url)
|
6
|
+
@page_url = page_url
|
7
|
+
end
|
8
|
+
|
9
|
+
def fetch
|
10
|
+
@video = OpenStruct.new title: title, url: download_url
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def html
|
16
|
+
Nokogiri::HTML(open(@page_url))
|
17
|
+
end
|
18
|
+
|
19
|
+
def flashvars
|
20
|
+
@flashvars ||= fetch_flashvars
|
21
|
+
end
|
22
|
+
|
23
|
+
def title
|
24
|
+
@title ||= fetch_title
|
25
|
+
end
|
26
|
+
|
27
|
+
def download_url
|
28
|
+
@download_url ||= fetch_download_url
|
29
|
+
end
|
30
|
+
|
31
|
+
def fetch_flashvars
|
32
|
+
js_fragment = html.
|
33
|
+
css('#watch-video').
|
34
|
+
children.select {|x| x.name == 'script'}.
|
35
|
+
last.
|
36
|
+
children.
|
37
|
+
first.
|
38
|
+
content.
|
39
|
+
gsub!("\n (function() {\n var swf = \"", '').
|
40
|
+
gsub!("\";\n document.getElementById('watch-player').innerHTML = swf;\n })()\n ", '').
|
41
|
+
gsub!(/\\u[a-z0-9]{4}/) {|x| [x.chars.to_a[2..-1].join.to_i(16)].pack("U*")}.
|
42
|
+
gsub!('\\n', '\\').gsub!('\\', '')
|
43
|
+
embed = Nokogiri::HTML(js_fragment).css('embed')
|
44
|
+
#title = embed.to_json['title']
|
45
|
+
CGI::parse(embed.attr('flashvars').value)
|
46
|
+
end
|
47
|
+
|
48
|
+
def fetch_download_url
|
49
|
+
stream_map = flashvars['url_encoded_fmt_stream_map'].first
|
50
|
+
CGI::parse(stream_map)['url'].first
|
51
|
+
end
|
52
|
+
|
53
|
+
def fetch_title
|
54
|
+
flashvars['title'].first
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/youtube-ripper/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Maurizio De Magnis"]
|
6
|
+
gem.email = ["maurizio.demagnis@gmail.com"]
|
7
|
+
gem.description = %q{Download YouTube videos given their public URL.}
|
8
|
+
gem.summary = %q{
|
9
|
+
Use it as a standalone shell command or a Ruby library.
|
10
|
+
}
|
11
|
+
gem.homepage = "https://github.com/olistik/youtube-ripper"
|
12
|
+
|
13
|
+
gem.add_dependency('nokogiri', '~> 1.5.2')
|
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 = "youtube-ripper"
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.version = Youtube::Ripper::VERSION
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: youtube-ripper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Maurizio De Magnis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.5.2
|
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: 1.5.2
|
30
|
+
description: Download YouTube videos given their public URL.
|
31
|
+
email:
|
32
|
+
- maurizio.demagnis@gmail.com
|
33
|
+
executables:
|
34
|
+
- yt_ripper
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/yt_ripper
|
44
|
+
- lib/youtube-ripper.rb
|
45
|
+
- lib/youtube-ripper/downloader.rb
|
46
|
+
- lib/youtube-ripper/ripper.rb
|
47
|
+
- lib/youtube-ripper/version.rb
|
48
|
+
- youtube-ripper.gemspec
|
49
|
+
homepage: https://github.com/olistik/youtube-ripper
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.23
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Use it as a standalone shell command or a Ruby library.
|
73
|
+
test_files: []
|