getvideo 0.0.5 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a05caec5a828055c6ed17d483e8323240803f4f5
4
- data.tar.gz: 883ed8d880add6c2247534fd8a9e6db91a368c59
3
+ metadata.gz: 966b2b18dc31ed75dc68aa6be526dd4a007ccba9
4
+ data.tar.gz: 5d7a0212afab5c185fc3785009efa84cceca5ecf
5
5
  SHA512:
6
- metadata.gz: 23eba5aff34a41371bb27c58bd619ba5c1709f4f1936ca36d868b02b82d3074d31d7d47bea6c0fccb31c095908bfcc1f6f5d8753d3662ae15000b83239792de1
7
- data.tar.gz: d139dbbc2ebfe31e629fdbf10a4d30547734b2f1591d8a115941876326cd8f23e5a01625cdc5951eefd23b3cdf639e0874c825e0a608166e580c85e6de34c710
6
+ metadata.gz: cec3ea5db8dd89ad25834ec2288513f460d10ca327b884be0fdc8d9726e42d6f9f39d45f7b77d82d34849146a72e0f98fd98d09eae1e3b969d2be15a31dd493b
7
+ data.tar.gz: 8661946a3c84fe918f9643b2e84ef79042030ec7fc1df9024f247dbf6bb6f27c7e61418d44489ffda6ceb6f5311d74de50ebee2eb5e5d641ff06f99412538b96
data/README.md CHANGED
@@ -34,15 +34,16 @@ check faraday, multi_json, nokogiri gems installed
34
34
  require 'getvideo'
35
35
 
36
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
- ````
37
+ video.cover # 视频网站提供的截图或封面
38
+ video.id #视频的ID,用来在视频网站查询视频
39
+ video.html_url #视频的源url
40
+ video.title #视频的标题
41
+ video.media #获取视频内容 {"mp4" => "http://mp4 play url", "hlv" => "http://hlv"}
42
+ video.flash #视频flash格式
43
+ video.play_media #已获取视频内容,选取一条作为播放内容
44
+ video.json #以json格式显示
45
+ ```
46
+
46
47
  ## Contributing
47
48
 
48
49
  1. Fork it
@@ -53,4 +54,4 @@ check faraday, multi_json, nokogiri gems installed
53
54
 
54
55
  ## Thanks
55
56
 
56
- get more video you can access [you-get](https://github.com/soimort/you-get)
57
+ get more video you can access [you-get](https://github.com/soimort/you-get)
@@ -32,8 +32,10 @@ module Getvideo
32
32
  Ku6.new(url)
33
33
  elsif url =~ /youtube/
34
34
  Youtube.new(url)
35
- else url =~ /(iask|sina)/
35
+ elsif url =~ /(iask|sina)/
36
36
  Sina.new(url)
37
+ else
38
+ return false
37
39
  end
38
40
  end
39
41
  end
@@ -1,180 +1,94 @@
1
1
  #coding:utf-8
2
+ require 'digest/md5'
2
3
 
3
4
  module Getvideo
4
5
  class Sina < Video
5
- set_api_uri { "http://v.iask.com/v_play.php?vid=#{id}" }
6
+ set_api_uri do
7
+ rand = "0.#{rand(10000..10000000)}#{rand(10000..10000000)}"
8
+ "http://v.iask.com/v_play.php?vid=#{id}&ran=#{rand}&p=i&k=#{get_k(id, rand)}"
9
+ end
10
+
11
+ def ipad_response
12
+ @ipad_response ||= ipad_connection
13
+ end
6
14
 
7
15
  def initialize(url)
8
- @url = url
9
- set_id
16
+ super
17
+ parse_page if !(is_flash_url? || is_subject_url?)
10
18
  end
11
19
 
12
- def ipad_response
13
- @ipad_response ||= ipad_connect
20
+ def id
21
+ return url.match(/vid=(\d+)/).to_a[1] if is_flash_url?
22
+ return url.match(/#(\d+)/).to_a[1] if is_subject_url?
23
+ page.match(/vid[\s]*:[\s]*["|']?[\s]*(\d+)[\s]*["|']?/).to_a[1]
14
24
  end
15
25
 
16
- def info_response
17
- @info_response ||= Nokogiri::HTML(parse_html).css("head script").text.gsub(" ", "")
26
+ def cover
27
+ return "" if is_flash_url? || is_subject_url?
28
+ page.match(/pic[\s]*:[\s]*["|']?[\s]*([^'|"]+)?/).to_a[1]
18
29
  end
19
30
 
20
31
  def html_url
21
- if has_html?
22
- if url =~ /\.html$/
23
- url
24
- else
25
- "http://video.sina.com.cn/v/b/#{@id}-#{@uid}.html"
26
- end
27
- else
28
- ""
29
- end
32
+ return "" if is_flash_url?
33
+ url
30
34
  end
31
35
 
32
36
  def title
33
- if has_html?
34
- info_response.scan(/title:'([^']+)'/)[0][0]
35
- else
36
- response["vname"]
37
- end
38
- end
39
-
40
- def cover
41
- if has_html?
42
- pic = info_response.scan(/pic:'([^']+)'/)
43
- pic.empty? ? "" : pic[0][0]
44
- else
45
- ""
46
- end
37
+ response["video"]["vname"]
47
38
  end
48
39
 
49
40
  def flash
50
- if url =~ /\.swf/
51
- url
52
- else
53
- flash_url = info_response.scan(/swfOutsideUrl:'([^']+)'/)
54
- unless flash_url.empty?
55
- flash_url[0][0]
56
- else
57
- ""
58
- end
59
- end
41
+ return url if is_flash_url?
42
+ return "" if is_subject_url?
43
+ return "" if !page
44
+ page.match(/swfOutsideUrl[\s]*:[\s]*["|']?[\s]*([^'|"]+)/).to_a[1]
60
45
  end
61
46
 
62
47
  def m3u8
63
- if has_html?
64
- if !ipad_response.nil?
65
- media["mp4"][0]
66
- end
48
+ if !(is_flash_url? || is_subject_url?)
49
+ ipad_response["video"]["durl"]["url"]
67
50
  else
68
51
  ""
69
52
  end
70
53
  end
71
54
 
72
- def id
73
- @id
74
- end
75
-
76
55
  def media
77
- vedio_list = {}
78
- vedio_list["hlv"] = []
79
- vedio_list["mp4"] = []
80
- if res = response
81
- if res["video"]["result"] != "error"
82
- vedio_list["hlv"] << res["video"]["durl"]["url"]
83
- end
56
+ video_list = {}
57
+ if !(is_flash_url? || is_subject_url?)
58
+ video_list["mp4"] = []
59
+ video_list["mp4"] << ipad_response["video"]["durl"]["url"]
84
60
  end
85
-
86
- if m_res = ipad_response
87
- if m_res["video"]["result"] != "error"
88
- vedio_list["mp4"] << m_res["vdieo"]["durl"]["url"]
89
- end
90
- end
91
-
92
- return vedio_list
61
+ video_list["hlv"] = []
62
+ video_list["hlv"] << response["video"]["durl"]["url"]
63
+ return video_list
93
64
  end
94
65
 
95
66
  private
96
67
 
97
- def has_html?
98
- @uid =~ /[\d]{3,}?/ || (url =~ /\.html/)
99
- end
100
-
101
- def set_id
102
- if url =~ /\/v\/b\/([^\D]+)-([^\D]+)\.html/
103
- ids = url.scan(/\/v\/b\/([^\D]+)-([^\D]+)\.html/)[0]
104
- @id = ids[0]
105
- @uid = ids[1]
106
- elsif url =~ /\/playlist\/([^\D]+).*.#([^\D]+)/
107
- ids = url.scan(/\/playlist\/[^\D]+-([^\D]+).*#([^\D]+)/)[0]
108
- @id = ids[1]
109
- @uid = ids[0]
110
- elsif url =~ /\.swf/
111
- ids = url.scan(/vid=([^\D]+)_([^\D]+)_.+\.swf/)[0]
112
- @id = ids[0]
113
- @uid = ids[1]
114
- elsif url =~ /(\/[\S]?\/)/
115
- if url.index("#").nil?
116
- html = parse_html
117
- ids = html.scan(/vid[\s]?:[\s]?['|"]([^\D]+)['|"]/)[0]
118
- uids = html.scan(/uid[\s]?:[\s]?['|"]([^\D]+)['|"]/)[0]
119
- @id = ids[0]
120
- @uid = uids[0]
121
- else
122
- ids = url.scan(/(\/[\S]?\/).+#([^\D]+)/)[0]
123
- @id = ids[1]
124
- end
125
- else
126
- ids = url.split("|")
127
- @id = ids[0]
128
- @uid = ids[1]
129
- end
68
+ def ipad_connection
69
+ rand = "0.#{rand(10000..10000000)}#{rand(10000..10000000)}"
70
+ Response.new(Faraday.get("http://v.iask.com/v_play.php?vid=#{ipad_vid}&ran=#{rand}&p=i&k=#{get_k(ipad_vid, rand)}")).parsed
130
71
  end
131
72
 
132
- def ipad_id
133
- ipad_ids = info_response.scan(/videoData:{ipad_vid:[']?([^\D]+)[']?/)
134
- ipad_ids.empty? ? nil : ipad_ids[0][0]
73
+ def get_k(vid, rand)
74
+ t = Time.now.to_i.to_s(2)[0..-7].to_i(2)
75
+ Digest::MD5.hexdigest("#{vid.to_s}Z6prk18aWxP278cVAH#{t.to_s}#{rand.to_s}".encode('utf-8'))[0..15] + t.to_s
135
76
  end
136
77
 
137
- def ipad_connect
138
- conn = Faraday.new
139
- response = conn.get "http://v.iask.com/v_play.php?vid=#{ipad_id}"
140
- Response.new(response).parsed
78
+ def is_flash_url?
79
+ url =~ /\.swf/
141
80
  end
142
81
 
143
- def html_info_path
144
- if url =~ /\.html/
145
- if url.index("#")
146
- if url =~ /play_list/
147
- html_url
148
- else
149
- url
150
- end
151
- else
152
- url
153
- end
154
- elsif url =~ /\.swf/
155
- html_url
156
- else
157
- html_url
158
- end
82
+ def is_subject_url?
83
+ url =~ /#\d+/
159
84
  end
160
85
 
161
- def parse_html
162
- if !html_info_path.empty?
163
- conn = Faraday.new
164
- conn.get(html_info_path).body
165
- end
86
+ def parse_page
87
+ page_res = Faraday.get(url)
88
+ @page = page_res.body
89
+ @ipad_vid = page.match(/ipad_vid[\s]*:[\s]*["|']?[\s]*(\d+)[\s]*["|']?/).to_a[1]
166
90
  end
167
91
 
168
- def get_media(type=nil)
169
- if type == "mp4"
170
- if ipad_id
171
- uri = "http://v.iask.com/v_play.php?vid=#{ipad_id}"
172
- end
173
- else
174
- uri = "http://v.iask.com/v_play.php?vid=#{id}"
175
- end
176
- conn = Faraday.new
177
- return conn.get(uri).body
178
- end
92
+ attr_accessor :page, :ipad_vid
179
93
  end
180
94
  end
@@ -45,7 +45,11 @@ module Getvideo
45
45
 
46
46
  def cover
47
47
  if url_type == "albumplay" || url_type == "oplay"
48
- response["data"][0]["logo"]
48
+ if data = response["data"]
49
+ data[0]["logo"]
50
+ else
51
+ page_get_pic
52
+ end
49
53
  else
50
54
  page_get_pic
51
55
  end
@@ -253,11 +257,13 @@ module Getvideo
253
257
 
254
258
  def albumplay_media(type = nil)
255
259
  video_list = {}
256
- response["data"][0]["streamfileids"].each_key do |type|
257
- stream = parse_stream(type)
258
- video_list[type] = []
259
- segs(type).each do |s|
260
- video_list[type] << "http://f.youku.com/player/getFlvPath/sid/" + sid + "/st/#{type}/fileid/#{stream[0..8]+s["no"].to_i.to_s(16)+stream[10..-1]}_0#{s["no"].to_i.to_s(16)}?K="+s["k"] if s["k"] != -1
260
+ if data = response["data"]
261
+ data[0]["streamfileids"].each_key do |type|
262
+ stream = parse_stream(type)
263
+ video_list[type] = []
264
+ segs(type).each do |s|
265
+ video_list[type] << "http://f.youku.com/player/getFlvPath/sid/" + sid + "/st/#{type}/fileid/#{stream[0..8]+s["no"].to_i.to_s(16)+stream[10..-1]}_0#{s["no"].to_i.to_s(16)}?K="+s["k"] if s["k"] != -1
266
+ end
261
267
  end
262
268
  end
263
269
  return video_list
@@ -272,7 +278,9 @@ module Getvideo
272
278
  end
273
279
 
274
280
  def videoid
275
- response["data"][0]["videoid"]
281
+ if data = response["data"]
282
+ data[0]["videoid"]
283
+ end
276
284
  end
277
285
 
278
286
  def parse_stream(type)
@@ -1,3 +1,3 @@
1
1
  module Getvideo
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -17,11 +17,15 @@ module Getvideo
17
17
  end
18
18
 
19
19
  def title
20
- response["data"][0]["title"]
20
+ if data = response["data"]
21
+ data[0]["title"]
22
+ end
21
23
  end
22
24
 
23
25
  def cover
24
- response["data"][0]["logo"]
26
+ if data = response["data"]
27
+ data[0]["logo"]
28
+ end
25
29
  end
26
30
 
27
31
  def flash
@@ -34,11 +38,13 @@ module Getvideo
34
38
 
35
39
  def media(type = nil)
36
40
  video_list = {}
37
- response["data"][0]["streamfileids"].each_key do |type|
38
- stream = parse_stream(type)
39
- video_list[type] = []
40
- segs(type).each do |s|
41
- video_list[type] << "http://f.youku.com/player/getFlvPath/sid/" + sid + "/st/#{type}/fileid/#{stream[0..8]+s["no"].to_i.to_s(16)+stream[10..-1]}_0#{s["no"].to_i.to_s(16)}?K="+s["k"] if s["k"] != -1
41
+ if data = response["data"]
42
+ data[0]["streamfileids"].each_key do |type|
43
+ stream = parse_stream(type)
44
+ video_list[type] = []
45
+ segs(type).each do |s|
46
+ video_list[type] << "http://f.youku.com/player/getFlvPath/sid/" + sid + "/st/#{type}/fileid/#{stream[0..8]+s["no"].to_i.to_s(16)+stream[10..-1]}_0#{s["no"].to_i.to_s(16)}?K="+s["k"] if s["k"] != -1
47
+ end
42
48
  end
43
49
  end
44
50
  return video_list
@@ -55,7 +61,9 @@ module Getvideo
55
61
  end
56
62
 
57
63
  def videoid
58
- response["data"][0]["videoid"]
64
+ if data = response["data"]
65
+ data[0]["videoid"]
66
+ end
59
67
  end
60
68
 
61
69
  def parse_stream(type)
@@ -76,6 +84,7 @@ module Getvideo
76
84
  stream_fileids.split("*").each do |s|
77
85
  real_text = real_text + text.to_s[s.to_i]
78
86
  end
87
+
79
88
  return real_text
80
89
  end
81
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getvideo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ye.li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-27 00:00:00.000000000 Z
11
+ date: 2014-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday