bandcamp

package
v0.0.0-...-d41d457 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package bandcamp provides required Web API access to undocumented user API.

Index

Constants

View Source
const (
	ItemTypeAlbum = "a"
	ItemTypeTrack = "t"
)

Variables

View Source
var Extensions = map[string]string{

	"mp3-v0":        ".mp3",
	"mp3-320":       ".mp3",
	"flac":          ".flac",
	"aac-hi":        ".m4a",
	"vorbis":        ".ogg",
	"alac":          ".m4a",
	"wav":           ".wav",
	"aiff-lossless": ".aiff",
}

While bandcamp stores the extension metadata, this is required to check if a given track exists for the given format.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL *url.URL
	*http.Client
}

Client embeds an http.Client to make currently implemented Bandcamp API calls that are undocumented.

func New

func New(identity string) *Client

New returns a new Client. To make authenticated API calls, an authenticated auoted Bandcamp login 'identity' cookie is required.

func (*Client) GetCollection

func (c *Client) GetCollection(id FanID) (Collection, error)

func (*Client) GetFan

func (c *Client) GetFan() (*Fan, error)

Report the current authenticated user.

func (*Client) GetItemDownload

func (c *Client) GetItemDownload(item *Item, format string) (*Download, error)

func (*Client) Request

func (c *Client) Request(method, endpoint string, body, v any) error

func (*Client) Value

func (c *Client) Value(f *Fan, items Collection, target string) (float64, error)

Value uses the currency data in the HTML metadata using the given fan's URL page to report the total cost of the given items converted to the given target currency.

type Collection

type Collection []Item

Bandcamp store this behind the fancollection/1/collection_items endpoint, and also keep it under the page-data if visited the user's profile.

func (*Collection) UnmarshalJSON

func (c *Collection) UnmarshalJSON(b []byte) error

type Download

type Download struct {
	Email    string `json:"-"`
	Size     string `json:"size_mb"`
	Encoding string `json:"encoding_name"`
	URL      string `json:"url"`
}

type Error

type Error struct {
	IsError bool   `json:"error"`
	Message string `json:"error_message"`
}

func (Error) Error

func (e Error) Error() string

type Fan

type Fan struct {
	Username string `json:"username"`
	URL      string `json:"url"`
	ID       FanID  `json:"fan_id"`
}

type FanID

type FanID int64

type Item

type Item struct {
	// Extraneous metadata stripped, such as fan id,
	// genre, dates, "why", URLs, etc.
	ID        ItemID   `json:"item_id"`
	Type      ItemType `json:"tralbum_type"`
	BandName  string   `json:"band_name"`
	Title     string   `json:"item_title"`
	Purchased Time     `json:"purchased"`
	ArtURL    string   `json:"item_art_url"`
	Sale

	Price    float64 `json:"price"`
	Currency string  `json:"currency"`

	Download string  `json:"-"`
	Tracks   []Track `json:"-"`
}

func (Item) String

func (i Item) String() string

type ItemID

type ItemID int64

type ItemType

type ItemType string

func (ItemType) String

func (t ItemType) String() string

type Sale

type Sale struct {
	ID   SaleID   `json:"sale_item_id"`
	Type SaleType `json:"sale_item_type"`
}

func (Sale) String

func (s Sale) String() string

type SaleID

type SaleID int64

type SaleType

type SaleType string
const (
	// Redeemed from a code
	Code SaleType = "c"

	// Purchased individually from an artist
	Purchase SaleType = "p"

	// Purchased as part of a whole discography
	Records SaleType = "r"
)

type StatusError

type StatusError struct {
	StatusCode int
}

func (*StatusError) Error

func (e *StatusError) Error() string

type Time

type Time struct {
	time.Time
}

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

type Track

type Track struct {
	// Artist, duration, file excluded
	Title  string `json:"title"`
	Number int64  `json:"track_number"` // null if item is track
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL