youtube_video_info 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/youtube_video_info.rb +13 -0
- data/lib/youtube_video_info/request.rb +19 -0
- data/lib/youtube_video_info/response.rb +43 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b931cd6caa9c2e9670b6042f405170d87772a3ae
|
4
|
+
data.tar.gz: 679075ee2d256ac806b72cd4a6936a1a6b5adcb7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8dd13673432ef4b4333df6dcc3313294fa379b71cc7f99fbc9cf11603c99bdbfe28c0de57e7cac712d72c67b57eece6445471521cb7c07cc352bc6bdc1b4cc5
|
7
|
+
data.tar.gz: a24625e9e4e0237e21609b7f6f46506802eadae20bcd56c27c5160068605a9bd549ee98525f7557c66cc042297d3c0b362ca451d45beee19ce60ec4df1c9124c
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module YoutubeVideoInfo
|
2
|
+
require 'bundler'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'cgi'
|
6
|
+
require 'ostruct'
|
7
|
+
Bundler.require
|
8
|
+
require_relative 'youtube_video_info/request'
|
9
|
+
require_relative 'youtube_video_info/response'
|
10
|
+
def self.download url
|
11
|
+
Request.new(url, URI, Net::HTTP, Response, CGI).get
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module YoutubeVideoInfo
|
2
|
+
class Request
|
3
|
+
def initialize uri_string, uri_module, requester, response_class, cgi_module
|
4
|
+
@uri_module = uri_module
|
5
|
+
@uri = @uri_module.parse(uri_string)
|
6
|
+
@requester = requester
|
7
|
+
@response_class = response_class
|
8
|
+
@cgi_module = cgi_module
|
9
|
+
end
|
10
|
+
def id
|
11
|
+
@cgi_module.parse(@uri.query)['v'].first
|
12
|
+
end
|
13
|
+
def get
|
14
|
+
@response_class.new @requester.get(@uri_module.parse("http://www.youtube.com/get_video_info?video_id=#{id}&el=detailpage")), @cgi_module
|
15
|
+
rescue => e
|
16
|
+
raise self.class.const_set(e.class.to_s, Class.new(e.class)).new(e)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module YoutubeVideoInfo
|
2
|
+
class Response < OpenStruct
|
3
|
+
attr_accessor :raw_response
|
4
|
+
def initialize http_response, cgi_module
|
5
|
+
@cgi_module = cgi_module
|
6
|
+
super @cgi_module.parse(http_response)
|
7
|
+
end
|
8
|
+
def title
|
9
|
+
self['title'].first
|
10
|
+
end
|
11
|
+
def author
|
12
|
+
self['author'].first
|
13
|
+
end
|
14
|
+
def links
|
15
|
+
@cgi_module.parse(self['url_encoded_fmt_stream_map'].first)['url']
|
16
|
+
end
|
17
|
+
def links_by_itag
|
18
|
+
parsed_links = {}
|
19
|
+
list_of_links = links
|
20
|
+
list_of_links.each do |link|
|
21
|
+
parsed_link = @cgi_module.parse(link)
|
22
|
+
itag = parsed_link['itag'].first
|
23
|
+
parsed_links[itag] = link
|
24
|
+
end
|
25
|
+
parsed_links
|
26
|
+
end
|
27
|
+
def video_download_headers
|
28
|
+
# This is just for convenience.
|
29
|
+
# Many of these are here to make the request appear genuine.
|
30
|
+
{
|
31
|
+
"Connection" => "keep-alive",
|
32
|
+
"Origin" => "https://www.youtube.com",
|
33
|
+
"X-FirePHP-Version" => "0.0.6",
|
34
|
+
"User-Agent" => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.95 Safari/537.36",
|
35
|
+
"Accept" => "*/*",
|
36
|
+
"DNT" => "1",
|
37
|
+
"Referer" => "https://www.youtube.com/watch?v=#{video_id[0]}",
|
38
|
+
"Accept-Encoding" => "gzip, deflate, sdch",
|
39
|
+
"Accept-Language" => "en-US,en;q=0.8,de-DE;q=0.6,de;q=0.4"
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: youtube_video_info
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Titcomb
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Get info and download links from YouTube videos.
|
14
|
+
email: benjamin@pixelstreetinc.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/youtube_video_info.rb
|
20
|
+
- lib/youtube_video_info/request.rb
|
21
|
+
- lib/youtube_video_info/response.rb
|
22
|
+
homepage: http://github.com/ravenstine/youtube_video_info
|
23
|
+
licenses:
|
24
|
+
- Public Domain
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.1
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Get info and download links from YouTube videos.
|
46
|
+
test_files: []
|
47
|
+
has_rdoc:
|