bandcamp-discover 0.6.1 → 0.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2f1f8a4daa65012813a3a09bd62db1afc77e51751f14d9f69fa39ecfb144dab
4
- data.tar.gz: f0311426fe47b54f71c722869395a9b435f63b13085e3c6779e0b82d40e81a77
3
+ metadata.gz: 0e4dc43f9146747097ff3c34b9a581e02e96ad6e3dc812b84e7c77f1dd459147
4
+ data.tar.gz: 208fdb4ae22424fb73d93722bbbb1158703a89c4626a4897dbfb79a5dffa32b1
5
5
  SHA512:
6
- metadata.gz: ff76b0b9b44909e568340ad18db61ed52af685391e9607ea88478bb23ba8feb346a96504a9624b9aed68b5c17b2f074bf38a2c9d26dde9f215c36b803a360bbc
7
- data.tar.gz: 503083930726ae15941c4cbcf63a7783aed3c921c4f25af1745e1ef684481743f69efd4d87cae53c0ec572df95fdcd7ac197ac69291a59b9e9f4f2a94c9a688a
6
+ metadata.gz: 615dd28ade655b5c351249c4e98d1088102bb85d9ad002ca4e0396f49b60bd33c5fe058198f366dab1300f825e2e858a721e5ce715f866a77ce6a6f3afac8b32
7
+ data.tar.gz: 6cc60964b92fd4cbc56544c13606397632fd526b4871cd1ae28feaa3cfcde54b1cbf7c6483c9c613e10e09a876a582d42f9d7890575cb0fb097fd5e351cdd3ed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bandcamp-discover (0.6.1)
4
+ bandcamp-discover (0.7.0)
5
5
  async
6
6
  base64
7
7
  concurrent-ruby
data/README.rdoc CHANGED
@@ -17,7 +17,9 @@ accepts demos. The model and both prompts can be set by the host app:
17
17
  Before the bio is asked, the /music grid is read: a page whose releases carry
18
18
  no artist credit other than the owner is an artist, not a label, and is
19
19
  rejected without a model call. The credits that remain are appended to the
20
- bio for the model and returned as +artists+ in the scrape result.
20
+ bio for the model and returned as +artists+ in the scrape result; each
21
+ entry in +albums+ carries its own credit as +artist+ (nil when the release
22
+ is credited to the page owner).
21
23
 
22
24
  Without a token, +label?+ falls back to matching /label|platform|records/i
23
25
  and +accepts_demos?+ is always false.
@@ -31,7 +31,7 @@ module BandcampDiscover
31
31
  items.map do |item|
32
32
  {
33
33
  url: absolute(item.query_selector("a")[:href]),
34
- credit: item.query_selector(".artist-override")&.inner_text
34
+ credit: item.query_selector(".artist-override")&.inner_text&.strip
35
35
  }
36
36
  end
37
37
  end
@@ -41,6 +41,9 @@ module BandcampDiscover
41
41
  Roster.new(band_name: band_name, credits: grid.map { _1[:credit] }, releases: grid.size)
42
42
  end
43
43
 
44
+ # Each album carries the credit its grid item showed: the artist's name,
45
+ # or nil when the release is credited to the page owner. The grid is the
46
+ # only place the credit appears without another page load.
44
47
  def albums(grid)
45
48
  guarded do
46
49
  semaphore = Async::Semaphore.new(@max_tasks)
@@ -53,12 +56,12 @@ module BandcampDiscover
53
56
 
54
57
  puts "done scraping #{item[:url]}"
55
58
 
56
- album
59
+ [item, album]
57
60
  end
58
61
  end.map(&:wait)
59
62
 
60
- albums.map! do |album_url, album_title, album_tags, album_player|
61
- {url: album_url, title: album_title, tags: album_tags, player_url: album_player}
63
+ albums.map! do |item, (album_url, album_title, album_tags, album_player)|
64
+ {url: album_url, title: album_title, tags: album_tags, player_url: album_player, artist: item[:credit]}
62
65
  end
63
66
 
64
67
  [albums, normalize_tally(albums.map { _1[:tags] }.flatten.tally)]
@@ -1,3 +1,3 @@
1
1
  module BandcampDiscover
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -0,0 +1,46 @@
1
+ require_relative "test_helper"
2
+ require "bandcamp-discover/scrapers/music"
3
+
4
+ # The album pages are stubbed; what is under test is how the grid's credits
5
+ # travel into the album hashes.
6
+ class MusicTest < Minitest::Test
7
+ Music = BandcampDiscover::Scrapers::Music
8
+
9
+ FakeBrowser = Struct.new(:pages) do
10
+ def new_page = nil
11
+ end
12
+
13
+ FakeAlbum = Struct.new(:url) do
14
+ def scrape = [url, "Title of #{url}", ["drone"], nil]
15
+ end
16
+
17
+ def setup
18
+ @music = Music.new(url: "https://kranky.bandcamp.com/music", browser: FakeBrowser.new, max_tasks: 2)
19
+ end
20
+
21
+ def test_each_album_carries_the_credit_from_its_grid_item
22
+ grid = [
23
+ {url: "https://kranky.bandcamp.com/album/one", credit: "Helen"},
24
+ {url: "https://kranky.bandcamp.com/album/two", credit: nil}
25
+ ]
26
+
27
+ albums, tags = BandcampDiscover::Scrapers::Album.stub(:new, ->(url:, **) { FakeAlbum.new(url) }) do
28
+ Sync { @music.albums(grid) }
29
+ end
30
+
31
+ assert_equal ["Helen", nil], albums.map { _1[:artist] }
32
+ assert_equal ["https://kranky.bandcamp.com/album/one", "https://kranky.bandcamp.com/album/two"], albums.map { _1[:url] }
33
+ assert_equal({"drone" => 1.0}, tags)
34
+ end
35
+
36
+ def test_a_timed_out_album_still_keeps_its_credit
37
+ grid = [{url: "https://kranky.bandcamp.com/album/gone", credit: "Helen"}]
38
+ timed_out = Struct.new(:url) { def scrape = nil }
39
+
40
+ albums, _tags = BandcampDiscover::Scrapers::Album.stub(:new, ->(url:, **) { timed_out.new(url) }) do
41
+ Sync { @music.albums(grid) }
42
+ end
43
+
44
+ assert_equal [{url: nil, title: nil, tags: nil, player_url: nil, artist: "Helen"}], albums
45
+ end
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bandcamp-discover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian RUbisch
@@ -206,6 +206,7 @@ files:
206
206
  - test/analyzer_test.rb
207
207
  - test/default_test.rb
208
208
  - test/discover_test.rb
209
+ - test/music_test.rb
209
210
  - test/roster_test.rb
210
211
  - test/test_helper.rb
211
212
  homepage: https://julianrubisch.at