musicz 0.0.1
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 +7 -0
- data/.github/workflows/ruby.yml +20 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/musicz.rb +12 -0
- data/lib/musicz/configuration.rb +62 -0
- data/lib/musicz/entities.rb +21 -0
- data/lib/musicz/entities/alias.rb +14 -0
- data/lib/musicz/entities/area.rb +18 -0
- data/lib/musicz/entities/area_reference.rb +14 -0
- data/lib/musicz/entities/area_relation.rb +17 -0
- data/lib/musicz/entities/artist.rb +29 -0
- data/lib/musicz/entities/artist_credit.rb +14 -0
- data/lib/musicz/entities/artist_list.rb +15 -0
- data/lib/musicz/entities/artist_reference.rb +14 -0
- data/lib/musicz/entities/disc_id.rb +12 -0
- data/lib/musicz/entities/error.rb +12 -0
- data/lib/musicz/entities/label_info_reference.rb +18 -0
- data/lib/musicz/entities/life_span.rb +13 -0
- data/lib/musicz/entities/media.rb +18 -0
- data/lib/musicz/entities/rating.rb +12 -0
- data/lib/musicz/entities/recording.rb +21 -0
- data/lib/musicz/entities/recording_list.rb +15 -0
- data/lib/musicz/entities/recording_reference.rb +13 -0
- data/lib/musicz/entities/release.rb +37 -0
- data/lib/musicz/entities/release_event.rb +13 -0
- data/lib/musicz/entities/release_group.rb +14 -0
- data/lib/musicz/entities/release_reference.rb +20 -0
- data/lib/musicz/entities/tag.rb +12 -0
- data/lib/musicz/entities/text_representation.rb +12 -0
- data/lib/musicz/entities/track.rb +17 -0
- data/lib/musicz/entity.rb +22 -0
- data/lib/musicz/request.rb +37 -0
- data/lib/musicz/search.rb +6 -0
- data/lib/musicz/search/area_repository.rb +16 -0
- data/lib/musicz/search/artist_repository.rb +36 -0
- data/lib/musicz/search/options/artist_query_terms.rb +29 -0
- data/lib/musicz/search/options/id_search.rb +15 -0
- data/lib/musicz/search/options/recording_query_terms.rb +14 -0
- data/lib/musicz/search/recording_repository.rb +36 -0
- data/lib/musicz/search/repository.rb +93 -0
- data/lib/musicz/types.rb +9 -0
- data/lib/musicz/version.rb +5 -0
- data/musicz.gemspec +43 -0
- metadata +236 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
require "musicz/entities/artist_reference"
|
5
|
+
|
6
|
+
module Musicz
|
7
|
+
module Entities
|
8
|
+
class ArtistCredit < Entity
|
9
|
+
attribute :name, Types::Strict::String
|
10
|
+
attribute? :joinphrase, Types::Strict::String.optional
|
11
|
+
attribute? :artist, ArtistReference
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
require "musicz/entities/artist"
|
5
|
+
|
6
|
+
module Musicz
|
7
|
+
module Entities
|
8
|
+
class ArtistList < Entity
|
9
|
+
attribute :created, Types::Strict::String
|
10
|
+
attribute :count, Types::JSON::Decimal
|
11
|
+
attribute :offset, Types::JSON::Decimal
|
12
|
+
attribute :artists, Types::Array.of(Artist)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
|
5
|
+
module Musicz
|
6
|
+
module Entities
|
7
|
+
class ArtistReference < Entity
|
8
|
+
attribute :id, Types::Strict::String
|
9
|
+
attribute :name, Types::Strict::String
|
10
|
+
attribute? :sort_name, Types::Strict::String.optional
|
11
|
+
attribute? :disambiguation, Types::Strict::String.optional
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
|
5
|
+
module Musicz
|
6
|
+
module Entities
|
7
|
+
class LabelInfoReference < Entity
|
8
|
+
attribute :label do
|
9
|
+
attribute :id, Types::Strict::String
|
10
|
+
attribute :name, Types::Strict::String
|
11
|
+
attribute :sort_name, Types::Strict::String
|
12
|
+
attribute? :label_code, Types::Strict::String.optional
|
13
|
+
attribute? :disambiguation, Types::Strict::String.optional
|
14
|
+
end
|
15
|
+
attribute? :catalog_number, Types::Strict::String.optional
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
|
5
|
+
module Musicz
|
6
|
+
module Entities
|
7
|
+
class LifeSpan < Entity
|
8
|
+
attribute :ended, Types::Strict::Bool.default(false)
|
9
|
+
attribute? :begin, Types::Strict::String.optional
|
10
|
+
attribute? :end, Types::Strict::String.optional
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
require "musicz/entities/disc_id"
|
5
|
+
require "musicz/entities/track"
|
6
|
+
|
7
|
+
module Musicz
|
8
|
+
module Entities
|
9
|
+
class Media < Entity
|
10
|
+
attribute :track_offset, Types::Strict::Integer
|
11
|
+
attribute :track_count, Types::Strict::Integer
|
12
|
+
attribute :title, Types::Strict::String
|
13
|
+
attribute :format, Types::Strict::String
|
14
|
+
attribute :discids, Types::Array.of(DiscId).default([].freeze)
|
15
|
+
attribute :tracks, Types::Array.of(Track).default([].freeze)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
require "musicz/entities/artist_credit"
|
5
|
+
require "musicz/entities/release_reference"
|
6
|
+
|
7
|
+
module Musicz
|
8
|
+
module Entities
|
9
|
+
class Recording < Entity
|
10
|
+
attribute :id, Types::Strict::String
|
11
|
+
attribute :title, Types::Strict::String
|
12
|
+
attribute? :disambiguation, Types::Strict::String.optional
|
13
|
+
attribute? :score, Types::Strict::Integer.optional
|
14
|
+
attribute? :artist_credit, Types::Array.of(ArtistCredit)
|
15
|
+
attribute? :length, Types::JSON::Decimal.optional
|
16
|
+
attribute? :isrcs, Types::Array.of(Types::Strict::String)
|
17
|
+
.default([].freeze)
|
18
|
+
attribute? :releases, Types::Array.of(ReleaseReference)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
require "musicz/entities/recording"
|
5
|
+
|
6
|
+
module Musicz
|
7
|
+
module Entities
|
8
|
+
class RecordingList < Entity
|
9
|
+
attribute :created, Types::Strict::String
|
10
|
+
attribute :count, Types::JSON::Decimal
|
11
|
+
attribute :offset, Types::JSON::Decimal
|
12
|
+
attribute :recordings, Types::Array.of(Recording)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
|
5
|
+
module Musicz
|
6
|
+
module Entities
|
7
|
+
class RecordingReference < Entity
|
8
|
+
attribute :id, Types::Strict::String
|
9
|
+
attribute :title, Types::Strict::String
|
10
|
+
attribute? :disambiguation, Types::Strict::String.optional
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
require "musicz/entities/text_representation"
|
5
|
+
require "musicz/entities/artist_credit"
|
6
|
+
require "musicz/entities/label_info_reference"
|
7
|
+
require "musicz/entities/media"
|
8
|
+
|
9
|
+
module Musicz
|
10
|
+
module Entities
|
11
|
+
class Release < Entity
|
12
|
+
attribute :id, Types::Strict::String
|
13
|
+
attribute :title, Types::Strict::String
|
14
|
+
attribute? :date, Types::Strict::String.optional
|
15
|
+
attribute? :text_representation, TextRepresentation.optional
|
16
|
+
attribute? :country, Types::Strict::String.optional
|
17
|
+
attribute? :status, Types::Strict::String.optional
|
18
|
+
attribute? :quality, Types::Strict::String.optional
|
19
|
+
attribute? :packaging, Types::Strict::String.optional
|
20
|
+
attribute? :barcode, Types::Strict::String.optional
|
21
|
+
attribute? :status_id, Types::Strict::String.optional
|
22
|
+
attribute? :artist_credit, Types::Array.of(ArtistCredit)
|
23
|
+
attribute? :label_info, Types::Array.of(LabelInfoReference)
|
24
|
+
attribute? :asin, Types::Strict::String.optional
|
25
|
+
attribute? :disambiguation, Types::Strict::String.optional
|
26
|
+
attribute? :media, Media.optional
|
27
|
+
|
28
|
+
attribute? :release_group do
|
29
|
+
attribute :id, Types::Strict::String
|
30
|
+
attribute :primary_type, Types::Strict::String
|
31
|
+
end
|
32
|
+
|
33
|
+
attribute :release_events, Types::Array.of(ReleaseEvent)
|
34
|
+
.default([].freeze)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
|
5
|
+
module Musicz
|
6
|
+
module Entities
|
7
|
+
class ReleaseGroup < Entity
|
8
|
+
attribute :id, Types::Strict::String
|
9
|
+
attribute :type_id, Types::Strict::String
|
10
|
+
attribute? :title, Types::Strict::String.optional
|
11
|
+
attribute? :primary_type, Types::Strict::String.optional
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
require "musicz/entities/text_representation"
|
5
|
+
require "musicz/entities/release_event"
|
6
|
+
require "musicz/entities/release_group"
|
7
|
+
|
8
|
+
module Musicz
|
9
|
+
module Entities
|
10
|
+
class ReleaseReference < Entity
|
11
|
+
attribute :id, Types::Strict::String
|
12
|
+
attribute :title, Types::Strict::String
|
13
|
+
attribute? :status, Types::Strict::String.optional
|
14
|
+
attribute? :disambiguation, Types::Strict::String.optional
|
15
|
+
attribute? :date, Types::Strict::String.optional
|
16
|
+
attribute? :country, Types::Strict::String.optional
|
17
|
+
attribute? :release_group, ReleaseGroup.optional
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entity"
|
4
|
+
require "musicz/entities/recording_reference"
|
5
|
+
require "musicz/entities/artist_credit"
|
6
|
+
|
7
|
+
module Musicz
|
8
|
+
module Entities
|
9
|
+
class Track < Entity
|
10
|
+
attribute :number, Types::Strict::String
|
11
|
+
attribute :length, Types::Strict::Integer
|
12
|
+
attribute :title, Types::Strict::String
|
13
|
+
attribute :recording, RecordingReference
|
14
|
+
attribute :artist_credit, ArtistCredit
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry-struct"
|
4
|
+
require "musicz/types"
|
5
|
+
|
6
|
+
module Musicz
|
7
|
+
class Entity < Dry::Struct
|
8
|
+
transform_keys do |key|
|
9
|
+
key.to_s.tr("-", "_").to_sym
|
10
|
+
end
|
11
|
+
|
12
|
+
transform_types do |type|
|
13
|
+
if type.default?
|
14
|
+
type.constructor do |value|
|
15
|
+
value.nil? ? Dry::Types::Undefined : value
|
16
|
+
end
|
17
|
+
else
|
18
|
+
type
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "typhoeus"
|
5
|
+
|
6
|
+
module Musicz
|
7
|
+
class Request
|
8
|
+
def self.default_config
|
9
|
+
Musicz.config
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.build(config: default_config)
|
13
|
+
new(config: config)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(config:)
|
17
|
+
@config = config
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(endpoint:, parameters:)
|
21
|
+
url = "#{uri(endpoint)}?#{URI.encode_www_form(parameters)}"
|
22
|
+
Typhoeus.get(url, headers: headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def headers
|
28
|
+
{
|
29
|
+
"User-Agent" => "#{@config.app_name} #{@config.contact}"
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def uri(endpoint)
|
34
|
+
"#{@config.base_uri}/#{endpoint}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/search/repository"
|
4
|
+
require "musicz/entities/area"
|
5
|
+
|
6
|
+
module Musicz
|
7
|
+
module Search
|
8
|
+
class AreaRepository < Repository
|
9
|
+
ENDPOINT = "area"
|
10
|
+
|
11
|
+
def by_id(id_options)
|
12
|
+
by_id_with_entity(id_options, ENDPOINT, Musicz::Entities::Area)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "musicz/entities/artist_list"
|
4
|
+
require "musicz/entities/artist"
|
5
|
+
require "musicz/search/repository"
|
6
|
+
|
7
|
+
module Musicz
|
8
|
+
module Search
|
9
|
+
class ArtistRepository < Repository
|
10
|
+
ENDPOINT = "artist"
|
11
|
+
|
12
|
+
# @param id_options [Musicz::Search::Options::IdSearch]
|
13
|
+
def by_id(id_options)
|
14
|
+
by_id_with_entity(id_options, ENDPOINT, Musicz::Entities::Artist)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param term [String] The general term to searh MusicBrainz for
|
18
|
+
# This gets executed on the MusicBrainz server by querying
|
19
|
+
# the artist, sortname and alias fields
|
20
|
+
def by_term(term)
|
21
|
+
by_term_with_entity(term, ENDPOINT, Musicz::Entities::ArtistList)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param query_terms [Musicz::Search::Options::ArtistQueryTerms]
|
25
|
+
# This executes a generic query against the MusicBrainz API
|
26
|
+
# No support for paging, so use decently specific queries
|
27
|
+
def by_query(query_terms)
|
28
|
+
by_query_with_entity(
|
29
|
+
query_terms,
|
30
|
+
ENDPOINT,
|
31
|
+
Musicz::Entities::ArtistList
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|