getvideo 0.0.4

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50e448a1b0d1171b5a43900fbcba5660059840bd
4
+ data.tar.gz: dd220588081b5a4d1fd99622d8d0640ec3bb5cce
5
+ SHA512:
6
+ metadata.gz: d2a288e9d6b9c38371c117d481c970bfaecbede33c96669ca4df1c2e4e292f12fe9c26f3dc157aee8c03ac9817e399ec4fd9c5c43f9181b4fae35ff6c47e0b96
7
+ data.tar.gz: e163fc082316b4ba6a4dcf75bd14425ad53d4b17afcd47568b46b2a84a3b23ce8a06d146ce308cdef65c4f6bd8d0f15b6fc3de79192e7ba92cfd84011ab8e3df
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
19
+ *.swo
20
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in getvideo.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+
8
+ gem 'colored'
9
+
10
+ group :development, :test do
11
+ gem 'guard-rspec'
12
+ gem 'nokogiri'
13
+ gem 'rb-fsevent'
14
+ gem 'terminal-notifier-guard'
15
+ end
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara request specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 ye.li
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.
@@ -0,0 +1,56 @@
1
+ # Getvideo
2
+
3
+ getvideo is parse video information on Ruby, you can get video media download url, cover, flash url and title.
4
+
5
+ ## Support Sites List
6
+
7
+ * Youtube [http://www.youtube.com/](http://www.youtube.com/)
8
+ * 优酷网 [http://www.youku.com/](http://www.youku.com/)
9
+ * 土豆网 [http://www.tudou.com/](http://www.tudou.com/)
10
+ * 56网 [http://www.56.com/](http://www.56.com/)
11
+ * 爱奇艺 [http://www.iqiyi.com/](http://www.iqiyi.com/)
12
+ * 搜狐视频 [http://tv.sohu.com/](http://tv.sohu.com/)
13
+ * 酷6网 [http://www.ku6.com/](http://www.ku6.com/)
14
+ * 新浪视频 [http://video.sina.com.cn/](http://video.sina.com.cn/)
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'getvideo'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as
27
+
28
+ $ gem install getvideo
29
+
30
+ ## Usage
31
+ check faraday, multi_json, nokogiri gems installed
32
+
33
+ ```
34
+ require 'getvideo'
35
+
36
+ video = Getvideo.parse "http://videourl.com/info"
37
+ video.cover
38
+ video.id
39
+ video.html_url
40
+ video.title
41
+ video.media #get all video url like {"mp4" => "http://mp4 play url", "hlv" => "http://hlv"}
42
+ video.flash
43
+ video.play_media # get mp4 video
44
+ video.json
45
+ ````
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
53
+
54
+ ## Thanks
55
+
56
+ get more video you can access [you-get](https://github.com/soimort/you-get)
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/getvideo/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "getvideo"
6
+ gem.license = 'MIT'
7
+ gem.authors = ["ye.li"]
8
+ gem.email = ["yeeli@outlook.com"]
9
+ gem.description = "get video"
10
+ gem.summary = "get video"
11
+ gem.homepage = ""
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.require_paths = ["lib"]
17
+ gem.version = Getvideo::VERSION
18
+ gem.add_dependency 'faraday'
19
+ gem.add_dependency 'multi_json'
20
+ gem.add_dependency 'nokogiri'
21
+ end
@@ -0,0 +1,38 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'cgi'
4
+ require 'json'
5
+ require 'nokogiri'
6
+ require 'multi_json'
7
+ require 'getvideo/video'
8
+ require "getvideo/version"
9
+ require "getvideo/youku"
10
+ require "getvideo/ku6"
11
+ require "getvideo/56"
12
+ require "getvideo/tudou"
13
+ require "getvideo/sohu"
14
+ require "getvideo/iqiyi"
15
+ require "getvideo/youtube"
16
+ require 'getvideo/iask'
17
+
18
+ module Getvideo
19
+ def self.parse(url)
20
+ if url =~ /youku/
21
+ Youku.new(url)
22
+ elsif url =~ /tudou/
23
+ Tudou.new(url)
24
+ elsif url =~ /iqiyi/
25
+ Iqiyi.new(url)
26
+ elsif url =~ /sohu/
27
+ Sohu.new(url)
28
+ elsif url =~ /56\.com/
29
+ Wole.new(url)
30
+ elsif url =~ /ku6/
31
+ Ku6.new(url)
32
+ elsif url =~ /youtube/
33
+ Youtube.new(url)
34
+ else url =~ /(iask|sina)/
35
+ Iask.new(url)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,60 @@
1
+ #coding:utf-8
2
+
3
+ module Getvideo
4
+ class Wole < Video
5
+ set_api_uri { "http://vxml.56.com/json/#{id}/?src=site" }
6
+
7
+ def html_url
8
+ if url =~ /v_([^.]+).html/
9
+ url
10
+ else
11
+ "http://www.56.com/u/v_#{id}.html"
12
+ end
13
+ end
14
+
15
+ def id
16
+ if url =~ /v_([^.]+).[html|swf]/
17
+ url.scan(/v_([^.]+)\.[html|swf]/)[0][0]
18
+ elsif url =~ /w.+\/play_album.+_vid-([^.]+)\.html/
19
+ ids = url.scan /w.+\/play_album.+_vid-([^.]+)\.html/
20
+ ids[0][0]
21
+ else
22
+ url
23
+ end
24
+ end
25
+
26
+ def cover
27
+ response["info"]["bimg"] if response
28
+ end
29
+
30
+ def title
31
+ response["info"]["Subject"] if response
32
+ end
33
+
34
+ def flash
35
+ "http://player.56.com/v_#{id}.swf"
36
+ end
37
+
38
+ def m3u8
39
+ "http://vxml.56.com/m3u8/#{response["info"]["vid"]}/" if response
40
+ end
41
+
42
+ def media
43
+ video_list = {}
44
+ response["info"]["rfiles"].each do |f|
45
+ f_type = f["url"].scan(/\.(flv|mp4|m3u8)\?/)[0][0]
46
+ if video_list[f_type].nil?
47
+ video_list[f_type] = []
48
+ video_list[f_type] << f["url"]
49
+ else
50
+ video_list[f_type] << f["url"]
51
+ end
52
+ end
53
+ return video_list
54
+ end
55
+
56
+ def play_media
57
+ media["mp4"][0] if media["mp4"]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,173 @@
1
+ #coding:utf-8
2
+
3
+ module Getvideo
4
+ class Iask < Video
5
+ set_api_uri { "http://v.iask.com/v_play.php?vid=#{id}" }
6
+ attr_reader :ipad_response, :info_response
7
+
8
+ def initialize(url)
9
+ @url = url
10
+ set_id()
11
+ connection
12
+ if has_html?
13
+ @info_response = Nokogiri::HTML(parse_html).css("head script").text.gsub(" ", "")
14
+ ipad_connect if ipad_id
15
+ end
16
+ end
17
+
18
+ def html_url
19
+ if has_html?
20
+ if url =~ /\.html$/
21
+ url
22
+ else
23
+ "http://video.sina.com.cn/v/b/#{@id}-#{@uid}.html"
24
+ end
25
+ else
26
+ ""
27
+ end
28
+ end
29
+
30
+ def title
31
+ if has_html?
32
+ info_response.scan(/title:'([^']+)'/)[0][0]
33
+ else
34
+ response.css("vname").text
35
+ end
36
+ end
37
+
38
+ def cover
39
+ if has_html?
40
+ pic = info_response.scan(/pic:'([^']+)'/)
41
+ pic.empty? ? "" : pic[0][0]
42
+ else
43
+ ""
44
+ end
45
+ end
46
+
47
+ def flash
48
+ if url =~ /\.swf/
49
+ url
50
+ else
51
+ flash_url = info_response.scan(/swfOutsideUrl:'([^']+)'/)
52
+ unless flash_url.empty?
53
+ flash_url[0][0]
54
+ else
55
+ ""
56
+ end
57
+ end
58
+ end
59
+
60
+ def m3u8
61
+ if has_html?
62
+ ipad_response.nil? ? "" : media["mp4"][0]
63
+ else
64
+ ""
65
+ end
66
+ end
67
+
68
+ def id
69
+ @id
70
+ end
71
+
72
+ def media
73
+ vedio_list = {}
74
+ vedio_list["hlv"] = []
75
+
76
+ response.css("url").each do |d|
77
+ vedio_list["hlv"] << d.text
78
+ end
79
+
80
+ if ipad_response
81
+ vedio_list["mp4"] = []
82
+ ipad_response.css("url").each do |d|
83
+ vedio_list["mp4"] << d.text
84
+ end
85
+ end
86
+
87
+ return vedio_list
88
+ end
89
+
90
+ private
91
+
92
+ def has_html?
93
+ @uid =~ /[\d]{3,}?/ || (url =~ /\.html/)
94
+ end
95
+
96
+ def set_id
97
+ if url =~ /\/v\/b\/([^\D]+)-([^\D]+)\.html/
98
+ ids = url.scan(/\/v\/b\/([^\D]+)-([^\D]+)\.html/)[0]
99
+ @id = ids[0]
100
+ @uid = ids[1]
101
+ elsif url =~ /\/playlist\/([^\D]+).*.#([^\D]+)/
102
+ ids = url.scan(/\/playlist\/[^\D]+-([^\D]+).*#([^\D]+)/)[0]
103
+ @id = ids[1]
104
+ @uid = ids[0]
105
+ elsif url =~ /\.swf/
106
+ ids = url.scan(/vid=([^\D]+)_([^\D]+)_.+\.swf/)[0]
107
+ @id = ids[0]
108
+ @uid = ids[1]
109
+ elsif url =~ /(\/[\S]?\/)/
110
+ if url.index("#").nil?
111
+ html = parse_html
112
+ ids = html.scan(/vid[\s]?:[\s]?['|"]([^\D]+)['|"]/)[0]
113
+ uids = html.scan(/uid[\s]?:[\s]?['|"]([^\D]+)['|"]/)[0]
114
+ @id = ids[0]
115
+ @uid = uids[0]
116
+ else
117
+ ids = url.scan(/(\/[\S]?\/).+#([^\D]+)/)[0]
118
+ @id = ids[1]
119
+ end
120
+ else
121
+ ids = url.split("|")
122
+ @id = ids[0]
123
+ @uid = ids[1]
124
+ end
125
+ end
126
+
127
+ def ipad_id
128
+ ipad_ids = info_response.scan(/videoData:{ipad_vid:[']?([^\D]+)[']?/)
129
+ ipad_ids.empty? ? nil : ipad_ids[0][0]
130
+ end
131
+
132
+ def ipad_connect
133
+ conn = Faraday.new
134
+ response = conn.get "http://v.iask.com/v_play.php?vid=#{ipad_id}"
135
+ @ipad_response = Response.new(response).parsed
136
+ end
137
+
138
+ def html_info_path
139
+ if url =~ /\.html/
140
+ if url.index("#")
141
+ if url =~ /play_list/
142
+ html_url
143
+ else
144
+ url
145
+ end
146
+ else
147
+ url
148
+ end
149
+ elsif url =~ /\.swf/
150
+ html_url
151
+ else
152
+ html_url
153
+ end
154
+ end
155
+
156
+ def parse_html()
157
+ conn = Faraday.new
158
+ conn.get(html_info_path).body
159
+ end
160
+
161
+ def get_media(type=nil)
162
+ if type == "mp4"
163
+ if ipad_id
164
+ uri = "http://v.iask.com/v_play.php?vid=#{ipad_id}"
165
+ end
166
+ else
167
+ uri = "http://v.iask.com/v_play.php?vid=#{id}"
168
+ end
169
+ conn = Faraday.new
170
+ return conn.get(uri).body
171
+ end
172
+ end
173
+ end