### Lookup Works by ISWC Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Fetches all works that share a given ISWC. No specific includes are demonstrated in this example. ```go ctx := context.Background() result, err := client.LookupISWC(ctx, "T-010.433.166-0", musicbrainzws2.IncludesFilter{}, ) if err != nil { log.Fatal(err) } for _, work := range result.Works { fmt.Printf("Work: %s (%s)\n", work.Title, work.Type) } ``` -------------------------------- ### Lookup Release Group by MBID Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Fetches a single release group by its MBID. Can include artist credits and releases. Useful for getting release group details and associated releases. ```go ctx := context.Background() rg, err := client.LookupReleaseGroup(ctx, "f5093c06-23e3-404f-aeaa-40f72885ee3a", // The Dark Side of the Moon (RG) musicbrainzws2.IncludesFilter{ Includes: []string{"artist-credits", "releases"}, }, ) if err != nil { log.Fatal(err) } fmt.Printf("%s (%s, %s)\n", rg.Title, rg.PrimaryType, rg.FirstReleaseDate) for _, r := range rg.Releases { fmt.Printf(" - %s [%s] %s\n", r.Title, r.CountryCode, r.Date) } ``` -------------------------------- ### Summarize Release Media Formats in Go Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Produce a compact summary string of release media formats (e.g., "4×CD + DVD"). Also shows how to iterate through individual media details. ```go release, _ := client.LookupRelease(ctx, mbid, musicbrainzws2.IncludesFilter{Includes: []string{"media"}}) // e.g. "2×CD + Blu-ray" fmt.Println(release.Media.String()) for _, medium := range release.Media { fmt.Printf("Disc %d: %s, %d tracks\n", medium.Position, medium.Format, medium.TrackCount) } ``` -------------------------------- ### Create MusicBrainz Client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Initializes a MusicBrainz API client with built-in rate-limit handling and a custom User-Agent. Use `NewWithHTTPClient` for custom HTTP client configurations like proxies or TLS settings. The client should be closed when no longer needed. ```go package main import ( "context" "fmt" "log" "time" "go.uploadedlobster.com/musicbrainzws2" ) func main() { client := musicbrainzws2.NewClient(musicbrainzws2.AppInfo{ Name: "MyMusicApp", Version: "1.0.0", URL: "https://example.com/mymusicapp", }) defer client.Close() // Optionally point at a different MusicBrainz instance // client.SetBaseURL("https://beta.musicbrainz.org/ws/2/") ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() artist, err := client.LookupArtist(ctx, "65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab", // David Bowie musicbrainzws2.IncludesFilter{Includes: []string{"aliases", "tags"}}, ) if err != nil { log.Fatal(err) } fmt.Println(artist.Name, "-", artist.Disambiguation) // Output: David Bowie - rock musician } ``` -------------------------------- ### NewClient — Create a client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Creates a *Client with built-in rate-limit handling and a meaningful User-Agent as required by MusicBrainz. NewWithHTTPClient accepts a custom *http.Client for proxy or TLS customisation. ```APIDOC ## NewClient ### Description Creates a `*Client` with built-in rate-limit handling and a meaningful `User-Agent` as required by MusicBrainz. `NewWithHTTPClient` accepts a custom `*http.Client` for proxy or TLS customisation. ### Usage ```go package main import ( "context" "fmt" "log" "time" "go.uploaded lobster.com/musicbrainzws2" ) func main() { client := musicbrainzws2.NewClient(musicbrainzws2.AppInfo{ Name: "MyMusicApp", Version: "1.0.0", URL: "https://example.com/mymusicapp", }) defer client.Close() // Optionally point at a different MusicBrainz instance // client.SetBaseURL("https://beta.musicbrainz.org/ws/2/") ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() artist, err := client.LookupArtist(ctx, "65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab", // David Bowie musicbrainzws2.IncludesFilter{Includes: []string{"aliases", "tags"}}, ) if err != nil { log.Fatal(err) } fmt.Println(artist.Name, "- ", artist.Disambiguation) // Output: David Bowie - rock musician } ``` ``` -------------------------------- ### Format Artist Credits as String in Go Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Generate a human-readable display string for artist credits, including join phrases. Also demonstrates iterating through individual credited artists. ```go release, _ := client.LookupRelease(ctx, mbid, musicbrainzws2.IncludesFilter{Includes: []string{"artist-credits"}}) // Prints "Simon & Garfunkel" (join phrases included) fmt.Println(release.ArtistCredit.String()) // Iterate individual credits for _, entry := range release.ArtistCredit { fmt.Printf(" Artist MBID: %s, Credited as: %s\n", entry.Artist.ID, entry.Name) } ``` -------------------------------- ### Fetch All Genres with MusicBrainzWS2 Go Client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Use this to retrieve all genres from the MusicBrainz database. The results are paginated alphabetically. Ensure to handle pagination correctly to fetch all genres. ```go ctx := context.Background() paginator := musicbrainzws2.Paginator{Offset: 0, Limit: musicbrainzws2.MaxLimit} for { result, err := client.AllGenres(ctx, paginator) if err != nil { log.Fatal(err) } for _, g := range result.Genres { fmt.Printf("%s (%s)\n", g.Name, g.ID) } if paginator.Offset+len(result.Genres) >= result.Count { break } paginator = paginator.Next() } ``` -------------------------------- ### Search Releases with MusicBrainzWS2 Go Client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Use this to perform full-text searches on releases. Specify query parameters like release title, artist, and status. ```go ctx := context.Background() result, err := client.SearchReleases(ctx, musicbrainzws2.SearchFilter{ Query: `release:"Abbey Road" AND artist:"Beatles" AND status:official`, }, musicbrainzws2.Paginator{Offset: 0, Limit: 10}, ) if err != nil { log.Fatal(err) } for _, r := range result.Releases { fmt.Printf(" [%d%%] %s – %s – %s (%s)\n", r.Score, r.ArtistCredit, r.Title, r.Date, r.CountryCode) } ``` -------------------------------- ### Configure Authentication for MusicBrainz Client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Sets up authentication for the MusicBrainz client. Use `SetDigestAuth` for username/password credentials or `SetAuthToken` for an OAuth2 Bearer token. Authentication is necessary for submission endpoints and user-specific data. ```go client := musicbrainzws2.NewClient(musicbrainzws2.AppInfo{ Name: "MyApp", Version: "1.0", }) defer client.Close() // Option A: Digest auth client.SetDigestAuth("mb-username", "mb-password") // Option B: OAuth2 Bearer token (token obtained externally via OAuth2 flow) client.SetAuthToken("your-oauth2-access-token") ``` -------------------------------- ### Handle MusicBrainz API Errors in Go Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Demonstrates structured error handling for API calls, distinguishing between MusicBrainz ClientErrors (with status codes) and network errors. ```go artist, err := client.LookupArtist(ctx, "invalid-mbid", musicbrainzws2.IncludesFilter{}) if err != nil { if cerr, ok := err.(*musicbrainzws2.ClientError); ok { switch cerr.StatusCode { case 400: fmt.Println("Bad request:", cerr.Message) case 401: fmt.Println("Unauthorized – check credentials") case 404: fmt.Println("Entity not found") case 503: fmt.Println("Service unavailable – will be retried automatically") default: fmt.Printf("API error %d: %s\n", cerr.StatusCode, cerr.Message) } } else { fmt.Println("Network error:", err) } } ``` -------------------------------- ### Lookup Release by MBID Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Fetches a detailed `Release` struct using its MBID. This includes optional information such as media details, label information, cover art status, and artist credits. Errors during the lookup are handled by checking the returned error. ```go ctx := context.Background() release, err := client.LookupRelease(ctx, "b84ee12a-09ef-421b-82de-0441a926375b", // Dark Side of the Moon (original UK) musicbrainzws2.IncludesFilter{ Includes: []string{"artist-credits", "labels", "discids", "media", "recordings"}, }, ) if err != nil { log.Fatal(err) } fmt.Printf("Title : %s\n", release.Title) fmt.Printf("Artist : %s\n", release.ArtistCredit) // ArtistCredit.String() fmt.Printf("Date : %s\n", release.Date) fmt.Printf("Status : %s\n", release.Status) fmt.Printf("Media : %s\n", release.Media) // MediaList.String(), e.g. "CD" for i, medium := range release.Media { fmt.Printf(" Disc %d (%s): %d tracks\n", i+1, medium.Format, medium.TrackCount) for _, track := range medium.Tracks { fmt.Printf(" %s. %s (%s)\n", track.Number, track.Title, track.Length) } } ``` -------------------------------- ### MediaList.String Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Summarize release media formats. Implements String() for a compact disc-format summary. ```APIDOC ## MediaList.String — Summarise release media formats `MediaList` implements `String()` to produce a compact disc-format summary, e.g. `"4×CD + DVD"`. ```go release, _ := client.LookupRelease(ctx, mbid, musicbrainzws2.IncludesFilter{Includes: []string{"media"}}, ) // e.g. "2×CD + Blu-ray" fmt.Println(release.Media.String()) for _, medium := range release.Media { fmt.Printf("Disc %d: %s, %d tracks\n", medium.Position, medium.Format, medium.TrackCount) } ``` ``` -------------------------------- ### Browse URLs by Target Resource Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Use this to retrieve URL entities for a given resource. It supports filtering by resources and including related information like artist relationships. ```go ctx := context.Background() result, err := client.BrowseURLs(ctx, musicbrainzws2.URLFilter{ Resources: []string{"https://www.discogs.com/artist/301-Pink-Floyd"}, Includes: []string{"artist-rels"}, }, musicbrainzws2.DefaultPaginator(), ) if err != nil { log.Fatal(err) } for _, u := range result.URLs { fmt.Printf("URL: %s (ID: %s)\n", u.Resource, u.ID) for _, rel := range u.RelationList.Relations { fmt.Printf(" -> %s %s\n", rel.TargetType, rel.Type) } } ``` -------------------------------- ### Browse Artists by Release MBID with MusicBrainzWS2 Go Client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Use this to find artists associated with a specific release MBID. You can also include related data like aliases. ```go ctx := context.Background() // Artists on a specific release result, err := client.BrowseArtists(ctx, musicbrainzws2.ArtistFilter{ ReleaseMBID: "b84ee12a-09ef-421b-82de-0441a926375b", Includes: []string{"aliases"}, }, musicbrainzws2.DefaultPaginator(), ) if err != nil { log.Fatal(err) } fmt.Printf("Found %d artist(s):\n", result.Count) for _, a := range result.Artists { fmt.Printf(" %s (%s)\n", a.Name, a.Type) } ``` -------------------------------- ### Search Recordings with MusicBrainzWS2 Go Client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Use this to perform full-text searches on recordings. You can filter by recording title, artist, and duration. ```go ctx := context.Background() result, err := client.SearchRecordings(ctx, musicbrainzws2.SearchFilter{ Query: `recording:"Bohemian Rhapsody" AND artist:"Queen" AND dur:[354000 TO 358000]`, }, musicbrainzws2.DefaultPaginator(), ) if err != nil { log.Fatal(err) } for _, rec := range result.Recordings { fmt.Printf(" [%d%%] %s - %s (%s)\n", rec.Score, rec.ArtistCredit, rec.Title, rec.Length) } ``` -------------------------------- ### Browse Recordings by Artist MBID with MusicBrainzWS2 Go Client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Use this to browse recordings by a specific artist MBID. You can include ISRCs and artist credits. ```go ctx := context.Background() result, err := client.BrowseRecordings(ctx, musicbrainzws2.RecordingFilter{ ArtistMBID: "65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab", Includes: []string{"isrcs", "artist-credits"}, }, musicbrainzws2.Paginator{Offset: 0, Limit: 50}, ) if err != nil { log.Fatal(err) } for _, rec := range result.Recordings { fmt.Printf(" %s (%s) ISRCs: %v\n", rec.Title, rec.Length, rec.ISRCs) } ``` -------------------------------- ### Lookup Work by MBID Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Fetches a single work by its MBID. Can include artist relations and recording relations. Returns work details like title, type, languages, and ISWCs. ```go ctx := context.Background() work, err := client.LookupWork(ctx, "b1df2cf3-69ea-3b76-9b91-a36a4a599c06", musicbrainzws2.IncludesFilter{ Includes: []string{"artist-rels", "recording-rels"}, }, ) if err != nil { log.Fatal(err) } fmt.Printf("Title: %s\nType: %s\nLanguages: %v\nISWCs: %v\n", work.Title, work.Type, work.Languages, work.ISWCs) ``` -------------------------------- ### AllGenres Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Retrieves all genres from the MusicBrainz database, returned in a paginated, alphabetical order. ```APIDOC ## AllGenres — Browse all MusicBrainz genres ### Description Retrieves all genres in the MusicBrainz database, paginated alphabetically. ### Method `AllGenres` ### Parameters - `ctx` (context.Context) - The context for the request. - `paginator` (musicbrainzws2.Paginator) - Pagination settings for the results, with `Offset` and `Limit`. ### Request Example ```go ctx := context.Background() paginator := musicbrainzws2.Paginator{Offset: 0, Limit: musicbrainzws2.MaxLimit} for { result, err := client.AllGenres(ctx, paginator) // ... process result.Genres ... if paginator.Offset+len(result.Genres) >= result.Count { break } paginator = paginator.Next() } ``` ### Response - `result` (*musicbrainzws2.AllGenresResult) - Contains a list of genres and the total count. - `err` (error) - An error if the request failed. ``` -------------------------------- ### Paginate Search Results in Go Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Iterate through large result sets by using the Paginator. Default settings are offset=0, limit=25. The maximum limit per request is 100. ```go ctx := context.Background() paginator := musicbrainzws2.DefaultPaginator() for { result, err := client.SearchRecordings(ctx, musicbrainzws2.SearchFilter{Query: `artist:"Beatles"`}, paginator, ) if err != nil { log.Fatal(err) } for _, rec := range result.Recordings { fmt.Printf(" %s – %s\n", rec.ArtistCredit, rec.Title) } fetched := paginator.Offset + len(result.Recordings) if fetched >= result.Count { break } paginator = paginator.Next() } ``` -------------------------------- ### Browse Events by Artist MBID with MusicBrainzWS2 Go Client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Use this to browse events associated with a specific artist MBID. You can include aliases and tags. ```go ctx := context.Background() result, err := client.BrowseEvents(ctx, musicbrainzws2.EventFilter{ ArtistMBID: "83d91898-7763-47d7-b03b-b92132375c47", Includes: []string{"aliases", "tags"}, }, musicbrainzws2.DefaultPaginator(), ) if err != nil { log.Fatal(err) } for _, ev := range result.Events { fmt.Printf(" %s (%s – %s)\n", ev.Name, ev.LifeSpan.Begin, ev.LifeSpan.End) } ``` -------------------------------- ### Browse Release Groups by Artist MBID with MusicBrainzWS2 Go Client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Use this to browse release groups for a specific artist MBID. You can filter by type and status, and include artist credits. ```go ctx := context.Background() result, err := client.BrowseReleaseGroups(ctx, musicbrainzws2.ReleaseGroupFilter{ ArtistMBID: "83d91898-7763-47d7-b03b-b92132375c47", Type: "album", ReleaseGroupStatus: musicbrainzws2.ReleaseGroupStatusWebsiteDefault, Includes: []string{"artist-credits"}, }, musicbrainzws2.DefaultPaginator(), ) if err != nil { log.Fatal(err) } for _, rg := range result.ReleaseGroups { fmt.Printf(" %s – %s (%s)\n", rg.Title, rg.FirstReleaseDate, rg.PrimaryType) } ``` -------------------------------- ### Manage Collection Contents Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Adds or removes MBIDs from a collection. Requires the collection ID, entity type, and an authenticated client. Demonstrates both adding and removing. ```go ctx := context.Background() client.SetDigestAuth("myuser", "mypassword") collection := musicbrainzws2.Collection{ ID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", EntityType: "release", } toAdd := []mbtypes.MBID{ "b84ee12a-09ef-421b-82de-0441a926375b", "7c56ec6c-1f11-4d18-9254-46e8e6c8bbc3", } res, err := client.CollectionAdd(ctx, collection, toAdd) if err != nil { log.Fatal(err) } fmt.Println(res.Message) // "OK" // Remove the same releases res, err = client.CollectionRemove(ctx, collection, toAdd) if err != nil { log.Fatal(err) } fmt.Println(res.Message) // "OK" ``` -------------------------------- ### LookupRecording Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Lookup a single recording by MBID. Returns a Recording with ISRCs, artist credit, duration, first release date, and optionally linked releases. ```APIDOC ## LookupRecording — Lookup a single recording by MBID Returns a `Recording` with ISRCs, artist credit, duration, first release date, and optionally linked releases. ### Method Signature `client.LookupRecording(ctx context.Context, mbid string, inc IncludesFilter) (*Recording, error)` ### Parameters - **mbid** (string) - The MusicBrainz ID of the recording. - **inc** (IncludesFilter) - Filter to specify which related data to include (e.g., "artist-credits", "isrcs", "releases"). ### Request Example ```go ctx := context.Background() rec, err := client.LookupRecording(ctx, "f3c02ea4-5951-4943-9f22-efdca7d0c3e0", musicbrainzws2.IncludesFilter{Includes: []string{"artist-credits", "isrcs", "releases"}}) if err != nil { log.Fatal(err) } fmt.Printf("Title : %s\n", rec.Title) ``` ``` -------------------------------- ### LookupRelease — Lookup a single release by MBID Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Returns a full `Release` struct, including optional details such as media information, label data, cover art status, and artist credits. ```APIDOC ## LookupRelease ### Description Returns a full `Release` with optional media, label info, cover art status, artist credits, and more. ### Method `LookupRelease(ctx context.Context, mbid string, inc IncludesFilter) (*Release, error)` ### Parameters #### Path Parameters - **mbid** (string) - Required - The MusicBrainz ID of the release to look up. #### Query Parameters - **inc** (`IncludesFilter`) - Optional - Specifies which related entities to include in the response. Example: `musicbrainzws2.IncludesFilter{Includes: []string{"artist-credits", "labels"}}`. ### Request Example ```go ctx := context.Background() release, err := client.LookupRelease(ctx, "b84ee12a-09ef-421b-82de-0441a926375b", // Dark Side of the Moon (original UK) musicbrainzws2.IncludesFilter{ Includes: []string{"artist-credits", "labels", "discids", "media", "recordings"}, }, ) if err != nil { log.Fatal(err) } fmt.Printf("Title : %s\n", release.Title) fmt.Printf("Artist : %s\n", release.ArtistCredit) // ArtistCredit.String() fmt.Printf("Date : %s\n", release.Date) fmt.Printf("Status : %s\n", release.Status) fmt.Printf("Media : %s\n", release.Media) // MediaList.String(), e.g. "CD" for i, medium := range release.Media { fmt.Printf(" Disc %d (%s): %d tracks\n", i+1, medium.Format, medium.TrackCount) for _, track := range medium.Tracks { fmt.Printf(" %s. %s (%s)\n", track.Number, track.Title, track.Length) } } ``` ### Response #### Success Response (200) - **Release** (`*Release`) - A struct containing the release's details and requested includes. ``` -------------------------------- ### Browse Releases by Artist MBID with MusicBrainzWS2 Go Client Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Use this to browse releases by a specific artist MBID. You can filter by status and type, and include related data like labels and media. ```go ctx := context.Background() paginator := musicbrainzws2.Paginator{Offset: 0, Limit: musicbrainzws2.MaxLimit} result, err := client.BrowseReleases(ctx, musicbrainzws2.ReleaseFilter{ ArtistMBID: "83d91898-7763-47d7-b03b-b92132375c47", // Pink Floyd Status: "official", Type: "album", Includes: []string{"labels", "media"}, }, paginator, ) if err != nil { log.Fatal(err) } fmt.Printf("Total releases: %d\n", result.Count) for _, r := range result.Releases { fmt.Printf(" %s (%s) [%s] %s\n", r.Title, r.Date, r.CountryCode, r.Media) } ``` -------------------------------- ### ArtistCredit.String Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Format artist credits as a display string. Implements String() for human-readable output. ```APIDOC ## ArtistCredit.String — Format artist credits as a display string `ArtistCredit` implements `String()` to produce a human-readable credit string (e.g., `"Simon & Garfunkel"` or `"Lennon/McCartney"`). ```go release, _ := client.LookupRelease(ctx, mbid, musicbrainzws2.IncludesFilter{Includes: []string{"artist-credits"}}, ) // Prints "Simon & Garfunkel" (join phrases included) fmt.Println(release.ArtistCredit.String()) // Iterate individual credits for _, entry := range release.ArtistCredit { fmt.Printf(" Artist MBID: %s, Credited as: %s\n", entry.Artist.ID, entry.Name) } ``` ``` -------------------------------- ### BrowseURLs Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Browse URLs by target resource. When a single resource URL is provided, returns the URL entity directly. With multiple resources, it performs a standard browse. ```APIDOC ## BrowseURLs — Browse URLs by target resource When a single resource URL is provided, returns the `URL` entity directly. With multiple resources it performs a standard browse. ```go ctx := context.Background() result, err := client.BrowseURLs(ctx, musicbrainzws2.URLFilter{ Resources: []string{"https://www.discogs.com/artist/301-Pink-Floyd"}, Includes: []string{"artist-rels"}, }, musicbrainzws2.DefaultPaginator(), ) if err != nil { log.Fatal(err) } for _, u := range result.URLs { fmt.Printf("URL: %s (ID: %s)\n", u.Resource, u.ID) for _, rel := range u.RelationList.Relations { fmt.Printf(" -> %s %s\n", rel.TargetType, rel.Type) } } ``` ``` -------------------------------- ### BrowseReleaseCollection Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Browse releases inside a collection. Enumerates the entities stored in a typed MusicBrainz collection. ```APIDOC ## BrowseReleaseCollection — Browse releases inside a collection Enumerates the entities stored in a typed MusicBrainz collection. ```go ctx := context.Background() colMBID := mbtypes.MBID("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") result, err := client.BrowseReleaseCollection(ctx, colMBID, musicbrainzws2.IncludesFilter{Includes: []string{"artist-credits", "labels", "media"}}, musicbrainzws2.Paginator{Offset: 0, Limit: musicbrainzws2.MaxLimit}, ) if err != nil { log.Fatal(err) } fmt.Printf("Collection has %d releases:\n", result.Count) for _, r := range result.Releases { fmt.Printf(" %s – %s (%s)\n", r.ArtistCredit, r.Title, r.Date) } ``` ``` -------------------------------- ### Lookup Recording by MBID Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Retrieves a single recording by its MusicBrainz ID (MBID). Supports including artist credits, ISRCs, and releases. ```go ctx := context.Background() rec, err := client.LookupRecording(ctx, "f3c02ea4-5951-4943-9f22-efdca7d0c3e0", musicbrainzws2.IncludesFilter{ Includes: []string{"artist-credits", "isrcs", "releases"}, }, ) if err != nil { log.Fatal(err) } fmt.Printf("Title : %s\n", rec.Title) fmt.Printf("Artist : %s\n", rec.ArtistCredit) fmt.Printf("Duration : %s\n", rec.Length) for _, isrc := range rec.ISRCs { fmt.Printf("ISRC: %s\n", isrc) } ``` -------------------------------- ### Browse Releases Inside a Collection Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Enumerates entities within a MusicBrainz collection. Supports including details like artist credits, labels, and media. Requires a collection MBID. ```go ctx := context.Background() colMBID := mbtypes.MBID("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") result, err := client.BrowseReleaseCollection(ctx, colMBID, musicbrainzws2.IncludesFilter{Includes: []string{"artist-credits", "labels", "media"}}, musicbrainzws2.Paginator{Offset: 0, Limit: musicbrainzws2.MaxLimit}, ) if err != nil { log.Fatal(err) } fmt.Printf("Collection has %d releases:\n", result.Count) for _, r := range result.Releases { fmt.Printf(" %s – %s (%s)\n", r.ArtistCredit, r.Title, r.Date) } ``` -------------------------------- ### Lookup Recordings by ISRC Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Retrieves all recordings associated with a given ISRC code. Can include artist credits and releases for each recording. ```go ctx := context.Background() result, err := client.LookupISRC(ctx, "GBAYE0601477", musicbrainzws2.IncludesFilter{Includes: []string{"artist-credits", "releases"}}, ) if err != nil { log.Fatal(err) } fmt.Printf("ISRC: %s\n", result.ISRC) for _, rec := range result.Recordings { fmt.Printf(" %s - %s\n", rec.ArtistCredit, rec.Title) } ``` -------------------------------- ### Browse User Collections Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Fetches collections for the authenticated user or finds collections containing a specific entity. Requires setting digest authentication. ```go ctx := context.Background() client.SetDigestAuth("myuser", "mypassword") result, err := client.BrowseCollections(ctx, musicbrainzws2.CollectionFilter{ Editor: "myuser", Includes: []string{"user-collections"}, }, musicbrainzws2.Paginator{Limit: musicbrainzws2.MaxLimit}, ) if err != nil { log.Fatal(err) } for _, col := range result.Collections { fmt.Printf(" [%s] %s (%s) by %s\n", col.EntityType, col.Name, col.Type, col.Editor) } ``` -------------------------------- ### Lookup Label by MBID Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Retrieves a single label by its MBID. Supports including aliases and tags. Provides label details like name, type, country, and label code. ```go ctx := context.Background() label, err := client.LookupLabel(ctx, "46f0f4cd-8aab-4b33-b698-f459faf64190", // Harvest Records musicbrainzws2.IncludesFilter{ Includes: []string{"aliases", "tags"}, }, ) if err != nil { log.Fatal(err) } fmt.Printf("Name: %s\nType: %s\nCountry: %s\nLabel Code: %d\n", label.Name, label.Type, label.CountryCode, label.LabelCode) ``` -------------------------------- ### Lookup Artist by MBID Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Retrieves a complete `Artist` struct using their MusicBrainz ID (MBID). Include related sub-resources like aliases, tags, genres, ratings, relations, recordings, releases, release-groups, or works by using `IncludesFilter`. Handles potential errors during the lookup process. ```go ctx := context.Background() artist, err := client.LookupArtist(ctx, "83d91898-7763-47d7-b03b-b92132375c47", // Pink Floyd musicbrainzws2.IncludesFilter{ Includes: []string{"aliases", "tags", "genres", "ratings", "release-groups"}, }, ) if err != nil { log.Fatal(err) } fmt.Printf("Name: %s\nType: %s\nCountry: %s\n", artist.Name, artist.Type, artist.CountryCode) for _, tag := range artist.Tags { fmt.Printf(" tag: %s (%d)\n", tag.Name, tag.Count) } for _, rg := range artist.ReleaseGroups { fmt.Printf(" release group: %s (%s)\n", rg.Title, rg.PrimaryType) } // Output: // Name: Pink Floyd // Type: Group // Country: GB // tag: progressive rock (34) // ... // release group: The Dark Side of the Moon (Album) // ... ``` -------------------------------- ### SubmitISRCs Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Submit ISRCs for recordings. Associates ISRC codes with recording MBIDs. Requires authentication. ```APIDOC ## SubmitISRCs — Submit ISRCs for recordings Associates ISRC codes with recording MBIDs. Requires authentication. ```go ctx := context.Background() client.SetAuthToken("oauth2-bearer-token") isrcs := musicbrainzws2.RecordingISRCMap{ "f3c02ea4-5951-4943-9f22-efdca7d0c3e0": []mbtypes.ISRC{ "GBAYE0601477", "USAT29900609", }, } result, err := client.SubmitISRCs(ctx, isrcs) if err != nil { log.Fatal(err) } fmt.Println(result.Message) // "OK" ``` ``` -------------------------------- ### Submit Barcodes for Releases Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Submits EAN/UPC barcodes for releases. Requires authentication with an OAuth2 bearer token. Maps release MBIDs to their corresponding barcodes. ```go ctx := context.Background() client.SetAuthToken("oauth2-bearer-token") barcodes := musicbrainzws2.ReleaseBarcodeMap{ "b84ee12a-09ef-421b-82de-0441a926375b": "5099902987323", } result, err := client.SubmitBarcodes(ctx, barcodes) if err != nil { log.Fatal(err) } fmt.Println(result.Message) // "OK" ``` -------------------------------- ### SubmitBarcodes Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Submit barcodes for releases. ```APIDOC ## SubmitBarcodes — Submit barcodes for releases ```go ctx := context.Background() client.SetAuthToken("oauth2-bearer-token") barcodes := musicbrainzws2.ReleaseBarcodeMap{ "b84ee12a-09ef-421b-82de-0441a926375b": "5099902987323", } result, err := client.SubmitBarcodes(ctx, barcodes) if err != nil { log.Fatal(err) } fmt.Println(result.Message) // "OK" ``` ``` -------------------------------- ### BrowseEvents Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Browses events related to an entity, with options to include aliases and tags. ```APIDOC ## BrowseEvents — Browse events related to an entity ### Description Browses events related to a specified entity, with options for including aliases and tags. ### Method `BrowseEvents` ### Parameters - `ctx` (context.Context) - The context for the request. - `filter` (musicbrainzws2.EventFilter) - Filter criteria, can include `ArtistMBID`, `Includes`, etc. - `paginator` (musicbrainzws2.Paginator) - Pagination settings for the results. ### Request Example ```go ctx := context.Background() result, err := client.BrowseEvents(ctx, musicbrainzws2.EventFilter{ArtistMBID: "83d91898-7763-47d7-b03b-b92132375c47", Includes: []string{"aliases", "tags"}}, musicbrainzws2.DefaultPaginator()) ``` ### Response - `result` (*musicbrainzws2.BrowseEventsResult) - Contains a list of events and their details. - `err` (error) - An error if the request failed. ``` -------------------------------- ### Paginator Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Page through large result sets using the Paginator. Default is offset=0, limit=25. Max limit is 100. Use .Next() / .Prev() to navigate. ```APIDOC ## Paginator — Page through large result sets `DefaultPaginator()` returns offset=0, limit=25. `MaxLimit` (100) is the largest single-request limit. Use `.Next()` / `.Prev()` to navigate. ```go ctx := context.Background() paginator := musicbrainzws2.DefaultPaginator() for { result, err := client.SearchRecordings(ctx, musicbrainzws2.SearchFilter{Query: `artist:"Beatles"`}, paginator, ) if err != nil { log.Fatal(err) } for _, rec := range result.Recordings { fmt.Printf(" %s – %s\n", rec.ArtistCredit, rec.Title) } fetched := paginator.Offset + len(result.Recordings) if fetched >= result.Count { break } paginator = paginator.Next() } ``` ``` -------------------------------- ### LookupArtist — Lookup a single artist by MBID Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Fetches a complete `Artist` struct using their MusicBrainz ID (MBID). Optional `IncludesFilter` can be passed to request related sub-resources such as aliases, tags, genres, ratings, relations, recordings, releases, release-groups, or works. ```APIDOC ## LookupArtist ### Description Fetches a complete `Artist` struct. Pass `IncludesFilter` to request sub-resources like aliases, tags, genres, ratings, relations, recordings, releases, release-groups, or works. ### Method `LookupArtist(ctx context.Context, mbid string, inc IncludesFilter) (*Artist, error)` ### Parameters #### Path Parameters - **mbid** (string) - Required - The MusicBrainz ID of the artist to look up. #### Query Parameters - **inc** (`IncludesFilter`) - Optional - Specifies which related entities to include in the response. Example: `musicbrainzws2.IncludesFilter{Includes: []string{"aliases", "tags"}}`. ### Request Example ```go ctx := context.Background() artist, err := client.LookupArtist(ctx, "83d91898-7763-47d7-b03b-b92132375c47", // Pink Floyd musicbrainzws2.IncludesFilter{ Includes: []string{"aliases", "tags", "genres", "ratings", "release-groups"}, }, ) if err != nil { log.Fatal(err) } fmt.Printf("Name: %s\nType: %s\nCountry: %s\n", artist.Name, artist.Type, artist.CountryCode) for _, tag := range artist.Tags { fmt.Printf(" tag: %s (%d)\n", tag.Name, tag.Count) } for _, rg := range artist.ReleaseGroups { fmt.Printf(" release group: %s (%s)\n", rg.Title, rg.PrimaryType) } // Output: // Name: Pink Floyd // Type: Group // Country: GB // tag: progressive rock (34) // ... // release group: The Dark Side of the Moon (Album) // ... ``` ### Response #### Success Response (200) - **Artist** (`*Artist`) - A struct containing the artist's details and requested includes. ``` -------------------------------- ### Lookup Disc ID Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Finds releases matching a disc ID using TOC-based lookup. Supports fuzzy matching and including artist credits and recordings. ```go ctx := context.Background() discID, err := client.LookupDiscID(ctx, "IHFDxsSbgDmBmHqnlECNfBRkAHc-", musicbrainzws2.DiscIDFilter{ // TOC: "1 12 267257 150 22767 41887 58317 72102 91375 104652 115380 132165 143932 159870 174597" Includes: []string{"artist-credits", "recordings"}, }, ) if err != nil { log.Fatal(err) } fmt.Printf("Disc sectors: %d (%.0f sec)\n", discID.Sectors, discID.Duration().Seconds()) for _, r := range discID.Releases { fmt.Printf(" Release: %s by %s\n", r.Title, r.ArtistCredit) } ``` -------------------------------- ### BrowseRecordings Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Browses recordings related to an entity, with options to include ISRC and artist credits. ```APIDOC ## BrowseRecordings — Browse recordings related to an entity ### Description Browses recordings related to a specified entity, with options for including additional data. ### Method `BrowseRecordings` ### Parameters - `ctx` (context.Context) - The context for the request. - `filter` (musicbrainzws2.RecordingFilter) - Filter criteria, can include `ArtistMBID`, `Includes`, etc. - `paginator` (musicbrainzws2.Paginator) - Pagination settings for the results. ### Request Example ```go ctx := context.Background() result, err := client.BrowseRecordings(ctx, musicbrainzws2.RecordingFilter{ArtistMBID: "65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab", Includes: []string{"isrcs", "artist-credits"}}, musicbrainzws2.Paginator{Offset: 0, Limit: 50}) ``` ### Response - `result` (*musicbrainzws2.BrowseRecordingsResult) - Contains a list of recordings and their details. - `err` (error) - An error if the request failed. ``` -------------------------------- ### BrowseReleaseGroups Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Browses release groups for an artist, supporting filtering by status and type. ```APIDOC ## BrowseReleaseGroups — Browse release groups for an artist ### Description Browses release groups for an artist, with support for status and type filtering. ### Method `BrowseReleaseGroups` ### Parameters - `ctx` (context.Context) - The context for the request. - `filter` (musicbrainzws2.ReleaseGroupFilter) - Filter criteria, can include `ArtistMBID`, `Type`, `ReleaseGroupStatus`, `Includes`, etc. - `paginator` (musicbrainzws2.Paginator) - Pagination settings for the results. ### Request Example ```go ctx := context.Background() result, err := client.BrowseReleaseGroups(ctx, musicbrainzws2.ReleaseGroupFilter{ArtistMBID: "83d91898-7763-47d7-b03b-b92132375c47", Type: "album", ReleaseGroupStatus: musicbrainzws2.ReleaseGroupStatusWebsiteDefault, Includes: []string{"artist-credits"}}, musicbrainzws2.DefaultPaginator()) ``` ### Response - `result` (*musicbrainzws2.BrowseReleaseGroupsResult) - Contains a list of release groups and their details. - `err` (error) - An error if the request failed. ``` -------------------------------- ### Submit Ratings with Go MusicBrainz WS2 Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Submit integer ratings (0-100) for multiple entity types in a single API call. Requires authentication with an OAuth2 bearer token. ```go ctx := context.Background() client.SetAuthToken("oauth2-bearer-token") ratings := musicbrainzws2.EntityRatingMap{ ArtistRatings: musicbrainzws2.MBIDRatingMap{ "83d91898-7763-47d7-b03b-b92132375c47": 100, }, ReleaseGroupRatings: musicbrainzws2.MBIDRatingMap{ "f5093c06-23e3-404f-aeaa-40f72885ee3a": 100, }, } result, err := client.SubmitRatings(ctx, ratings) if err != nil { log.Fatal(err) } fmt.Println(result.Message) // "OK" ``` -------------------------------- ### BrowseReleases Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Browses releases related to an entity, supporting filtering by artist, label, recording, and more. ```APIDOC ## BrowseReleases — Browse releases related to an entity ### Description Browses releases related to an entity, supporting various filters. ### Method `BrowseReleases` ### Parameters - `ctx` (context.Context) - The context for the request. - `filter` (musicbrainzws2.ReleaseFilter) - Filter criteria, can include `ArtistMBID`, `Status`, `Type`, `Includes`, etc. - `paginator` (musicbrainzws2.Paginator) - Pagination settings for the results. ### Request Example ```go ctx := context.Background() paginator := musicbrainzws2.Paginator{Offset: 0, Limit: musicbrainzws2.MaxLimit} result, err := client.BrowseReleases(ctx, musicbrainzws2.ReleaseFilter{ArtistMBID: "83d91898-7763-47d7-b03b-b92132375c47", Status: "official", Type: "album", Includes: []string{"labels", "media"}}, paginator) ``` ### Response - `result` (*musicbrainzws2.BrowseReleasesResult) - Contains a list of releases and the total count. - `err` (error) - An error if the request failed. ``` -------------------------------- ### LookupReleaseGroup Source: https://context7.com/~phw/go-musicbrainzws2/llms.txt Lookup a single release group by MBID. Returns a ReleaseGroup with primary/secondary types, first release date, and optional releases list. ```APIDOC ## LookupReleaseGroup — Lookup a single release group by MBID Returns a `ReleaseGroup` with primary/secondary types, first release date, and optional releases list. ### Method Signature `client.LookupReleaseGroup(ctx context.Context, mbid string, inc IncludesFilter) (*ReleaseGroup, error)` ### Parameters - **mbid** (string) - The MusicBrainz ID of the release group. - **inc** (IncludesFilter) - Filter to specify which related data to include (e.g., "artist-credits", "releases"). ### Request Example ```go ctx := context.Background() rg, err := client.LookupReleaseGroup(ctx, "f5093c06-23e3-404f-aeaa-40f72885ee3a", musicbrainzws2.IncludesFilter{Includes: []string{"artist-credits", "releases"}}) if err != nil { log.Fatal(err) } fmt.Printf("%s (%s, %s)\n", rg.Title, rg.PrimaryType, rg.FirstReleaseDate) ``` ```