niconico 1.0.0 → 1.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/lib/niconico.rb +1 -1
- data/lib/niconico/version.rb +1 -1
- data/lib/niconico/video.rb +12 -7
- metadata +2 -2
data/lib/niconico.rb
CHANGED
@@ -8,7 +8,7 @@ class Niconico
|
|
8
8
|
URL = {
|
9
9
|
login: 'https://secure.nicovideo.jp/secure/login?site=niconico',
|
10
10
|
watch: 'http://www.nicovideo.jp/watch/',
|
11
|
-
getflv: 'http://
|
11
|
+
getflv: 'http://flapi.nicovideo.jp/api/getflv'
|
12
12
|
}
|
13
13
|
|
14
14
|
TEST_VIDEO_ID = "sm9"
|
data/lib/niconico/version.rb
CHANGED
data/lib/niconico/video.rb
CHANGED
@@ -7,10 +7,10 @@ class Niconico
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class Video
|
10
|
-
|
11
|
-
|
10
|
+
DEFERRABLES = [:id, :title, :url, :video_url, :type]
|
11
|
+
DEFERRABLES_VAR = DEFERRABLES.map{|k| :"@#{k}" }
|
12
12
|
|
13
|
-
|
13
|
+
DEFERRABLES.zip(DEFERRABLES_VAR).each do |(k,i)|
|
14
14
|
define_method(k) do
|
15
15
|
instance_variable_get(i) || (get && instance_variable_get(i))
|
16
16
|
end
|
@@ -19,12 +19,12 @@ class Niconico
|
|
19
19
|
def initialize(parent, video_id, defer=nil)
|
20
20
|
@parent = parent
|
21
21
|
@agent = parent.agent
|
22
|
-
@id = video_id
|
22
|
+
@thread_id = @id = video_id
|
23
23
|
@url = "#{Niconico::URL[:watch]}#{@id}"
|
24
24
|
|
25
25
|
if defer
|
26
26
|
defer.each do |k,v|
|
27
|
-
next unless
|
27
|
+
next unless DEFERRABLES.include?(k)
|
28
28
|
instance_variable_set :"@#{k}", v
|
29
29
|
end
|
30
30
|
@page = nil
|
@@ -42,7 +42,12 @@ class Niconico
|
|
42
42
|
raise NotFound, "#{@id} not found" if e.message == "404 => Net::HTTPNotFound"
|
43
43
|
raise e
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
|
+
if /^so/ =~ @id
|
47
|
+
sleep 5
|
48
|
+
@thread_id = @agent.get("#{Niconico::URL[:watch]}#{@id}").uri.path.sub(/^\/watch\//,"")
|
49
|
+
end
|
50
|
+
getflv = Hash[@agent.get_file("#{Niconico::URL[:getflv]}?v=#{@thread_id}").scan(/([^&]+)=([^&]+)/).map{|(k,v)| [k.to_sym,CGI.unescape(v)] }]
|
46
51
|
|
47
52
|
@title = @page.at("#video_title").inner_text
|
48
53
|
@video_url = getflv[:url]
|
@@ -61,7 +66,7 @@ class Niconico
|
|
61
66
|
end
|
62
67
|
|
63
68
|
def get_video_by_other
|
64
|
-
{cookie: @agent.cookie_jar.cookies(URI.parse(@video_url))
|
69
|
+
{cookie: @agent.cookie_jar.cookies(URI.parse(@video_url)),
|
65
70
|
url: @video_url}
|
66
71
|
end
|
67
72
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niconico
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: wrapper of Mechanize, optimized for nicovideo. :)
|
15
15
|
email:
|