metal-archives 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.rdoc +10 -10
- data/VERSION +1 -1
- data/lib/metal-archives.rb +13 -13
- data/metal-archives.gemspec +1 -1
- data/spec/metal-archives_spec.rb +12 -12
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -10,24 +10,24 @@ Here is a quick and dirty example:
|
|
10
10
|
require 'metal-archives'
|
11
11
|
|
12
12
|
agent = MetalArchives::Agent.new
|
13
|
-
|
13
|
+
urls = []
|
14
14
|
|
15
|
-
agent.
|
16
|
-
|
17
|
-
if
|
15
|
+
agent.paginated_result_urls.each do |search_result|
|
16
|
+
url = agent.album_urls(search_result)
|
17
|
+
if url.nil?
|
18
18
|
puts "\nThrew an exception so exit"
|
19
19
|
break
|
20
20
|
else
|
21
21
|
print '.'
|
22
|
-
|
22
|
+
urls << url
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
|
-
puts "DONE: #{
|
25
|
+
urls.flatten!
|
26
|
+
puts "DONE: #{urls.size}"
|
27
27
|
|
28
|
-
if
|
29
|
-
puts "album information for the first result: #{agent.album_from_url(
|
30
|
-
puts "album information for the first result: #{agent.album_from_url(
|
28
|
+
if urls.size >= 1
|
29
|
+
puts "album information for the first result: #{agent.album_from_url(urls.first).inspect}"
|
30
|
+
puts "album information for the first result: #{agent.album_from_url(urls.last).inspect}"
|
31
31
|
end
|
32
32
|
|
33
33
|
== Contributing to metal-archives
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/metal-archives.rb
CHANGED
@@ -25,35 +25,35 @@ module MetalArchives
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
# Finds all the
|
29
|
-
def
|
30
|
-
# need the first page because it's not a
|
31
|
-
|
28
|
+
# Finds all the url to the search results pages as they are paginated.
|
29
|
+
def paginated_result_urls
|
30
|
+
# need the first page because it's not a url
|
31
|
+
urls = ["/advanced.php?release_year=#{@year}&p=1"]
|
32
32
|
begin
|
33
33
|
search_by_year.search('body table:nth-child(2n) tr:first-child a').each do |link|
|
34
|
-
|
34
|
+
urls << link['href']
|
35
35
|
end
|
36
36
|
rescue Exception => e
|
37
|
-
puts "\nError accessing metal-archives.com's paginated result
|
37
|
+
puts "\nError accessing metal-archives.com's paginated result urls: #{e}"
|
38
38
|
ensure
|
39
|
-
return
|
39
|
+
return urls
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
# Finds all the
|
44
|
-
def
|
45
|
-
|
43
|
+
# Finds all the urls to the albums on a given search results page.
|
44
|
+
def album_urls(url)
|
45
|
+
urls = []
|
46
46
|
begin
|
47
47
|
page = @agent.get(SITE_URL + url)
|
48
48
|
page.encoding = 'iso-8859-1' if !page.nil? && page.encoding != 'iso-8859-1' # needed for foreign characters
|
49
49
|
page.search('body table:nth-child(2n) tr td:nth-child(3n) a').each do |link|
|
50
|
-
|
50
|
+
urls << link['href']
|
51
51
|
end
|
52
52
|
rescue Exception => e
|
53
|
-
puts "\nError accessing metal-archives.com's album
|
53
|
+
puts "\nError accessing metal-archives.com's album urls: #{e}"
|
54
54
|
return nil
|
55
55
|
end
|
56
|
-
return
|
56
|
+
return urls
|
57
57
|
end
|
58
58
|
|
59
59
|
# Finds the following fields on an album's page:
|
data/metal-archives.gemspec
CHANGED
data/spec/metal-archives_spec.rb
CHANGED
@@ -26,22 +26,22 @@ describe "MetalArchives" do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
context "with a results page" do
|
29
|
-
it "should find the paginated result
|
29
|
+
it "should find the paginated result urls" do
|
30
30
|
agent = MetalArchives::Agent.new(2011)
|
31
31
|
agent.stub!(:search_by_year).and_return(@search_results)
|
32
32
|
|
33
|
-
|
33
|
+
urls = (1..16).collect do |i|
|
34
34
|
"/advanced.php?release_year=2011&p=#{i}"
|
35
35
|
end
|
36
|
-
agent.
|
36
|
+
agent.paginated_result_urls.should == urls
|
37
37
|
end
|
38
38
|
|
39
|
-
it "should find the album
|
39
|
+
it "should find the album urls" do
|
40
40
|
@mechanize.stub!(:get).and_return(@search_results)
|
41
41
|
agent = MetalArchives::Agent.new(2011)
|
42
42
|
agent.stub!(:search_by_year).and_return(@search_results)
|
43
43
|
|
44
|
-
|
44
|
+
urls = [
|
45
45
|
"release.php?id=296061", "release.php?id=295756", "release.php?id=294429", "release.php?id=295451", "release.php?id=295197",
|
46
46
|
"release.php?id=289824", "release.php?id=295519", "release.php?id=295457", "release.php?id=288298", "release.php?id=296048",
|
47
47
|
"release.php?id=290116", "release.php?id=295059", "release.php?id=291931", "release.php?id=296081", "release.php?id=295301",
|
@@ -53,7 +53,7 @@ describe "MetalArchives" do
|
|
53
53
|
"release.php?id=295806", "release.php?id=294017", "release.php?id=296098", "release.php?id=294092", "release.php?id=295551",
|
54
54
|
"release.php?id=290740", "release.php?id=295410", "release.php?id=293189", "release.php?id=296140", "release.php?id=291295"
|
55
55
|
]
|
56
|
-
agent.
|
56
|
+
agent.album_urls(agent.paginated_result_urls.first).should == urls
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -67,9 +67,9 @@ describe "MetalArchives" do
|
|
67
67
|
Mechanize.stub!(:new).and_return(@mechanize)
|
68
68
|
@mechanize.stub!(:get).and_return(@search_results)
|
69
69
|
agent = MetalArchives::Agent.new(2011)
|
70
|
-
|
70
|
+
album_url = "release.php?id=000001"
|
71
71
|
|
72
|
-
agent.album_from_url(
|
72
|
+
agent.album_from_url(album_url).should == {
|
73
73
|
:album => 'Fn-2+Fn-1=Fn',
|
74
74
|
:band => 'A Tree',
|
75
75
|
:label => 'Nazgûl Distro & Prod.',
|
@@ -88,9 +88,9 @@ describe "MetalArchives" do
|
|
88
88
|
Mechanize.stub!(:new).and_return(@mechanize)
|
89
89
|
@mechanize.stub!(:get).and_return(@search_results)
|
90
90
|
agent = MetalArchives::Agent.new(2011)
|
91
|
-
|
91
|
+
album_url = "release.php?id=000001"
|
92
92
|
|
93
|
-
agent.album_from_url(
|
93
|
+
agent.album_from_url(album_url).should == {
|
94
94
|
:album => 'Flesh Torn in Twilight',
|
95
95
|
:band => 'Acephalix',
|
96
96
|
:label => 'Deific Mourning',
|
@@ -109,9 +109,9 @@ describe "MetalArchives" do
|
|
109
109
|
Mechanize.stub!(:new).and_return(@mechanize)
|
110
110
|
@mechanize.stub!(:get).and_return(@search_results)
|
111
111
|
agent = MetalArchives::Agent.new(2011)
|
112
|
-
|
112
|
+
album_url = "release.php?id=000001"
|
113
113
|
|
114
|
-
agent.album_from_url(
|
114
|
+
agent.album_from_url(album_url).should == {
|
115
115
|
:album => 'The Mirror of Deliverance',
|
116
116
|
:band => 'A Dream of Poe',
|
117
117
|
:label => 'ARX Productions',
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Danny Olson
|
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
143
|
requirements:
|
144
144
|
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
hash:
|
146
|
+
hash: 3280097642105159980
|
147
147
|
segments:
|
148
148
|
- 0
|
149
149
|
version: "0"
|