bandcamp-discover 0.6.0 → 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: 0d06bbc06b837c9d82502a0d9e9a61d3d2062af141f2a19e28ff0cb3e7e3fe5d
4
- data.tar.gz: 2b2bbe5682ed207b8911f31a74e1a1a0b8bf471326509b35a3849527b39bcab7
3
+ metadata.gz: 0e4dc43f9146747097ff3c34b9a581e02e96ad6e3dc812b84e7c77f1dd459147
4
+ data.tar.gz: 208fdb4ae22424fb73d93722bbbb1158703a89c4626a4897dbfb79a5dffa32b1
5
5
  SHA512:
6
- metadata.gz: 70c78eccc21549dd9c08fe183ec8ddf6a11060d79e913891ebca47de23f01248a07e7b73e27ea5fb45ba463ea93469d98f8be7f7fdcf5e99576600d5f2992c2a
7
- data.tar.gz: d345ad2550cd0ea344d0310a2aa8bdf351a5a3b08b999a19395092e7669ba07b9d98d9ea18a96b7480c3e5d4e44774922db943d115c1ca066ab1592cc058ac6c
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.0)
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.
@@ -25,8 +25,12 @@ module BandcampDiscover
25
25
 
26
26
  private
27
27
 
28
+ # open_router raises on a missing token rather than returning nil, which
29
+ # turned the documented regex fallback into an exception.
28
30
  def llm?
29
31
  defined?(OpenRouter) && !!OpenRouter.configuration.access_token
32
+ rescue OpenRouter::ConfigurationError
33
+ false
30
34
  end
31
35
 
32
36
  def ask(prompt)
@@ -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.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -4,7 +4,18 @@ require "bandcamp-discover/analyzer"
4
4
  # OpenRouter is the host app's dependency, not this gem's, so a stand-in that
5
5
  # records the request is enough to prove what the Analyzer sends.
6
6
  module OpenRouter
7
- Configuration = Struct.new(:access_token)
7
+ class ConfigurationError < StandardError; end
8
+
9
+ # The real gem raises on a missing token instead of returning nil.
10
+ Configuration = Struct.new(:token) do
11
+ def access_token=(value)
12
+ self.token = value
13
+ end
14
+
15
+ def access_token
16
+ token or raise ConfigurationError, "OpenRouter access token missing!"
17
+ end
18
+ end
8
19
 
9
20
  def self.configuration
10
21
  @configuration ||= Configuration.new
@@ -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.0
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