nicovideo 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.txt CHANGED
@@ -15,7 +15,7 @@ See sample/nv_download.rb
15
15
 
16
16
  == Author
17
17
 
18
- - emergent ( http://d.hatena.ne.jp/emergent )
18
+ - Satoshi Yoshikawa / emergent ( http://d.hatena.ne.jp/emergent )
19
19
  - thanks for many bloggers who wrote scraping scripts
20
20
 
21
21
  == License
data/Rakefile CHANGED
@@ -1,4 +1,24 @@
1
- require 'config/requirements'
2
- require 'config/hoe' # setup Hoe + all gem configuration
3
-
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ require 'rake/contrib/rubyforgepublisher'
5
+
6
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
7
+
8
+ Rake::RDocTask.new do |rdoc|
9
+ rdoc.rdoc_dir = 'html'
10
+ rdoc.options += RDOC_OPTS
11
+ rdoc.template = "#{ENV['template']}.rb" if ENV['template']
12
+ if ENV['DOC_FILES']
13
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
14
+ else
15
+ rdoc.rdoc_files.include('README.txt', 'ChangeLog')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+ end
19
+
20
+ desc "Publish to RubyForge"
21
+ task :rubyforge => [:rdoc, :package] do
22
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'emergent').upload
23
+ end
24
+
@@ -11,6 +11,8 @@ require 'nicovideo/openlist'
11
11
  require 'nicovideo/search'
12
12
  require 'nicovideo/tagsearch'
13
13
  require 'nicovideo/ranking'
14
+ require 'nicovideo/random'
15
+ require 'nicovideo/newarrival'
14
16
  #require 'nicovideo/tags'
15
17
  #require 'nicovideo/ichiba'
16
18
  #require 'nicovideo/feed'
@@ -104,6 +104,14 @@ module Nicovideo
104
104
  def openlist(video_id)
105
105
  OpenList.new(@agent, video_id)
106
106
  end
107
+
108
+ def random()
109
+ Random.new(@agent)
110
+ end
111
+
112
+ def newarrival(pagenum=1)
113
+ Newarrival.new(@agent,pagenum)
114
+ end
107
115
 
108
116
  # type : 'mylist', 'view' or 'res'
109
117
  # span : 'daily', 'newarrival', 'weekly', 'monthly', 'total'
@@ -0,0 +1,34 @@
1
+ module Nicovideo
2
+ class Newarrival < Page
3
+ include Enumerable
4
+
5
+ def initialize(agent, pagenum)
6
+ super(agent)
7
+
8
+ @pagenum = pagenum > 10 ? 10 : pagenum
9
+
10
+ params = ["videos"]
11
+ self.register_getter params
12
+
13
+ @url = url()
14
+ end
15
+
16
+ def parse(page)
17
+ result_xpath = page/'//div[@class="cmn_thumb_R"]//p[@class="TXT12"]/a[@class="video"]'
18
+ @videos = result_xpath.inject([]) do |arr, v|
19
+ vp = VideoPage.new(@agent, v.attributes['href'].sub(/watch\/(\w+)$/,'\1'))
20
+ vp.title = v.inner_html
21
+ arr << vp
22
+ end
23
+ end
24
+
25
+ def each
26
+ self.videos.each {|v| yield v }
27
+ end
28
+
29
+ def url
30
+ opt = '?page=' + @pagenum.to_s if @pagenum
31
+ "#{BASE_URL}/newarrival#{opt}"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ module Nicovideo
2
+ class Random < Page
3
+ include Enumerable
4
+
5
+ def initialize agent
6
+ super(agent)
7
+ @url = url()
8
+ self.register_getter ["videos"]
9
+ end
10
+
11
+ def each
12
+ self.videos.each {|v| yield v }
13
+ end
14
+
15
+ def url
16
+ "#{BASE_URL}/random"
17
+ end
18
+
19
+ def to_a
20
+ videos()
21
+ end
22
+
23
+ def reload
24
+ end
25
+
26
+ protected
27
+ def parse(page)
28
+ result_xpath = page/'//td[@class="random_td"]//p[@class="TXT12"]/a[@class="video"]'
29
+ @videos = result_xpath.inject([]) {|arr,v| #
30
+ #puts v.attributes['href']
31
+ vp = VideoPage.new(@agent, v.attributes['href'].sub(/watch\/(\w+)$/,'\1'))
32
+ vp.title = v.inner_html
33
+ arr << vp
34
+ }
35
+ end
36
+
37
+ end
38
+ end
@@ -2,7 +2,7 @@ module Nicovideo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -15,6 +15,20 @@ module Nicovideo
15
15
 
16
16
  def id() @video_id end
17
17
 
18
+ def type
19
+ @params ||= get_params
20
+ pattern = %r!^http://.*\.nicovideo\.jp/smile\?(.*?)=.*$!
21
+ CGI.unescape(@params['url']) =~ pattern
22
+ case $1
23
+ when 'm'
24
+ return 'mp4'
25
+ when 's'
26
+ return 'swf'
27
+ else
28
+ return 'flv'
29
+ end
30
+ end
31
+
18
32
  def comments(num=500)
19
33
  puts_info 'getting comment xml : id = ' + @video_id
20
34
  begin
@@ -35,7 +35,7 @@ class TestNicovideoMyList < Test::Unit::TestCase
35
35
  ml.title = "test"
36
36
  assert_equal("test", ml.title)
37
37
 
38
- sleep 1
38
+ sleep 5
39
39
  end
40
40
 
41
41
  def test_mylist_invalid
@@ -51,7 +51,7 @@ class TestNicovideoMyList < Test::Unit::TestCase
51
51
  assert_raise(Nicovideo::NotFound) { ml.description }
52
52
  assert_raise(Nicovideo::NotFound) { ml.videos }
53
53
 
54
- sleep 1
54
+ sleep 5
55
55
  end
56
56
 
57
57
  def test_mylist_notopened
@@ -67,6 +67,6 @@ class TestNicovideoMyList < Test::Unit::TestCase
67
67
  assert_raise(Nicovideo::Forbidden) { ml.description }
68
68
  assert_raise(Nicovideo::Forbidden) { ml.videos }
69
69
 
70
- sleep 1
70
+ sleep 5
71
71
  end
72
72
  end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoNewarrival < Test::Unit::TestCase
4
+
5
+ def setup
6
+ account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
7
+ @nv = Nicovideo.new(account['mail'], account['password'])
8
+ @nv.login
9
+ end
10
+
11
+ def test_ranking_valid
12
+ rv = nil
13
+ assert_nothing_raised {
14
+ rv = @nv.newarrival
15
+ }
16
+
17
+ rv.each {|v|
18
+ # puts v.id + ':' + v.published_at.to_s + ':' + v.title
19
+ puts v.id + ':' + v.title
20
+ # sleep 1
21
+ }
22
+
23
+ sleep 1
24
+ end
25
+
26
+ def test_ranking_invalid
27
+ end
28
+
29
+ def test_ranking_notopened
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoRandom < Test::Unit::TestCase
4
+
5
+ def setup
6
+ account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
7
+ @nv = Nicovideo.new(account['mail'], account['password'])
8
+ @nv.login
9
+ end
10
+
11
+ def test_ranking_valid
12
+ rv = nil
13
+ assert_nothing_raised {
14
+ rv = @nv.random
15
+ }
16
+
17
+ rv.each {|v|
18
+ # puts v.id + ':' + v.published_at.to_s + ':' + v.title
19
+ puts v.id + ':' + v.title
20
+ # sleep 1
21
+ }
22
+
23
+ sleep 1
24
+ end
25
+
26
+ def test_ranking_invalid
27
+ end
28
+
29
+ def test_ranking_notopened
30
+ end
31
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: nicovideo
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
7
- date: 2008-03-16 00:00:00 +09:00
6
+ version: 0.1.4
7
+ date: 2008-03-20 00:00:00 +09:00
8
8
  summary: utils for nicovideo
9
9
  require_paths:
10
10
  - lib
@@ -46,6 +46,8 @@ files:
46
46
  - lib/nicovideo/ranking.rb
47
47
  - lib/nicovideo/search.rb
48
48
  - lib/nicovideo/tagsearch.rb
49
+ - lib/nicovideo/newarrival.rb
50
+ - lib/nicovideo/random.rb
49
51
  - test/test_helper.rb
50
52
  - test/runner.rb
51
53
  - test/test_nicovideo.rb
@@ -56,6 +58,8 @@ files:
56
58
  - test/test_ranking.rb
57
59
  - test/test_search.rb
58
60
  - test/test_tagsearch.rb
61
+ - test/test_newarrival.rb
62
+ - test/test_random.rb
59
63
  - sample/nv_download.rb
60
64
  - sample/nv_download2.rb
61
65
  - sample/nv_mylist.rb
@@ -67,9 +71,11 @@ test_files:
67
71
  - test/test_mylist.rb
68
72
  - test/test_ranking.rb
69
73
  - test/test_tagsearch.rb
74
+ - test/test_newarrival.rb
70
75
  - test/test_videopage.rb
71
76
  - test/test_helper.rb
72
77
  - test/test_login.rb
78
+ - test/test_random.rb
73
79
  - test/test_search.rb
74
80
  rdoc_options:
75
81
  - --main