getvideo 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ #coding:utf-8
2
+
3
+ module Getvideo
4
+ class Youku < Video
5
+ set_api_uri { "http://v.youku.com/player/getPlayList/VideoIDS/" + id }
6
+
7
+ def id
8
+ if url =~ /\.html/
9
+ url.scan(/id_([^.]+)/)[0][0]
10
+ elsif url =~ /\.swf/
11
+ url.scan(/sid\/([^\/]+)\/v.swf/)[0][0]
12
+ end
13
+ end
14
+
15
+ def html_url
16
+ "http://v.youku.com/v_show/id_#{id}.html"
17
+ end
18
+
19
+ def title
20
+ response["data"][0]["title"]
21
+ end
22
+
23
+ def cover
24
+ response["data"][0]["logo"]
25
+ end
26
+
27
+ def flash
28
+ "http://player.youku.com/player.php/sid/#{id}/v.swf"
29
+ end
30
+
31
+ def m3u8
32
+ "http://v.youku.com/player/getM3U8/vid/#{videoid}/type/flv/ts/v.m3u8"
33
+ end
34
+
35
+ def media(type = nil)
36
+ 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
42
+ end
43
+ end
44
+ return video_list
45
+ end
46
+
47
+ private
48
+
49
+ def sid
50
+ Time.now.to_i.to_s + rand(10..99).to_s+ "1000" + rand(30..80).to_s+"00"
51
+ end
52
+
53
+ def segs(type)
54
+ response["data"][0]["segs"][type]
55
+ end
56
+
57
+ def videoid
58
+ response["data"][0]["videoid"]
59
+ end
60
+
61
+ def parse_stream(type)
62
+ seed = response["data"][0]["seed"]
63
+ stream_fileids = response["data"][0]["streamfileids"][type]
64
+ random_text = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\:._-1234567890'
65
+
66
+ text = ""
67
+ random_text.each_char do |t|
68
+ seed = (seed * 211 + 30031) % 65536
69
+ cuch = ((seed / 65536.0) * random_text.length).to_i
70
+ char = random_text[cuch]
71
+ text = text + char
72
+ random_text = random_text.gsub(char, "")
73
+ end
74
+
75
+ real_text = ""
76
+ stream_fileids.split("*").each do |s|
77
+ real_text = real_text + text.to_s[s.to_i]
78
+ end
79
+ return real_text
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,65 @@
1
+ #coding:utf-8
2
+
3
+ module Getvideo
4
+ class Youtube < Video
5
+
6
+ def html_url
7
+ if url =~ /(?:v=|youtu\.be\/)/
8
+ url
9
+ else
10
+ "http://www.youtube.com/watch?v=" + id
11
+ end
12
+ end
13
+
14
+ def id
15
+ if url =~ /(?:v=|youtu\.be\/|youtube\.com\/v\/)([^.|&]+)/
16
+ url.scan(/(?:v=|youtu\.be\/|youtube\.com\/v\/)([^.|&]+)/)[0][0]
17
+ else
18
+ url
19
+ end
20
+ end
21
+
22
+ def cover
23
+ CGI::unescape(response.scan(/thumbnail_url=([^&]+)/)[0][0]).gsub("default.jpg","")+"0.jpg"
24
+ end
25
+
26
+ def flash
27
+ "http://www.youtube.com/v/#{id}"
28
+ end
29
+
30
+ def m3u8
31
+ media["mp4"][0]
32
+ end
33
+
34
+ def media
35
+ stream = CGI::unescape(response.scan(/url_encoded_fmt_stream_map=([^&]+)/)[0][0])
36
+ media = stream.scan(/url=([^&]+)/)
37
+ sig = stream.scan(/sig=([^&]+)/)
38
+ type = stream.scan(/type=([^&]+)/)
39
+ vedio_list = {}
40
+ media.zip(sig, type).each do |m|
41
+ m_type = m[2][0].match(/(flv|mp4|webm|3gp)/)[0]
42
+ u = CGI::unescape(m[0][0])+ "&signature=" + m[1][0]
43
+ if vedio_list[m_type].nil?
44
+ vedio_list[m_type] = []
45
+ vedio_list[m_type] << u
46
+ else
47
+ vedio_list[m_type] << u
48
+ end
49
+ end
50
+ return vedio_list
51
+ end
52
+
53
+ def title
54
+ CGI::unescape response.scan(/title=([^&]+)/)[0][0]
55
+ end
56
+
57
+ private
58
+
59
+ def connection
60
+ conn = Faraday.new
61
+ res = conn.post "http://www.youtube.com/get_video_info", { "video_id" => id }
62
+ @response = Response.new(res).body
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Getvideo::Wole do
4
+ let(:wole){ Getvideo::Wole.new("http://www.56.com/u97/v_NzIzOTUxMzQ.html") }
5
+ let(:wole_album) { Getvideo::Wole.new "http://www.56.com/w83/play_album-aid-10272986_vid-NzYxMTk0Nzg.html"}
6
+ let(:wole_swf){ Getvideo::Wole.new("http://player.56.com/v_NzIzOTUxMzQ.swf")}
7
+ let(:wole_id){ Getvideo::Wole.new("NzIzOTUxMzQ")}
8
+
9
+ describe "#html_url" do
10
+ context "when html url" do
11
+ it{ wole.html_url.should == "http://www.56.com/u97/v_NzIzOTUxMzQ.html" }
12
+ end
13
+
14
+ context "when swf url" do
15
+ it "should return url" do
16
+ wole_swf.html_url.should == "http://www.56.com/u/v_NzIzOTUxMzQ.html"
17
+ wole_id.html_url.should == "http://www.56.com/u/v_NzIzOTUxMzQ.html"
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#id" do
23
+ it "shold return url" do
24
+ wole.id.should == "NzIzOTUxMzQ"
25
+ wole_album.id.should == "NzYxMTk0Nzg"
26
+ wole_swf.id.should == "NzIzOTUxMzQ"
27
+ wole_id.id.should == "NzIzOTUxMzQ"
28
+ end
29
+ end
30
+
31
+ describe "#title" do
32
+ it{ wole.title.should match(/20120906/) }
33
+ end
34
+
35
+ describe "#cover" do
36
+ it{ wole.cover.should match(/v19.56img.com/) }
37
+ end
38
+
39
+ describe "#flash" do
40
+ it{ wole.flash.should == "http://player.56.com/v_NzIzOTUxMzQ.swf" }
41
+ end
42
+
43
+ describe "#media" do
44
+ it{ wole.media["flv"].count.should be(3) }
45
+ end
46
+
47
+ describe "#m3u8" do
48
+ it{ wole.m3u8.should == "http://vxml.56.com/m3u8/72395134/" }
49
+ end
50
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Getvideo do
4
+ context "when is youku url" do
5
+ it "should get youku video infomation" do
6
+ end
7
+ end
8
+
9
+ context "when is tudou url" do
10
+ it "should get tudou infomation" do
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,128 @@
1
+ #coding:utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Getvideo::Iask do
5
+ let(:iask){ Getvideo::Iask.new "http://video.sina.com.cn/v/b/87948161-2162799562.html" }
6
+ let(:iask_swf){ Getvideo::Iask.new "http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=87948161_2162799562_PE+1GCBtBjbK+l1lHz2stqkP7KQNt6nniGy2vFutIAhbQ0/XM5GRZdQD6CjQAdkEqDhATJ82cfYn0Rw/s.swf" }
7
+ let(:iask_id){ Getvideo::Iask.new "87948161|2162799562" }
8
+ let(:iask_noflash){ Getvideo::Iask.new "http://video.sina.com.cn/m/xbfmnz_61889719.html" }
9
+
10
+
11
+ describe "#id" do
12
+ it "should return true id" do
13
+ iask.id.should == "87948161"
14
+ iask_swf.id.should == "87948161"
15
+ iask_id.id.should == "87948161"
16
+ end
17
+ end
18
+
19
+ describe "#html_url" do
20
+ it "should return html url" do
21
+ iask_swf.html_url.should == "http://video.sina.com.cn/v/b/87948161-2162799562.html"
22
+ iask_id.html_url.should == "http://video.sina.com.cn/v/b/87948161-2162799562.html"
23
+ end
24
+ end
25
+
26
+ describe "#flash" do
27
+ it "should return flash url" do
28
+ iask.flash.should == "http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=87948161_2162799562_aEPhGCo5BjTK+l1lHz2stqlF+6xCpv2xhGi1vVCjLAdcUw6YJMXNb9UA6S3eAclD5yoUEJU3cvci3xwraQ/s.swf"
29
+ iask_noflash.flash.should be_empty()
30
+ end
31
+ end
32
+
33
+ describe "#title" do
34
+ it "should return title text" do
35
+ iask.title.should match(/1080p/)
36
+ end
37
+ end
38
+
39
+ describe "#cover" do
40
+ it "should return cover url" do
41
+ iask.cover.should match(/\.jpg/)
42
+ end
43
+ end
44
+
45
+ describe "#media" do
46
+ it "should return media data" do
47
+ iask.media["hlv"][0].should match(/edge\.v\.iask.com.+\.hlv/)
48
+ iask_swf.media["hlv"][0].should match(/edge\.v\.iask.com.+\.hlv/)
49
+ iask_id.media["hlv"][0].should match(/edge\.v\.iask.com.+\.hlv/)
50
+ end
51
+ end
52
+
53
+ context "when url is play_list" do
54
+ let(:iask_p){ Getvideo::Iask.new "http://video.sina.com.cn/playlist/5204279-2214257545-1.html#68348849" }
55
+ let(:iask_p2){ Getvideo::Iask.new "http://video.sina.com.cn/playlist/4077594-1549077107-2.html" }
56
+ let(:iask_p_swf){ Getvideo::Iask.new "http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=68348849_2214257545_aR69SnA+C2DK+l1lHz2stqkP7KQNt6nni2uwuVejIApcQ0/XM5Gfat4D6CHSCdkEqDhAQpA8cfYu0xQ/s.swf" }
57
+
58
+ describe "#id" do
59
+ it "should return true id" do
60
+ iask_p.id.should == "68348849"
61
+ iask_p2.id.should match(/[\d]+/)
62
+ iask_p_swf.id.should == "68348849"
63
+ end
64
+ end
65
+
66
+ describe "#html_url" do
67
+ it "should return html url" do
68
+ iask_p_swf.html_url.should == "http://video.sina.com.cn/v/b/68348849-2214257545.html"
69
+ end
70
+ end
71
+
72
+ describe "#media" do
73
+ it "should return media data" do
74
+ iask_p.media["hlv"][0].should match(/\.hlv/)
75
+ iask_p_swf.media["hlv"][0].should match(/\.hlv/)
76
+ end
77
+ end
78
+
79
+
80
+ end
81
+
82
+
83
+ context "when url is news" do
84
+ let(:iask_n){ Getvideo::Iask.new "http://video.sina.com.cn/p/news/c/v/2012-10-21/101961889769.html" }
85
+ #let(:iask_n){ Getvideo::Iask.new "http://news.sina.com.cn/z/video/rbgd2012/#88208237_6" }
86
+ let(:iask_n_id){ Getvideo::Iask.new "http://video.sina.com.cn/p/news/c/v/2012-10-21/101961889769.html#61889105" }
87
+ let(:iask_n_swf){ Getvideo::Iask.new "http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=88279853_1_bEO9GyM9DWfK+l1lHz2stqkM7KQNt6nknynt71+iJAZRXAuIborfO4kK6CHUB8ZK9G8/s.swf" }
88
+
89
+ describe "#id" do
90
+ it "should return true id" do
91
+ iask_n.id.should == "88279853"
92
+ iask_n_id.id.should == "61889105"
93
+ iask_n_swf.id.should == "88279853"
94
+ end
95
+ end
96
+
97
+ describe "#html_url" do
98
+ it "should return html url" do
99
+ iask_n_swf.html_url.should be_empty
100
+ end
101
+ end
102
+
103
+ describe "#media" do
104
+ it "should return media data" do
105
+ iask_n.media["hlv"][0].should match(/\.hlv/)
106
+ iask_n_swf.media["hlv"][0].should match(/\.hlv/)
107
+ end
108
+ end
109
+
110
+ describe "#cover" do
111
+ it "should return cover url" do
112
+ iask_n_swf.cover.should be_empty
113
+ end
114
+ end
115
+
116
+ describe "#title" do
117
+ it "should return title" do
118
+ iask_n_swf.title.should match(/美航母/)
119
+ end
120
+ end
121
+
122
+ describe "#m3u8" do
123
+ it "should return m3u8" do
124
+ iask_n_swf.m3u8.should be_empty
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,42 @@
1
+ #coding:utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Getvideo::Iqiyi do
5
+ let(:iqiyi){ Getvideo::Iqiyi.new("http://www.iqiyi.com/weidianying/20120925/f15221a897037d07.html")}
6
+
7
+ let(:iqiyi_swf){ Getvideo::Iqiyi.new("http://player.video.qiyi.com/38c130b7b4124b1e902161e8e377324b/0/649/weidianying/20120925/f15221a897037d07.swf-pid=47084-ptype=2-albumId=233012-tvId=280286")}
8
+
9
+ let(:iqiyi_id){ Getvideo::Iqiyi.new("38c130b7b4124b1e902161e8e377324b")}
10
+
11
+ describe "#id" do
12
+ it "should return id" do
13
+ iqiyi.id.should == "38c130b7b4124b1e902161e8e377324b"
14
+ iqiyi_swf.id.should == "38c130b7b4124b1e902161e8e377324b"
15
+ iqiyi_id.id.should == "38c130b7b4124b1e902161e8e377324b"
16
+ end
17
+ end
18
+
19
+ describe "#url" do
20
+ it{iqiyi.html_url.should eq("http://www.iqiyi.com/weidianying/20120925/f15221a897037d07.html")}
21
+ end
22
+
23
+ describe "#title" do
24
+ it{ iqiyi.title.should match(/网络/)}
25
+ end
26
+
27
+ describe "#m3u8" do
28
+ it{ iqiyi.m3u8.should == "http://meta.video.qiyi.com/161/2d67f7aa72fe95ee65d36ca7ceabb69e.m3u8" }
29
+ end
30
+
31
+ describe "#flash" do
32
+ it{ iqiyi.flash.should == "http://player.video.qiyi.com/38c130b7b4124b1e902161e8e377324b/0/649/weidianying/20120925/f15221a897037d07.swf" }
33
+ end
34
+
35
+ describe "#media" do
36
+ it{ iqiyi.media["mp4"].count.should be(1) }
37
+ end
38
+
39
+ describe "#cover" do
40
+ it{ iqiyi.cover.should =~ /qiyipic\.com/ }
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Getvideo::Ku6 do
4
+ let(:ku6){ Getvideo::Ku6.new("http://v.ku6.com/special/show_6584838/7qc3x3fB98cPpTD509x1OQ...html") }
5
+ let(:ku6_swf){ Getvideo::Ku6.new("http://player.ku6.com/refer/7qc3x3fB98cPpTD509x1OQ../v.swf") }
6
+ let(:ku6_id){ Getvideo::Ku6.new("7qc3x3fB98cPpTD509x1OQ..") }
7
+
8
+ describe "#id" do
9
+ it "shouw return id" do
10
+ ku6.id.should == "7qc3x3fB98cPpTD509x1OQ.."
11
+ ku6_swf.id.should == "7qc3x3fB98cPpTD509x1OQ.."
12
+ ku6_id.id.should == "7qc3x3fB98cPpTD509x1OQ.."
13
+ end
14
+ end
15
+
16
+ describe "#title" do
17
+ it{ ku6.title.should match(/MV/)}
18
+ end
19
+
20
+ describe "#html_url" do
21
+ it "should return url" do
22
+ ku6.html_url.should == "http://v.ku6.com/special/show_6584838/7qc3x3fB98cPpTD509x1OQ...html"
23
+ ku6_swf.html_url.should == "http://v.ku6.com/show/7qc3x3fB98cPpTD509x1OQ...html"
24
+ ku6_swf.html_url.should == "http://v.ku6.com/show/7qc3x3fB98cPpTD509x1OQ...html"
25
+ end
26
+ end
27
+
28
+ describe "#cover" do
29
+ it{ ku6.cover.should =~ /ku6img\.com/ }
30
+ end
31
+
32
+ describe "#flash" do
33
+ it{ ku6.flash.should == "http://player.ku6.com/refer/7qc3x3fB98cPpTD509x1OQ../v.swf" }
34
+ end
35
+
36
+ describe "#media" do
37
+ it{ ku6.media["f4v"].count.should equal(1) }
38
+ end
39
+ end
@@ -0,0 +1,62 @@
1
+ #coding:utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Getvideo::Sohu do
5
+ let(:sohu){ Getvideo::Sohu.new("http://tv.sohu.com/20120111/n331887864.shtml") }
6
+ let(:sohu_swf){ Getvideo::Sohu.new("http://share.vrs.sohu.com/549836/v.swf&autoplay=false&xuid=") }
7
+ let(:sohu_id){ Getvideo::Sohu.new("549836") }
8
+ #let(:sohu_my){ Getvideo::Sohu.new("http://my.tv.sohu.com/u/pw/5085302_1_3") }
9
+ let(:sohu_my){ Getvideo::Sohu.new("http://my.tv.sohu.com/pl/5085302/28323085.shtml") }
10
+ #let(:sohu_my_u){ Getvideo::Sohu.new("http://my.tv.sohu.com/u/vw/32845325") }
11
+ let(:sohu_my_u){ Getvideo::Sohu.new("http://my.tv.sohu.com/us/6562328/32845325.shtml") }
12
+ let(:sohu_user_detail){ Getvideo::Sohu.new("http://my.tv.sohu.com/user/detail/90962205.shtml?pvid=22d90f5ff2caa66f")}
13
+ let(:sohu_my_swf){ Getvideo::Sohu.new("http://share.vrs.sohu.com/my/v.swf&autoplay=false&id=32427841&skinNum=1&topBar=1&xuid=") }
14
+ let(:sohu_my_id){ Getvideo::Sohu.new("32427841|my") }
15
+
16
+ describe "#id" do
17
+ context "when is tv.sohu.com" do
18
+ it "should return id" do
19
+ sohu.id.should == "549836"
20
+ sohu_swf.id.should == "549836"
21
+ sohu_id.id.should == "549836"
22
+ end
23
+ end
24
+
25
+ context "when is my.tv.sohu.com" do
26
+ it "should return id" do
27
+ sohu_my.id.should == "28323085"
28
+ sohu_my_u.id.should == "32845325"
29
+ sohu_my_swf.id.should == "32427841"
30
+ sohu_my_id.id.should == "32427841"
31
+ sohu_user_detail.id.should == "59344870"
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#html_url" do
37
+ it{sohu.html_url.should == "http://tv.sohu.com/20120111/n331887864.shtml"}
38
+ end
39
+
40
+ describe "title" do
41
+ it{ sohu.title.should match(/怒火/)}
42
+ end
43
+
44
+ describe "#cover" do
45
+ it{ sohu.cover.should match(/photocdn\.sohu\.com/) }
46
+ end
47
+
48
+ describe "#flash" do
49
+ it "should return falsh" do
50
+ sohu.flash.should == "http://share.vrs.sohu.com/549836/v.swf&autoplay=false"
51
+ sohu_my.flash.should == "http://share.vrs.sohu.com/my/v.swf&topBar=1&id=28323085&autoplay=false"
52
+ end
53
+ end
54
+
55
+ describe "m3u8" do
56
+ it{ sohu.m3u8.should == "http://hot.vrs.sohu.com/ipad549836.m3u8" }
57
+ end
58
+
59
+ describe "#media" do
60
+ it{ sohu.media["mp4"].count.should be(20) }
61
+ end
62
+ end