nicovideo 0.1.1 → 0.1.2

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/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ 2008-03-15 version 0.1.2
2
+
3
+ * removed outputs for debug
4
+ * fixed internal search parameters
5
+ * fixed xpath for sp1
6
+ *
7
+
1
8
  2008-02-25 version 0.1.1
2
9
 
3
10
  * fixed typo in Nicovideo::Ranking#url
@@ -26,7 +26,7 @@ module Nicovideo
26
26
  private
27
27
  def parse(page)
28
28
  @rss = RSS::Parser.parse(page.body)
29
- @title = rss.channel.title.sub(/#{BASE_TITLE+NICO_MYLIST} /, '')
29
+ @title = rss.channel.title.sub(/#{BASE_TITLE2+NICO_MYLIST} /, '')
30
30
  @user = rss.channel.managingEditor
31
31
  @description = rss.channel.description
32
32
 
@@ -7,7 +7,7 @@ module Nicovideo
7
7
  class OpenList < Page
8
8
  include Enumerable
9
9
 
10
- def initialize agent, video_id, pagenum=1, sort='c', order='d'
10
+ def initialize agent, video_id, sort='c', order='d', pagenum=1
11
11
  super(agent)
12
12
  @video_id = video_id
13
13
  @pagenum = pagenum
@@ -46,34 +46,42 @@ module Nicovideo
46
46
 
47
47
  def page=(pagenum)
48
48
  self.pagenum = pagenum
49
+ self
49
50
  end
50
51
 
51
52
  def next
52
53
  self.pagenum = @pagenum + 1
54
+ self
53
55
  end
54
56
 
55
57
  def prev
56
58
  self.pagenum = @pagenum - 1
59
+ self
57
60
  end
58
61
 
59
62
  protected
60
63
  def parse(page)
61
- if page.body =~ /<strong>#{@video_id}<\/strong> を含む公開マイリストはありません。/
62
- @not_found = true
63
- raise NotFound
64
+ if page.body =~ /<strong>#{@video_id}<\/strong>を含む公開マイリストはありません。/
65
+ @not_found = true
66
+ raise NotFound
64
67
  end
65
68
 
66
- @total_size = page.search('form[@name="sort"]//td[@class="TXT12"]//strong').first.inner_html.to_i
67
- if (page/'a//img[@src="http://res.nicovideo.jp/img/common/pager_next_on.gif"]').size > 0
68
- @has_next = true
69
- else
70
- @has_next = false
71
- end
72
-
73
- if (page/'a//img[@src="http://res.nicovideo.jp/img/common/pager_back_on.gif"]').size > 0
74
- @has_prev = true
75
- else
76
- @has_prev = false
69
+ @total_size = page.search('//form[@name="sort"]//td[@class="TXT12"]//strong').first.inner_html.sub(/,/,'').to_i
70
+
71
+ @has_next = false
72
+ @has_prev = false
73
+ respages = page/'//div[@class="mb16p4"]//p[@class="TXT12"]//a'
74
+ puts_info respages.size
75
+ respages.each {|r| puts_info r.inner_html }
76
+ if respages.size > 0
77
+ respages.each {|text|
78
+ if text.inner_html =~ /前のページ/
79
+ @has_prev = true
80
+ end
81
+ if text.inner_html =~ /次のページ/
82
+ @has_next = true
83
+ end
84
+ }
77
85
  end
78
86
 
79
87
  scanpattern = /<a href=\"#{BASE_URL}\/mylist\/(\d+)\">(.+?)<\/a>/ou
@@ -6,7 +6,8 @@ module Nicovideo
6
6
  NV_DEBUG_LEVEL = 0
7
7
 
8
8
  BASE_URL = 'http://www.nicovideo.jp'
9
- BASE_TITLE = 'ニコニコ動画\(RC\)'.toutf8
9
+ BASE_TITLE1 = '‐ニコニコ動画\(SP1\)'.toutf8
10
+ BASE_TITLE2 = 'ニコニコ動画\(SP1\)‐'.toutf8
10
11
 
11
12
  def initialize agent
12
13
  @agent = agent
@@ -7,19 +7,27 @@ module Nicovideo
7
7
  def initialize agent, keyword, sort=nil, order=nil, pagenum=1
8
8
  super(agent)
9
9
  @search_type = 'search'
10
- @keyword = CGI.escape(CGI.escape(keyword)) # なぜか2回エスケープが必要?
10
+ #@keyword = CGI.escape(CGI.escape(keyword))
11
+ @keyword = CGI.escape(keyword)
12
+ @sort = sort
11
13
  @order = order
14
+ @pagenum = pagenum
12
15
 
13
16
  params = ["videos", "total_size", "has_next?", "has_prev?"]
14
17
  self.register_getter params
15
18
 
16
19
  @url = url()
20
+
21
+ puts_info "url = #{@url}"
22
+ puts_info "sort=#{@sort},order=#{@order},pagenum=#{@pagenum}"
17
23
  end
18
24
 
19
25
  def url
20
- url = "#{BASE_URL}/#{@search_type}?ref=top&s=#{@keyword}"
26
+ url = "#{BASE_URL}/#{@search_type}/#{@keyword}"
27
+ url += '?' if (@sort || @order || @pagenum)
21
28
  url += '&sort=' + @sort if @sort
22
29
  url += '&order=' + @order if @order
30
+ url += '&page=' + @pagenum.to_s if @pagenum
23
31
  url
24
32
  end
25
33
 
@@ -45,10 +53,12 @@ module Nicovideo
45
53
 
46
54
  def next
47
55
  self.pagenum = @pagenum + 1
56
+ self
48
57
  end
49
58
 
50
59
  def prev
51
60
  self.pagenum = @pagenum - 1
61
+ self
52
62
  end
53
63
 
54
64
  protected
@@ -58,28 +68,32 @@ module Nicovideo
58
68
  raise NotFound
59
69
  end
60
70
 
61
- @total_size = page.search('form[@name="sort"]//td[@class="TXT12"]//strong').first.inner_html.to_i
62
-
63
- if (page/'a//img[@src="http://res.nicovideo.jp/img/common/pager_next_on.gif"]').size > 0
64
- @has_next = true
65
- else
66
- @has_next = false
71
+ @total_size = page.search('form[@name="sort"]//td[@class="TXT12"]//strong').first.inner_html.sub(/,/,'').to_i
72
+
73
+ @has_next = false
74
+ @has_prev = false
75
+ respages = page/'//div[@class="mb16p4"]//p[@class="TXT12"]//a'
76
+ puts_info respages.size
77
+ respages.each {|r| puts_info r.inner_html }
78
+ if respages.size > 0
79
+ respages.each {|text|
80
+ if text.inner_html =~ /前のページ/
81
+ @has_prev = true
82
+ end
83
+ if text.inner_html =~ /次のページ/
84
+ @has_next = true
85
+ end
86
+ }
67
87
  end
68
88
 
69
- if (page/'a//img[@src="http://res.nicovideo.jp/img/common/pager_back_on.gif"]').size > 0
70
- @has_prev = true
71
- else
72
- @has_prev = false
73
- end
89
+ result_xpath = page/'//div[@class="cmn_thumb_R"]//p[@class="TXT12"]/a[@class="video"]'
74
90
 
75
- result_xpath = page/'div[@class="thumb_R"]/p[@class="TXT12"]/a[@class="video"]'
76
- puts result_xpath.size.to_s
91
+ puts_info result_xpath.size.to_s
77
92
  @videos = result_xpath.inject([]) {|arr, v|
78
93
  vp = VideoPage.new(@agent, v.attributes['href'].sub(/watch\/(\w+)$/,'\1'))
79
94
  vp.title = v.inner_html
80
95
  arr << vp
81
96
  }
82
-
83
97
  end
84
98
 
85
99
  end
@@ -2,7 +2,7 @@ module Nicovideo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -59,7 +59,7 @@ module Nicovideo
59
59
  private
60
60
  def parse(page)
61
61
  # title
62
- @title = page.title.toutf8.sub(/^#{BASE_TITLE}/ou, '')
62
+ @title = page.title.toutf8.sub(/#{BASE_TITLE1}$/ou, '')
63
63
 
64
64
  # tags
65
65
  div = page.parser.search("div#video_tags")
@@ -15,7 +15,8 @@ class TestNicovideoRanking < Test::Unit::TestCase
15
15
  }
16
16
 
17
17
  rv.each {|v|
18
- puts v.id + ':' + v.published_at.to_s + ':' + v.title
18
+ # puts v.id + ':' + v.published_at.to_s + ':' + v.title
19
+ puts v.id + ':' + v.title
19
20
  sleep 1
20
21
  }
21
22
 
@@ -8,40 +8,70 @@ class TestNicovideoSearch < Test::Unit::TestCase
8
8
  @nv.login
9
9
  end
10
10
 
11
- def test_search_testing0
12
- result = @nv.search("aaa")
11
+ def output_results result
13
12
  puts result.total_size
14
13
  result.each {|v|
15
- puts v.title
14
+ puts v.id + ':' + v.title
16
15
  }
17
- sleep 1
16
+ end
17
+ =begin
18
+ def test_search_testing0
19
+ result = @nv.search("aaa")
20
+ output_results result
21
+ sleep 3
18
22
  end
19
23
 
20
24
  def test_search_testing1
21
25
  result = @nv.search("ミク")
22
- result.each {|v|
23
- puts v.title
24
- }
25
- sleep 1
26
+ output_results result
27
+ sleep 3
26
28
  end
29
+ =end
27
30
 
31
+ def test_search_next
32
+ result = @nv.search("ミク", 'n')
33
+ output_results result
34
+ i = 1
35
+ sleep 5
36
+ while result.has_next? && i < 5
37
+ output_results result.next
38
+ i += 1
39
+ sleep 5
40
+ end
41
+
42
+ sleep 3
43
+ end
44
+ def test_search_prev
45
+ result = @nv.search("ミク", 'n', nil, 5)
46
+ output_results result
47
+ i = 5
48
+ sleep 5
49
+ while result.has_prev? && i > 0
50
+ output_results result.prev
51
+ i -= 1
52
+ sleep 5
53
+ end
54
+ end
55
+
56
+ =begin
28
57
  def test_search_testing2
29
58
  result = @nv.search("ミク", 'n')
30
- result.each {|v|
59
+ puts result.total_size
60
+ result.each { |v|
31
61
  puts v.title
32
62
  }
33
- sleep 1
63
+ sleep 3
34
64
  end
35
65
 
36
66
  def test_search_testing3
37
67
  result = @nv.search("ミク", 'n', 'd')
68
+ puts result.total_size
38
69
  result.each {|v|
39
70
  puts v.title
40
71
  }
41
- sleep 1
72
+ sleep 3
42
73
  end
43
-
44
-
74
+ =end
45
75
  =begin
46
76
  def test_search_valid
47
77
  rv = nil
@@ -19,10 +19,10 @@ class TestNicovideoVideoPage < Test::Unit::TestCase
19
19
  assert_nothing_raised {
20
20
  vp = @nv.watch(@vid_valid)
21
21
  }
22
- assert_nothing_raised { vp.flv }
22
+ # assert_nothing_raised { vp.flv }
23
23
  sleep 5
24
24
  end
25
- =begin
25
+
26
26
  def test_watch_valid
27
27
  vp = nil
28
28
  assert_nothing_raised {
@@ -37,10 +37,10 @@ class TestNicovideoVideoPage < Test::Unit::TestCase
37
37
  puts vp.tags
38
38
  puts vp.title
39
39
  puts vp.published_at
40
- assert_nothing_raised { vp.flv }
40
+ # assert_nothing_raised { vp.flv }
41
41
  #assert_instance_of(String, vp.flv)
42
42
  #assert_instance_of(String, vp.video)
43
- File.open("#{@vid_valid}.flv", "wb") {|f| f.write vp.flv }
43
+ # File.open("#{@vid_valid}.flv", "wb") {|f| f.write vp.flv }
44
44
 
45
45
  sleep 1
46
46
  end
@@ -93,5 +93,4 @@ class TestNicovideoVideoPage < Test::Unit::TestCase
93
93
 
94
94
  sleep 1
95
95
  end
96
- =end
97
96
  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.1
7
- date: 2008-02-25 00:00:00 +09:00
6
+ version: 0.1.2
7
+ date: 2008-03-15 00:00:00 +09:00
8
8
  summary: utils for nicovideo
9
9
  require_paths:
10
10
  - lib