nicoquery 0.0.1.4 → 0.0.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.
@@ -0,0 +1,195 @@
1
+ require "nori"
2
+
3
+
4
+ module NicoQuery
5
+ module ObjectMapper
6
+ class MylistRSS
7
+ attr_reader :meta, :items
8
+ def initialize(xml)
9
+ parser = Nori.new
10
+ parsed_xml = parser.parse xml
11
+ entire = parsed_xml['rss']['channel']
12
+
13
+ @meta = Meta.new entire, title_prefix
14
+ @items = entire['item'].map { |item| Item.new item }
15
+ end
16
+
17
+ def title_prefix
18
+ "マイリスト"
19
+ end
20
+
21
+ class Meta
22
+ def initialize(parsed_xml, title_prefix)
23
+ @title_prefix = title_prefix
24
+ @hash = parsed_xml
25
+ end
26
+
27
+ def title
28
+ @hash['title']
29
+ .scan(/(?<=#{@title_prefix}\s).+(?=\‐ニコニコ動画)/)[0].split(' ')[0]
30
+ # .force_encoding('utf-8')
31
+ end
32
+
33
+ def url
34
+ link
35
+ end
36
+
37
+ def link
38
+ @hash['link']
39
+ end
40
+
41
+ def mylist_id
42
+ @hash['link'].scan(/(?<=mylist\/)\d{1,}/)[0].to_i
43
+ end
44
+
45
+ def description
46
+ @hash['description']
47
+ end
48
+
49
+ def publish_date
50
+ Time.parse @hash['publish_date']
51
+ end
52
+
53
+ def last_build_date
54
+ Time.parse @hash['lastBuildDate']
55
+ end
56
+
57
+ def creator
58
+ @hash['dc:creator']
59
+ end
60
+ end
61
+
62
+ class Item
63
+
64
+ # <item>
65
+ # <title>【初音ミク】みくみくにしてあげる♪【してやんよ】</title>
66
+ # <link>http://www.nicovideo.jp/watch/sm1097445</link>
67
+ # <guid isPermaLink="false">tag:nicovideo.jp,2007-09-20:/watch/1190218917</guid>
68
+ # <pubDate>Sat, 17 Aug 2013 22:54:20 +0900</pubDate>
69
+ # <description><![CDATA[<p class="nico-thumbnail"><img alt="【初音ミク】みくみくにしてあげる♪【してやんよ】" src="http://tn-skr2.smilevideo.jp/smile?i=1097445" width="94" height="70" border="0"/></p><p class="nico-description">おまえら、みっくみくにしてやんよ。歌詞はhttp://ikamo.hp.infoseek.co.jp/mikumiku.txt(9/20 1:55修正)。上げている他のもの→mylist/1450136</p><p class="nico-info"><small><strong class="nico-info-length">1:38</strong>|<strong class="nico-info-date">2007年09月20日 01:22:02</strong> 投稿</small></p><p class="nico-numbers"><small>再生:<strong class="nico-numbers-view">10,643,217</strong>&nbsp;&#x20;コメント:<strong class="nico-numbers-res">2,726,450</strong>&nbsp;&#x20;マイリスト:<strong class="nico-numbers-mylist">210,310</strong></small></p>]]></description>
70
+ # </item>
71
+
72
+ def initialize(parsed_xml)
73
+ @hash = parsed_xml
74
+ end
75
+
76
+ def title
77
+ @hash['title']
78
+ end
79
+
80
+ def video_id
81
+ (url.scan(/((sm|nm)\d{1,})/).map {|e| e[0]})[0]
82
+ end
83
+
84
+ def url
85
+ @hash['link']
86
+ end
87
+
88
+ def thread_id
89
+ @hash['guid'].scan(/(?<=watch\/)\d{1,}$/)[0].to_i
90
+ end
91
+
92
+ def publish_date
93
+ Time.parse @hash['pubDate']
94
+ end
95
+
96
+ def thumbnail_url
97
+ description.raw_text.scan(/(?<=src\=\").{1,}(?=\"\swidth)/)[0]
98
+ $&
99
+ end
100
+
101
+ def view_counter
102
+ description.raw_text.scan(/(?<=nico-numbers-view\">)[0-9,]{1,}(?=\<\/strong)/)[0].delete(',').to_i
103
+ end
104
+
105
+ def comment_num
106
+ description.raw_text.scan(/(?<=nico-numbers-res\">)[0-9,]{1,}(?=\<\/strong)/)[0].delete(',').to_i
107
+ end
108
+
109
+ def mylist_counter
110
+ description.raw_text.scan(/(?<=nico-numbers-mylist\">)[0-9,]{1,}(?=\<\/strong)/)[0].delete(',').to_i
111
+ end
112
+
113
+ def description
114
+ @_description ||= Description.new @hash['description']
115
+ end
116
+
117
+ def length
118
+ description.raw_text.scan(/(?<=class\=\"nico\-info\-length\"\>)\d{1,}\:\d{1,2}(?=\<\/strong\>)/)
119
+ length_string = $&.to_s.split(':')
120
+ length_string[0].to_i * 60 + length_string[1].to_i
121
+ end
122
+
123
+ class Description
124
+ attr_reader :raw_text
125
+
126
+ def initialize(raw_text)
127
+ @raw_text = raw_text.to_s
128
+ end
129
+
130
+ def text
131
+ @raw_text.scan /(?<=class\=\"nico\-description\"\>).{1,}(?=\<\/p\>)/
132
+ $&
133
+ end
134
+
135
+ def movie_references
136
+ # is this the high road?
137
+ text.scan(/((sm|nm)\d{1,})/).map {|e| e[0]}
138
+ end
139
+
140
+ def mylist_references
141
+ text.scan /(?<=mylist\/)\d{1,}/
142
+ end
143
+
144
+ def community_references
145
+ text.scan /co\d{1,}/
146
+ end
147
+
148
+ def seiga_references
149
+ text.scan /im\d{1,}/
150
+ end
151
+ end
152
+ end
153
+
154
+ # <?xml version="1.0" encoding="utf-8"?>
155
+ # <rss version="2.0"
156
+ # xmlns:dc="http://purl.org/dc/elements/1.1/"
157
+ # xmlns:atom="http://www.w3.org/2005/Atom">
158
+
159
+ # <channel>
160
+
161
+ # <title>マイリスト to_test‐ニコニコ動画</title>
162
+ # <link>http://www.nicovideo.jp/mylist/38369702</link>
163
+ # <atom:link rel="self" type="application/rss+xml" href="http://www.nicovideo.jp/mylist/38369702?rss=2.0"/>
164
+ # <description></description>
165
+ # <pubDate>Sat, 17 Aug 2013 22:51:40 +0900</pubDate>
166
+ # <lastBuildDate>Sat, 17 Aug 2013 22:51:40 +0900</lastBuildDate>
167
+ # <generator>ニコニコ動画</generator>
168
+ # <dc:creator>うえおに</dc:creator>
169
+ # <language>ja-jp</language>
170
+ # <copyright>(c) niwango, inc. All rights reserved.</copyright>
171
+ # <docs>http://blogs.law.harvard.edu/tech/rss</docs>
172
+
173
+
174
+ # <item>
175
+ # <title>【初音ミク】みくみくにしてあげる♪【してやんよ】</title>
176
+ # <link>http://www.nicovideo.jp/watch/sm1097445</link>
177
+ # <guid isPermaLink="false">tag:nicovideo.jp,2007-09-20:/watch/1190218917</guid>
178
+ # <pubDate>Sat, 17 Aug 2013 22:54:20 +0900</pubDate>
179
+ # <description><![CDATA[<p class="nico-thumbnail"><img alt="【初音ミク】みくみくにしてあげる♪【してやんよ】" src="http://tn-skr2.smilevideo.jp/smile?i=1097445" width="94" height="70" border="0"/></p><p class="nico-description">おまえら、みっくみくにしてやんよ。歌詞はhttp://ikamo.hp.infoseek.co.jp/mikumiku.txt(9/20 1:55修正)。上げている他のもの→mylist/1450136</p><p class="nico-info"><small><strong class="nico-info-length">1:38</strong>|<strong class="nico-info-date">2007年09月20日 01:22:02</strong> 投稿</small></p>]]></description>
180
+ # </item>
181
+
182
+ # <item>
183
+ # <title>新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師</title>
184
+ # <link>http://www.nicovideo.jp/watch/sm9</link>
185
+ # <guid isPermaLink="false">tag:nicovideo.jp,2007-03-06:/watch/1173108780</guid>
186
+ # <pubDate>Sat, 17 Aug 2013 22:52:21 +0900</pubDate>
187
+ # <description><![CDATA[<p class="nico-thumbnail"><img alt="新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師" src="http://tn-skr2.smilevideo.jp/smile?i=9" width="94" height="70" border="0"/></p><p class="nico-description">レッツゴー!陰陽師(フルコーラスバージョン)</p><p class="nico-info"><small><strong class="nico-info-length">5:19</strong>|<strong class="nico-info-date">2007年03月06日 00:33:00</strong> 投稿</small></p>]]></description>
188
+ # </item>
189
+
190
+ # </channel>
191
+
192
+ # </rss>
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,43 @@
1
+ require "nicoquery/object_mapper/mylist_rss"
2
+ require "nori"
3
+
4
+
5
+ module NicoQuery
6
+ module ObjectMapper
7
+ class TagSearchRss < MylistRSS
8
+ def title_prefix
9
+ "タグ";
10
+ end
11
+ end
12
+ end
13
+ end
14
+ # <?xml version="1.0" encoding="utf-8"?>
15
+ # <rss version="2.0"
16
+ # xmlns:atom="http://www.w3.org/2005/Atom">
17
+
18
+ # <channel>
19
+ # <title>タグ VOICEROID+_東北ずん子‐ニコニコ動画</title>
20
+ # <link>http://www.nicovideo.jp/tag/VOICEROID%2B_%E6%9D%B1%E5%8C%97%E3%81%9A%E3%82%93%E5%AD%90</link>
21
+ # <atom:link rel="self" type="application/rss+xml" href="http://www.nicovideo.jp/tag/VOICEROID%2B_%E6%9D%B1%E5%8C%97%E3%81%9A%E3%82%93%E5%AD%90?rss=2.0"/>
22
+ # <description>タグ「VOICEROID+_東北ずん子」が付けられた動画 (全 299 件)</description>
23
+ # <pubDate>Sun, 18 Aug 2013 19:15:24 +0900</pubDate>
24
+ # <lastBuildDate>Sun, 18 Aug 2013 19:15:24 +0900</lastBuildDate>
25
+ # <generator>ニコニコ動画</generator>
26
+ # <language>ja-jp</language>
27
+ # <copyright>(c) niwango, inc. All rights reserved.</copyright>
28
+ # <docs>http://blogs.law.harvard.edu/tech/rss</docs>
29
+
30
+ # <item>
31
+ # <title>【Minecraft】GREEN&#039;S CRAFT Part1【ゆっくり&amp;amp;VOICEROID+実況】</title>
32
+ # <link>http://www.nicovideo.jp/watch/sm21615389</link>
33
+ # <guid isPermaLink="false">tag:nicovideo.jp,2013-08-17:/watch/sm21615389</guid>
34
+ # <pubDate>Sat, 17 Aug 2013 19:48:21 +0900</pubDate>
35
+ # <description><![CDATA[
36
+ # <p class="nico-thumbnail"><img alt="【Minecraft】GREEN&#039;S CRAFT Part1【ゆっくり&amp;amp;VOICEROID+実況】" src="http://tn-skr2.smilevideo.jp/smile?i=21615389" width="94" height="70" border="0"/></p>
37
+ # <p class="nico-description">お久しぶりです。周りの人にも感化され、ようやく新シリーズに踏み込むことができました。勢いだけで始めてしまったため今後どうなるか自分でも予想できませんが前作同様ひっそりまったり、そして少しでも長く続けられるように頑張りますのでまたお付き合いいただけると嬉しいです(*´ヮ`*)それでは、よろしくお願いします。使用MOD1.Opti Fine2.MinecraftIM3.PlayerFormLittleMaid4.Audiotori5.littleMaidMob6.Zabuton+りばいあ製MOD×2次→まだシリーズまとめ→mylist/38367203まったりクラフター生活シリーズ→mylist/29017292他に作ったもの→mylist/29022355twitter⇒http://twitter.com/raichi_Jコミュco1590050『PHANTASY STAR ONLINE 2』公式サイトhttp://pso2.jp/</p>
38
+ # <p class="nico-info"><small><strong class="nico-info-length">12:33</strong>|<strong class="nico-info-date">2013年08月17日 19:48:21</strong> 投稿</small></p>
39
+ # ]]></description>
40
+ # </item>
41
+ # </channel>
42
+
43
+ # </rss>
@@ -1,3 +1,3 @@
1
1
  module NicoQuery
2
- VERSION = "0.0.1.4"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/nicoquery.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "nicoquery/version"
2
2
  require "nicoquery/crawler"
3
+ require "nicoquery/object/mylist"
4
+ require "nicoquery/object/movie"
3
5
 
4
6
 
5
7
  module NicoQuery
@@ -7,6 +9,15 @@ module NicoQuery
7
9
  NicoQuery::Crawler::TagSearch.execute(tag: tag, sort: sort, order: order, &block)
8
10
  end
9
11
 
12
+ def mylist(mylist_id)
13
+ NicoQuery::Object::Mylist.new mylist_id
14
+ end
15
+
16
+ def movie(video_id)
17
+ NicoQuery::Object::Movie.new video_id
18
+ end
19
+
10
20
  module_function :tag_search
21
+ module_function :mylist
22
+ module_function :movie
11
23
  end
12
- ;
@@ -0,0 +1,15 @@
1
+ require 'nicoquery/api/getthumbinfo'
2
+
3
+
4
+ describe "getthumbinfo" do
5
+ before do
6
+ @instance = NicoQuery::Api::GetThumbInfo.new 'sm9'
7
+ end
8
+
9
+ describe "uri" do
10
+ subject { @instance.uri }
11
+ specify {
12
+ expect(subject).to match /http:\/\/ext\.nicovideo\.jp\/api\/getthumbinfo\/(sm|nm)\d/
13
+ }
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require 'nicoquery/api/mylist_rss'
2
+
3
+
4
+ describe "mylist_rss" do
5
+ before do
6
+ @instance = NicoQuery::Api::MylistRSS.new 18266317
7
+ end
8
+
9
+ describe "uri" do
10
+ subject { @instance.uri }
11
+
12
+ specify { expect(subject).to match /http:\/\/www\.nicovideo\.jp\/mylist/ }
13
+ specify { expect(subject).to match /18266317/ }
14
+ specify { expect(subject).to match /rss\=2\.0/ }
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'nicoquery/api/tag_search'
2
+
3
+
4
+ describe "tag_search" do
5
+ before do
6
+ @instance = NicoQuery::Api::TagSearch.new tag: 'ゆっくり実況プレイ',
7
+ sort: :published_at,
8
+ order: :asc,
9
+ page: 1
10
+ end
11
+
12
+ describe "uri" do
13
+ subject { @instance.uri }
14
+
15
+ specify { expect(subject).to match /http:\/\/www\.nicovideo\.jp\/tag/ }
16
+
17
+ specify { expect(subject).to match /(sort=(v|r|m|f|l)){0,}/ }
18
+ specify { expect(subject).to match /(order=(a|d)){0,}/ }
19
+ specify { expect(subject).to match /(page=\d){1,}/ }
20
+ specify { expect(subject).to match /rss\=2\.0/ }
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ require 'nicoquery/api/video_array'
2
+
3
+
4
+ describe "VideoArray" do
5
+ before do
6
+ @instance = NicoQuery::Api::VideoArray.new ['sm9', 'sm14']
7
+ end
8
+
9
+ describe "uri" do
10
+ subject { @instance.uri }
11
+ specify {
12
+ expect(subject).to match /http:\/\/i\.nicovideo\.jp\/v3\/video\.array\?v=((sm\d|nm\d),{0,}){1,}/
13
+ }
14
+ end
15
+ end
@@ -1,16 +1,16 @@
1
- require "nicoquery"
1
+ require "nicoquery/crawler/tag_search"
2
2
 
3
3
 
4
- describe "NicoQuery::Crawler" do
4
+ describe "NicoQuery:Crawler" do
5
5
  describe "tag_search" do
6
6
  before do
7
7
  counter = 0
8
8
  @acquired_movies = []
9
9
 
10
- NicoQuery.tag_search( tag: "ゆっくり実況プレイ",
11
- sort: :published_at,
12
- order: :asc
13
- ) do |result|
10
+ NicoQuery::Crawler::TagSearch.execute( tag: "ゆっくり実況プレイ",
11
+ sort: :published_at,
12
+ order: :asc
13
+ ) do |result|
14
14
  counter += 1
15
15
  @acquired_movies.push result
16
16
  if counter >= 50 then :break else :continue end
@@ -0,0 +1,51 @@
1
+ module Fixture
2
+ def self.tag_search_item_xml_1
3
+ """
4
+ <item>
5
+ <title>[ゆっくり実況]どうぶつ達の森[最終日]</title>
6
+ <link>http://www.nicovideo.jp/watch/sm21441922</link>
7
+ <guid isPermaLink=\"false\">tag:nicovideo.jp,2013-07-26:/watch/sm21441922</guid>
8
+ <pubDate>Fri, 26 Jul 2013 10:32:46 +0900</pubDate>
9
+ <description><![CDATA[
10
+ <p class=\"nico-thumbnail\"><img alt=\"[ゆっくり実況]どうぶつ達の森[最終日]\" src=\"http://tn-skr3.smilevideo.jp/smile?i=21441922\" width=\"94\" height=\"70\" border=\"0\"/></p>
11
+ <p class=\"nico-description\">おもらし製作中のゲーム進行率:6%追記:最後の最後でスタッフロール間違えるとか死ねばいいよほんとこのうpぬし八日目→sm21386536  どうぶつ→mylist/37262141いままでの→mylist/31786817</p>
12
+ <p class=\"nico-info\"><small><strong class=\"nico-info-length\">18:08</strong>|<strong class=\"nico-info-date\">2013年07月26日 10:32:46</strong> 投稿</small></p>
13
+ ]]></description>
14
+ </item>
15
+ """
16
+ end
17
+
18
+ # コミュニティへの参照あり
19
+ def self.tag_search_item_xml_2
20
+ """
21
+ <item>
22
+ <title>【COD:BO2】戦場で空気になる動画 Part7</title>
23
+ <link>http://www.nicovideo.jp/watch/sm21452374</link>
24
+ <guid isPermaLink=\"false\">tag:nicovideo.jp,2013-07-27:/watch/sm21452374</guid>
25
+ <pubDate>Sat, 27 Jul 2013 19:25:33 +0900</pubDate>
26
+ <description><![CDATA[
27
+ <p class=\"nico-thumbnail\"><img alt=\"【COD:BO2】戦場で空気になる動画 Part7\" src=\"http://tn-skr3.smilevideo.jp/smile?i=21452374\" width=\"94\" height=\"70\" border=\"0\"/></p>
28
+ <p class=\"nico-description\">無駄な殺生をせず戦場で生き延びます。・すべて生放送で撮影しており、おまけ以外はフレンドとプレイしていません。・おまけの隠れ場所は私が考えました。戦場で空気になる動画BGM集 : mylist/37475771コブのコミュ : co519582Twitter : @KOBUKURO__LOVE戦場で空気になる動画 mylist/35284652うp動画リンク:mylist/35527016前:sm21077273 次:</p>
29
+ <p class=\"nico-info\"><small><strong class=\"nico-info-length\">10:28</strong>|<strong class=\"nico-info-date\">2013年07月27日 19:25:33</strong> 投稿</small></p>
30
+ ]]></description>
31
+ </item>
32
+ """
33
+ end
34
+
35
+ # 静画への参照あり
36
+ def self.tag_search_item_xml_3
37
+ """
38
+ <item>
39
+ <title>【Minecraft】 ゆっくり仙人sで二人言プレイ part32 【ゆっくり実況】</title>
40
+ <link>http://www.nicovideo.jp/watch/sm21460522</link>
41
+ <guid isPermaLink=\"false\">tag:nicovideo.jp,2013-07-28:/watch/sm21460522</guid>
42
+ <pubDate>Sun, 28 Jul 2013 19:14:38 +0900</pubDate>
43
+ <description><![CDATA[
44
+ <p class=\"nico-thumbnail\"><img alt=\"【Minecraft】 ゆっくり仙人sで二人言プレイ part32 【ゆっくり実況】\" src=\"http://tn-skr3.smilevideo.jp/smile?i=21460522\" width=\"94\" height=\"70\" border=\"0\"/></p>
45
+ <p class=\"nico-description\">今回は馬探しです。当初は馬小屋作りまでやろうと思っていたのですが……。 茨歌仙3巻、発売して間もないですがネタバレを含んでいるので注意です。ネタにするのは次のパートまで待とうかとも思いましたが、突っ込みどころが多くて我慢できませんでした。 最近話題の無断転載については、私は別にどうでもいいのでスルーさせて下さい……。ニコニコモンズの素材(ゆっくりキャラ素材)がニコニコ外の転載禁止だったら話は早かったのですが、利用許可範囲がインターネット全般だったので。もちろん転載を推奨するわけではないですが、対応がメンドイので……。 【sm21353692:前回┃mylist/33965897┃次回:8/11予定】 おまけイラスト全体:im3300193 </p>
46
+ <p class=\"nico-info\"><small><strong class=\"nico-info-length\">15:52</strong>|<strong class=\"nico-info-date\">2013年07月28日 19:14:38</strong> 投稿</small></p>
47
+ ]]></description>
48
+ </item>
49
+ """
50
+ end
51
+ end