! Copyright (C) 2020 . ! See http://factorcode.org/license.txt for BSD license. USING: kernel io.sockets.secure http http.client urls strings alien.syntax accessors arrays sequences xml.syntax xml.traversal assocs slots calendar words calendar.parser combinators io.streams.string furnace.utilities splitting qw hashtables ; USING: io prettyprint ; USING: musicbrainz.entities musicbrainz.parser ; IN: musicbrainz CONSTANT: mb-base-url URL" https://musicbrainz.org/ws/2/" CONSTANT: user-agent-header { "factor-musicbrainz/0.1.0 (steve@ayerh.art)" "user-agent" } CONSTANT: accept-header { "application/xml" "accept" } CONSTANT: collection-links qw{ releases } : mb-entity>string ( entity -- str ) word>string ":" split last ; : ( mbid entity inc -- url ) [ word>string ":" split last swap 2array "/" join mb-base-url clone swap >url derive-url ] dip "+" join "inc" set-query-param ; : ( mbid -- url ) release qw{ artist-credits recordings labels aliases } ; : ( mbid -- url ) artist qw{ aliases } ; : ( mbid -- url ) "/releases" append collection qw{ artist-credits releases } ; : ( url -- request ) user-agent-header first2 set-header accept-header first2 set-header http-request nip parse-mb-response ; : add-mb-headers ( url -- url ) user-agent-header first2 set-header accept-header first2 set-header ; : ( mbid -- release ) ; : ( mbid -- artist ) ; : ( mbid -- collection ) ; : ( mbid -- url ) [ mb-base-url clone "release" >url derive-url ] dip "collection" set-query-param "100" "limit" set-query-param ; : ( mbid -- releases ) ; : ( user -- collections ) [ mb-base-url clone "collection" >url derive-url ] dip "editor" set-query-param add-mb-headers http-request nip parse-mb-response ;