bremen 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bremen/mixcloud.rb +2 -0
- data/lib/bremen/nicovideo.rb +4 -0
- data/lib/bremen/soundcloud.rb +2 -0
- data/lib/bremen/version.rb +1 -1
- data/lib/bremen/youtube.rb +5 -1
- data/spec/bremen/base_spec.rb +30 -0
- data/spec/bremen/mixcloud_spec.rb +3 -3
- data/spec/bremen/nicovideo_spec.rb +3 -3
- data/spec/bremen/soundcloud_spec.rb +3 -3
- data/spec/bremen/youtube_spec.rb +3 -3
- data/spec/fixtures/mixcloud_single.json +1 -1
- metadata +4 -2
data/lib/bremen/mixcloud.rb
CHANGED
@@ -7,6 +7,7 @@ module Bremen
|
|
7
7
|
self.default_options = {
|
8
8
|
keyword: '',
|
9
9
|
limit: 20,
|
10
|
+
page: 1,
|
10
11
|
}
|
11
12
|
|
12
13
|
class << self
|
@@ -23,6 +24,7 @@ module Bremen
|
|
23
24
|
query = {
|
24
25
|
q: options[:keyword],
|
25
26
|
limit: options[:limit],
|
27
|
+
offset: options[:limit] * (options[:page] - 1),
|
26
28
|
type: 'cloudcast',
|
27
29
|
}
|
28
30
|
"#{BASE_URL}search/?#{build_query(query)}"
|
data/lib/bremen/nicovideo.rb
CHANGED
@@ -6,6 +6,7 @@ module Bremen
|
|
6
6
|
BASE_URL = 'http://www.nicovideo.jp/'
|
7
7
|
self.default_options = {
|
8
8
|
keyword: '',
|
9
|
+
page: 1,
|
9
10
|
sort: 'f', #n(newer commented)/v(viewed)/r(most commented)/m(listed)/f(uploaded)/l(duration)
|
10
11
|
order: 'd', #a(asc)/d(desc)
|
11
12
|
within: '', #1(24h)/2(1w)/3(1m)
|
@@ -25,6 +26,7 @@ module Bremen
|
|
25
26
|
def search_url options = {}
|
26
27
|
options = default_options.merge(options)
|
27
28
|
query = {
|
29
|
+
page: options[:page],
|
28
30
|
sort: options[:sort],
|
29
31
|
order: options[:order],
|
30
32
|
f_range: options[:within],
|
@@ -53,6 +55,8 @@ module Bremen
|
|
53
55
|
end
|
54
56
|
|
55
57
|
def convert_multiply response
|
58
|
+
return [] if response.scan(%r{<div class="mb16p4">}).flatten.first
|
59
|
+
|
56
60
|
response.scan(%r{<div class="thumb_col_1">\n<!---->\n(.*?)\n<!---->\n</div></div>}m).flatten.map do |html|
|
57
61
|
uid = html.scan(%r{<table [^>]+ summary="(.+)">}).flatten.first
|
58
62
|
min, sec = html.scan(%r{<p class="vinfo_length"><span>([\d:]+)</span></p>}).flatten.first.to_s.split(':')
|
data/lib/bremen/soundcloud.rb
CHANGED
@@ -8,6 +8,7 @@ module Bremen
|
|
8
8
|
keyword: '',
|
9
9
|
order: 'created_at', #created_at/hotness
|
10
10
|
limit: 50,
|
11
|
+
page: 1,
|
11
12
|
filter: '', #(all)/public/private/streamable/downloadable
|
12
13
|
}
|
13
14
|
|
@@ -33,6 +34,7 @@ module Bremen
|
|
33
34
|
q: options[:keyword],
|
34
35
|
order: options[:order],
|
35
36
|
limit: options[:limit],
|
37
|
+
offset: options[:limit] * (options[:page] - 1),
|
36
38
|
filter: options[:filter],
|
37
39
|
}
|
38
40
|
"#{BASE_URL}tracks.json?#{build_query(query)}"
|
data/lib/bremen/version.rb
CHANGED
data/lib/bremen/youtube.rb
CHANGED
@@ -7,6 +7,7 @@ module Bremen
|
|
7
7
|
self.default_options = {
|
8
8
|
order: 'published', #relevance/published/viewCount/rating
|
9
9
|
limit: 25,
|
10
|
+
page: 1,
|
10
11
|
category: 'Music',
|
11
12
|
tag: '',
|
12
13
|
}
|
@@ -27,6 +28,7 @@ module Bremen
|
|
27
28
|
vq: options[:keyword],
|
28
29
|
orderby: options[:order],
|
29
30
|
:"max-results" => options[:limit],
|
31
|
+
:"start-index" => options[:page],
|
30
32
|
}
|
31
33
|
"#{BASE_URL}-/#{options[:category]}/#{options[:tag]}/?#{build_query(query)}"
|
32
34
|
end
|
@@ -56,7 +58,9 @@ module Bremen
|
|
56
58
|
end
|
57
59
|
|
58
60
|
def convert_multiply response
|
59
|
-
JSON.parse(response)['feed']
|
61
|
+
feed = JSON.parse(response)['feed']
|
62
|
+
return [] unless feed['entry']
|
63
|
+
feed['entry'].map{|t| from_api(t) }
|
60
64
|
end
|
61
65
|
end
|
62
66
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
$:.unshift(File.expand_path('../../', __FILE__))
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Bremen::Base do
|
5
|
+
describe '.search' do
|
6
|
+
#TODO: need to suport autoload soundcloud consumerkey from dotfile.
|
7
|
+
['Youtube', 'Mixcloud', 'Nicovideo'].each do |site|
|
8
|
+
describe site do
|
9
|
+
let(:klass){ Bremen.const_get(site) }
|
10
|
+
|
11
|
+
describe 'pagination' do
|
12
|
+
let(:params){ {keyword: 'kyary pamyu pamyu', limit: 1} }
|
13
|
+
let(:track_page1){ klass.search(params.merge(page: 1)).first }
|
14
|
+
let(:track_page2){ klass.search(params.merge(page: 2)).first }
|
15
|
+
it 'first tracks on each pages are different' do
|
16
|
+
track_page1.uid.wont_equal track_page2.uid
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'no result keyword' do
|
21
|
+
let(:params){ {keyword: 'kyarolinecharonpropkyarypamyupamyu', limit: 1 } }
|
22
|
+
subject{ klass.search(params) }
|
23
|
+
it 'returns empty array' do
|
24
|
+
subject.must_be_empty
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -24,14 +24,14 @@ describe Bremen::Mixcloud do
|
|
24
24
|
describe 'only keyword' do
|
25
25
|
let(:params){ {keyword: 'searchword'} }
|
26
26
|
it 'generate' do
|
27
|
-
subject.must_equal 'http://api.mixcloud.com/search/?q=searchword&limit=20&type=cloudcast'
|
27
|
+
subject.must_equal 'http://api.mixcloud.com/search/?q=searchword&limit=20&offset=0&type=cloudcast'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe 'full params' do
|
32
|
-
let(:params){ {keyword: 'searchword', limit:
|
32
|
+
let(:params){ {keyword: 'searchword', limit: 10, page: 2} }
|
33
33
|
it 'generate' do
|
34
|
-
subject.must_equal 'http://api.mixcloud.com/search/?q=searchword&limit=
|
34
|
+
subject.must_equal 'http://api.mixcloud.com/search/?q=searchword&limit=10&offset=10&type=cloudcast'
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -24,14 +24,14 @@ describe Bremen::Nicovideo do
|
|
24
24
|
describe 'only keyword' do
|
25
25
|
let(:params){ {keyword: 'searchword'} }
|
26
26
|
it 'generate' do
|
27
|
-
subject.must_equal 'http://www.nicovideo.jp/search/searchword?sort=f&order=d&f_range=&l_range=&opt_md='
|
27
|
+
subject.must_equal 'http://www.nicovideo.jp/search/searchword?page=1&sort=f&order=d&f_range=&l_range=&opt_md='
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe 'full params' do
|
32
|
-
let(:params){ {keyword: 'searchword', sort: 'n', order: 'a', within: 3, length: 2, downloadable: 1} }
|
32
|
+
let(:params){ {keyword: 'searchword', page: 2, sort: 'n', order: 'a', within: 3, length: 2, downloadable: 1} }
|
33
33
|
it 'generate' do
|
34
|
-
subject.must_equal 'http://www.nicovideo.jp/search/searchword?sort=n&order=a&f_range=3&l_range=2&opt_md=1'
|
34
|
+
subject.must_equal 'http://www.nicovideo.jp/search/searchword?page=2&sort=n&order=a&f_range=3&l_range=2&opt_md=1'
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -42,14 +42,14 @@ describe Bremen::Soundcloud do
|
|
42
42
|
describe 'only keyword' do
|
43
43
|
let(:params){ {keyword: 'searchword'} }
|
44
44
|
it 'generate' do
|
45
|
-
subject.must_equal 'http://api.soundcloud.com/tracks.json?q=searchword&order=created_at&limit=50&filter=&consumer_key=CK'
|
45
|
+
subject.must_equal 'http://api.soundcloud.com/tracks.json?q=searchword&order=created_at&limit=50&offset=0&filter=&consumer_key=CK'
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
describe 'full params' do
|
50
|
-
let(:params){ {keyword: 'searchword', order: 'hotness', limit:
|
50
|
+
let(:params){ {keyword: 'searchword', order: 'hotness', limit: 10, page: 2, filter: 'public'} }
|
51
51
|
it 'generate' do
|
52
|
-
subject.must_equal 'http://api.soundcloud.com/tracks.json?q=searchword&order=hotness&limit=
|
52
|
+
subject.must_equal 'http://api.soundcloud.com/tracks.json?q=searchword&order=hotness&limit=10&offset=10&filter=public&consumer_key=CK'
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
data/spec/bremen/youtube_spec.rb
CHANGED
@@ -24,14 +24,14 @@ describe Bremen::Youtube do
|
|
24
24
|
describe 'only keyword' do
|
25
25
|
let(:params){ {keyword: 'searchword'} }
|
26
26
|
it 'generate' do
|
27
|
-
subject.must_equal 'http://gdata.youtube.com/feeds/api/videos/-/Music//?vq=searchword&orderby=published&max-results=25&alt=json'
|
27
|
+
subject.must_equal 'http://gdata.youtube.com/feeds/api/videos/-/Music//?vq=searchword&orderby=published&max-results=25&start-index=1&alt=json'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe 'full params' do
|
32
|
-
let(:params){ {keyword: 'searchword', order: 'relevance', limit:
|
32
|
+
let(:params){ {keyword: 'searchword', order: 'relevance', limit: 10, page: 2, category: 'Entertainment', tag: 'game'} }
|
33
33
|
it 'generate' do
|
34
|
-
subject.must_equal 'http://gdata.youtube.com/feeds/api/videos/-/Entertainment/game/?vq=searchword&orderby=relevance&max-results=
|
34
|
+
subject.must_equal 'http://gdata.youtube.com/feeds/api/videos/-/Entertainment/game/?vq=searchword&orderby=relevance&max-results=10&start-index=2&alt=json'
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bremen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
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: 2012-12-
|
12
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard-minitest
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/bremen/track.rb
|
84
84
|
- lib/bremen/version.rb
|
85
85
|
- lib/bremen/youtube.rb
|
86
|
+
- spec/bremen/base_spec.rb
|
86
87
|
- spec/bremen/mixcloud_spec.rb
|
87
88
|
- spec/bremen/nicovideo_spec.rb
|
88
89
|
- spec/bremen/soundcloud_spec.rb
|
@@ -122,6 +123,7 @@ specification_version: 3
|
|
122
123
|
summary: Bremen provides common search interface for some music websites. it supports
|
123
124
|
YouTube, SoundCloud, MixCloud and Nicovideo
|
124
125
|
test_files:
|
126
|
+
- spec/bremen/base_spec.rb
|
125
127
|
- spec/bremen/mixcloud_spec.rb
|
126
128
|
- spec/bremen/nicovideo_spec.rb
|
127
129
|
- spec/bremen/soundcloud_spec.rb
|