yasuyuki-nicovideo 0.1.8.3 → 0.1.8.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ module Nicovideo::Community
2
+ class CommunityPage < Nicovideo::Page
3
+ COMMUNITY_BASE_URL = 'http://ch.nicovideo.jp'
4
+
5
+ def initialize agent, community_id
6
+ super(agent)
7
+ @community_id = community_id
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,49 @@
1
+ require 'uri'
2
+
3
+ module Nicovideo::Community
4
+ class Main < CommunityPage
5
+ def initialize agent, community_id
6
+ super(agent, community_id)
7
+
8
+ @url = COMMUNITY_BASE_URL + '/community/' + @community_id
9
+ register_getter ["title", "description", "tags", "founded_at", "owner", "level"]
10
+ end
11
+
12
+ attr_reader :community_id, :url
13
+ def id() @community_id end
14
+
15
+ private
16
+ def parse(page)
17
+ raise Nicovideo::NotFound if @not_found
18
+ begin
19
+ # title
20
+ @title = page.title.toutf8.sub(/ - [^-]+$/ou, '')
21
+
22
+ # description
23
+ div = page.parser.search("//div[@class='community_bg']").first
24
+ puts_debug div
25
+ @description = div.search("//div[@class='community_description']").first.inner_html
26
+ div = div.to_html
27
+
28
+ # tags
29
+ @tags = div.scan(/<a href=\"\/search\/([^?]+)\?mode=t\"/ou).inject([]) {|arr, v|
30
+ puts_debug v[0]
31
+ arr << URI.unescape(v[0])
32
+ }
33
+
34
+ # founded_at
35
+ founded_time = div.match(/開設日:<strong>(\d+)年(\d+)月(\d+)日/).to_a.values_at(1, 2, 3)
36
+ @founded_at = Time.local(founded_time[0], founded_time[1], founded_time[2])
37
+
38
+ # owner
39
+ @owner = div.match(/オーナー:.*?<strong>([^<]+)<\/strong>/).to_a[1]
40
+
41
+ # level
42
+ @level = div.match(/レベル:.*?<strong>([^<]+)<\/strong>/m).to_a[1].to_i
43
+ rescue
44
+ @not_found = true
45
+ raise Nicovideo::NotFound
46
+ end
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yasuyuki-nicovideo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.3
4
+ version: 0.1.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - emergent
@@ -57,6 +57,8 @@ files:
57
57
  - config/hoe.rb
58
58
  - config/requirements.rb
59
59
  - lib/nicovideo.rb
60
+ - lib/nicovideo/community/community_page.rb
61
+ - lib/nicovideo/community/main.rb
60
62
  - lib/nicovideo/version.rb
61
63
  - lib/nicovideo/mechanize-ext.rb
62
64
  - lib/nicovideo/base.rb