abs

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsHTTPStatus

func IsHTTPStatus(err error, statusCode int) bool

IsHTTPStatus reports whether err or one of its wrapped errors is an HTTPStatusError for the given status code.

func SessionTag added in v0.9.1

func SessionTag(id string) string

SessionTag returns a short name for the ID of a play session, for a log line. The ID gives the audio of the session with no login, so a log line must not contain it. The same ID gives the same name.

func TranscriptIno added in v0.6.0

func TranscriptIno(files []LibraryFile, audioFilename string) string

TranscriptIno returns the inode of the VTT sidecar for audioFilename. If audioFilename is empty and the item has exactly one VTT, that file is used.

Types

type AudioTrack

type AudioTrack struct {
	Index       int          `json:"index"`
	StartOffset float64      `json:"startOffset"`
	Duration    float64      `json:"duration"`
	ContentURL  string       `json:"contentUrl"`
	Metadata    FileMetadata `json:"metadata"`
}

AudioTrack represents a single audio track in a play session.

type Author added in v0.3.0

type Author struct {
	ID   string `json:"id,omitempty"`
	Name string `json:"name"`
}

Author is an Audiobookshelf author reference attached to book metadata.

type Bookmark

type Bookmark struct {
	LibraryItemID string  `json:"libraryItemId,omitempty"`
	Title         string  `json:"title"`
	Time          float64 `json:"time"`      // seconds
	CreatedAt     int64   `json:"createdAt"` // unix timestamp ms
}

Bookmark represents a user bookmark within a media item.

type Chapter

type Chapter struct {
	ID    int     `json:"id"`
	Start float64 `json:"start"`
	End   float64 `json:"end"`
	Title string  `json:"title"`
}

Chapter represents a chapter within a media item.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an HTTP client for the Audiobookshelf API.

func NewClient

func NewClient(baseURL, token string) *Client

NewClient creates a new ABS API client. It removes the spaces around baseURL and the slashes at its end, so that a request path does not start with "//".

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the server base URL.

func (*Client) CloseSession

func (c *Client) CloseSession(ctx context.Context, sessionID string, currentTime, timeListened float64) error

CloseSession closes an active playback session. The server stores the position and the listening time before it closes the session.

func (*Client) CloseSessionNoSync added in v0.8.1

func (c *Client) CloseSessionNoSync(ctx context.Context, sessionID string) error

CloseSessionNoSync closes an active playback session and sends no position, so the server keeps the progress that it has.

func (*Client) CreateBookmark

func (c *Client) CreateBookmark(ctx context.Context, itemID string, time float64, title string) error

CreateBookmark creates a bookmark on a library item at the given time.

func (*Client) DeleteBookmark

func (c *Client) DeleteBookmark(ctx context.Context, itemID string, time float64) error

DeleteBookmark deletes a bookmark from a library item at the given time.

func (*Client) DeleteEpisode added in v0.4.0

func (c *Client) DeleteEpisode(ctx context.Context, podcastID string, episodeID string, hardDelete bool) error

DeleteEpisode deletes a podcast episode from the server.

func (*Client) DeleteItem added in v0.4.0

func (c *Client) DeleteItem(ctx context.Context, itemID string, hardDelete bool) error

DeleteItem deletes a library item from the server. To also delete the files from the filesystem, set hardDelete to true.

func (*Client) FilterAudioLibraries

func (c *Client) FilterAudioLibraries(ctx context.Context, libs []Library) []Library

FilterAudioLibraries filters out "book" type libraries that contain no audio content (ebooks without audio). Podcasts are always kept. A book library is kept if its longest item has audio, or if it has no items. Audio checks for book libraries run in parallel. A failed check goes to the log, and the library is kept.

func (*Client) GetBookmarks

func (c *Client) GetBookmarks(ctx context.Context, itemID string) ([]Bookmark, error)

GetBookmarks returns the bookmarks of the user for a library item. ABS before 2.36.0 has no route for the bookmarks of one item, and answers 404. GetBookmarks then reads the bookmarks of the item from GET /api/me, and the client does not ask for the route again. A later ABS answers 404 only for an item that it does not have. GET /api/me is correct for that server too.

func (*Client) GetItemListeningSessions added in v0.9.0

func (c *Client) GetItemListeningSessions(ctx context.Context, itemID, episodeID string, limit int) (*ListeningSessionsResponse, error)

GetItemListeningSessions returns the newest listening sessions of the user for a book, or for one episode of a podcast. The server answers 404 for a podcast if episodeID is empty.

func (*Client) GetLibraries

func (c *Client) GetLibraries(ctx context.Context) ([]Library, error)

GetLibraries returns all libraries on the server.

func (*Client) GetLibraryFile added in v0.6.0

func (c *Client) GetLibraryFile(ctx context.Context, itemID, ino string) ([]byte, error)

GetLibraryFile downloads a library file by inode.

func (*Client) GetLibraryFiles added in v0.6.0

func (c *Client) GetLibraryFiles(ctx context.Context, itemID string) ([]LibraryFile, error)

GetLibraryFiles returns libraryFiles from an expanded item without storing the item.

func (*Client) GetLibraryItem

func (c *Client) GetLibraryItem(ctx context.Context, itemID string) (*LibraryItem, error)

GetLibraryItem returns a single library item by ID with full details (including episodes for podcasts). include=progress makes ABS embed userMediaProgress; expanded=1 is required for include to take effect.

func (*Client) GetLibraryItems

func (c *Client) GetLibraryItems(ctx context.Context, libraryID string, page, limit int) (*LibraryItemsResponse, error)

GetLibraryItems returns a paginated list of items in a library.

func (*Client) GetLibraryItemsBatch

func (c *Client) GetLibraryItemsBatch(ctx context.Context, ids []string) ([]*LibraryItem, error)

GetLibraryItemsBatch fetches multiple library items concurrently.

func (*Client) GetLibrarySeries

func (c *Client) GetLibrarySeries(ctx context.Context, libraryID string, page, limit int) (*LibrarySeriesResponse, error)

GetLibrarySeries returns a paginated list of series in a library.

func (*Client) GetListeningSessions added in v0.9.0

func (c *Client) GetListeningSessions(ctx context.Context, limit int) (*ListeningSessionsResponse, error)

GetListeningSessions returns the newest listening sessions of the user, for all items.

func (*Client) GetMe added in v0.6.0

func (c *Client) GetMe(ctx context.Context) (*MeResponse, error)

GetMe returns the current user, including all media progress records.

func (*Client) GetMediaProgress

func (c *Client) GetMediaProgress(ctx context.Context, itemID string) (*MediaProgressWithBookmarks, error)

GetMediaProgress returns the user's media progress for a specific library item. ABS gives no bookmarks in this response: GetBookmarks reads them.

func (*Client) GetPersonalized

func (c *Client) GetPersonalized(ctx context.Context, libraryID string) ([]PersonalizedResponse, error)

GetPersonalized returns personalized shelves for a library (e.g. "continue-listening").

func (*Client) GetRecentEpisodes added in v0.2.0

func (c *Client) GetRecentEpisodes(ctx context.Context, libraryID string, limit int) ([]LibraryItem, error)

GetRecentEpisodes fetches recently added podcast episodes for a library.

func (*Client) GetSeries

func (c *Client) GetSeries(ctx context.Context, libraryID, seriesID string) (*Series, error)

GetSeries returns series metadata scoped to a library.

func (*Client) GetSeriesContents

func (c *Client) GetSeriesContents(ctx context.Context, libraryID, seriesID string) (*SeriesContents, error)

GetSeriesContents returns series metadata plus all library items in that series.

func (*Client) Login

func (c *Client) Login(ctx context.Context, username, password string) (string, error)

Login authenticates with the ABS server and stores the token.

func (*Client) ScanLibrary added in v0.10.0

func (c *Client) ScanLibrary(ctx context.Context, libraryID string) error

ScanLibrary starts a scan of a library on the server and waits until the scan ends. The server answers the scan request before the scan, so ScanLibrary reads the scan time of the library (lastScan) until it changes. The server must give the user admin rights. ctx limits the wait.

func (*Client) StartEpisodePlaySession

func (c *Client) StartEpisodePlaySession(ctx context.Context, itemID, episodeID string, device DeviceInfo) (*PlaySession, error)

StartEpisodePlaySession starts a new playback session for a podcast episode.

func (*Client) StartPlaySession

func (c *Client) StartPlaySession(ctx context.Context, itemID string, device DeviceInfo) (*PlaySession, error)

StartPlaySession starts a new playback session for a library item.

func (*Client) SyncSession

func (c *Client) SyncSession(ctx context.Context, sessionID string, currentTime, timeListened float64) error

SyncSession syncs the current playback position for an active session.

func (*Client) Token

func (c *Client) Token() string

Token returns the auth token.

func (*Client) UpdateBookmark

func (c *Client) UpdateBookmark(ctx context.Context, itemID string, time float64, title string) error

UpdateBookmark updates the title of an existing bookmark.

func (*Client) UpdateLibraryItemMedia added in v0.3.0

func (c *Client) UpdateLibraryItemMedia(ctx context.Context, itemID string, req UpdateMediaRequest) (*LibraryItem, error)

UpdateLibraryItemMedia updates an ABS library item's media metadata.

func (*Client) UpdatePodcastEpisode added in v0.3.0

func (c *Client) UpdatePodcastEpisode(ctx context.Context, itemID, episodeID string, req UpdatePodcastEpisodeRequest) (*LibraryItem, error)

UpdatePodcastEpisode updates ABS metadata for a single podcast episode.

func (*Client) UpdatePosition added in v0.8.1

func (c *Client) UpdatePosition(ctx context.Context, itemID, episodeID string, currentTime, progress float64) error

UpdatePosition updates the user's position in a library item, or in a podcast episode if episodeID is not empty. It sends no isFinished key.

func (*Client) UpdateProgress

func (c *Client) UpdateProgress(ctx context.Context, itemID, episodeID string, currentTime, progress float64, isFinished bool) error

UpdateProgress updates the user's progress on a library item, or on a podcast episode if episodeID is not empty.

type DeviceInfo

type DeviceInfo struct {
	DeviceID      string `json:"deviceId"`
	Manufacturer  string `json:"manufacturer"`
	Model         string `json:"model"`
	ClientName    string `json:"clientName"`
	ClientVersion string `json:"clientVersion"`
	// DeviceName is set by the server, from the manufacturer and the model.
	// The client does not send it.
	DeviceName string `json:"deviceName,omitempty"`
}

DeviceInfo identifies the client device for a play session.

type FileMetadata added in v0.6.0

type FileMetadata struct {
	Filename string `json:"filename"`
	Ext      string `json:"ext,omitempty"`
}

FileMetadata is ABS file metadata used to match audio tracks to sidecars.

type HTTPStatusError

type HTTPStatusError struct {
	StatusCode int
	// Body is the start of the response body, at most 500 bytes.
	Body string
}

HTTPStatusError wraps a non-2xx HTTP response status.

func (*HTTPStatusError) Error

func (e *HTTPStatusError) Error() string

type Library

type Library struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	MediaType string `json:"mediaType"` // "book" or "podcast"
}

Library represents an Audiobookshelf library.

type LibraryFile added in v0.6.0

type LibraryFile struct {
	Ino      string       `json:"ino"`
	FileType string       `json:"fileType,omitempty"`
	Metadata FileMetadata `json:"metadata"`
}

LibraryFile is a file attached to a library item.

type LibraryItem

type LibraryItem struct {
	ID                string             `json:"id"`
	LibraryID         string             `json:"libraryId,omitempty"`
	AddedAt           int64              `json:"addedAt,omitempty"`
	MediaType         string             `json:"mediaType"` // "book" or "podcast"
	Media             Media              `json:"media"`
	UserMediaProgress *UserMediaProgress `json:"userMediaProgress,omitempty"`
	RecentEpisode     *PodcastEpisode    `json:"recentEpisode,omitempty"`
}

LibraryItem represents a book or podcast in a library.

type LibraryItemsResponse

type LibraryItemsResponse struct {
	Results []LibraryItem `json:"results"`
	Total   int           `json:"total"`
	Limit   int           `json:"limit"`
	Page    int           `json:"page"`
}

LibraryItemsResponse is returned by GET /api/libraries/{id}/items.

type LibrarySeriesResponse

type LibrarySeriesResponse struct {
	Results []Series `json:"results"`
	Total   int      `json:"total"`
	Limit   int      `json:"limit"`
	Page    int      `json:"page"`
}

LibrarySeriesResponse is returned by GET /api/libraries/{id}/series.

type ListeningSession added in v0.9.0

type ListeningSession struct {
	ID            string `json:"id"`
	LibraryItemID string `json:"libraryItemId"`
	EpisodeID     string `json:"episodeId"`
	MediaType     string `json:"mediaType"`
	// DisplayTitle is the title of the book, or the title of the episode.
	DisplayTitle  string `json:"displayTitle"`
	DisplayAuthor string `json:"displayAuthor"`
	// MediaMetadata.Title is the title of the book or of the podcast.
	MediaMetadata struct {
		Title string `json:"title"`
	} `json:"mediaMetadata"`
	StartTime     float64    `json:"startTime"`
	CurrentTime   float64    `json:"currentTime"`
	TimeListening float64    `json:"timeListening"`
	UpdatedAt     int64      `json:"updatedAt"`
	DeviceInfo    DeviceInfo `json:"deviceInfo"`
}

ListeningSession is one playback session of the user. StartTime and CurrentTime are positions in the whole book or episode, in seconds. CurrentTime is the position of the last sync. UpdatedAt is the time of the last sync, in Unix milliseconds.

type ListeningSessionsResponse added in v0.9.0

type ListeningSessionsResponse struct {
	Total    int                `json:"total"`
	Sessions []ListeningSession `json:"sessions"`
}

ListeningSessionsResponse is one page of listening sessions, the newest first. Total is the number of sessions on all pages.

type LoginResponse

type LoginResponse struct {
	User LoginUser `json:"user"`
}

LoginResponse is returned by POST /login.

type LoginUser

type LoginUser struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Token    string `json:"token"`
}

LoginUser contains user info including the auth token.

type MeResponse added in v0.6.0

type MeResponse struct {
	MediaProgress []MediaProgressEntry `json:"mediaProgress"`
}

MeResponse is the subset of GET /api/me used by pine.

type Media

type Media struct {
	Metadata      MediaMetadata    `json:"metadata"`
	Duration      *float64         `json:"duration,omitempty"`
	CoverPath     *string          `json:"coverPath,omitempty"`
	Episodes      []PodcastEpisode `json:"episodes,omitempty"`
	NumAudioFiles *int             `json:"numAudioFiles,omitempty"`
	NumTracks     *int             `json:"numTracks,omitempty"`
}

Media contains the media content and metadata of a library item.

func (Media) HasDuration

func (m Media) HasDuration() bool

HasDuration returns true if a non-zero duration is available.

func (Media) TotalDuration

func (m Media) TotalDuration() float64

TotalDuration returns the item duration, checking media.duration first then falling back to media.metadata.duration. Returns 0 if neither is set.

type MediaMetadata

type MediaMetadata struct {
	Title       string           `json:"title"`
	AuthorName  *string          `json:"authorName,omitempty"`
	Authors     []Author         `json:"authors,omitempty"`
	Description *string          `json:"description,omitempty"`
	Duration    *float64         `json:"duration,omitempty"` // seconds
	Chapters    []Chapter        `json:"chapters,omitempty"`
	Series      *SeriesSequence  `json:"series,omitempty"`
	SeriesList  []SeriesSequence `json:"-"`
}

MediaMetadata holds descriptive information about a media item.

func (MediaMetadata) DisplayAuthor added in v0.3.0

func (m MediaMetadata) DisplayAuthor() string

DisplayAuthor returns the best author string for UI display and search.

func (MediaMetadata) HasMultipleAuthors added in v0.3.0

func (m MediaMetadata) HasMultipleAuthors() bool

HasMultipleAuthors reports whether ABS returned more than one non-empty author.

func (MediaMetadata) HasMultipleSeries added in v0.3.0

func (m MediaMetadata) HasMultipleSeries() bool

HasMultipleSeries reports whether ABS returned more than one series entry.

func (MediaMetadata) SeriesByID added in v0.3.0

func (m MediaMetadata) SeriesByID(id string) *SeriesSequence

SeriesByID returns the series entry with the given ABS series ID.

func (*MediaMetadata) UnmarshalJSON

func (m *MediaMetadata) UnmarshalJSON(data []byte) error

UnmarshalJSON handles ABS returning series metadata as either an object or an array.

type MediaProgressEntry added in v0.6.0

type MediaProgressEntry struct {
	LibraryItemID string  `json:"libraryItemId"`
	EpisodeID     string  `json:"episodeId"`
	CurrentTime   float64 `json:"currentTime"`
	Progress      float64 `json:"progress"`
	IsFinished    bool    `json:"isFinished"`
}

MediaProgressEntry is a single user progress record from /api/me.

type MediaProgressWithBookmarks

type MediaProgressWithBookmarks struct {
	LibraryItemID string     `json:"libraryItemId"`
	EpisodeID     string     `json:"episodeId,omitempty"`
	CurrentTime   float64    `json:"currentTime"`
	Progress      float64    `json:"progress"`
	IsFinished    bool       `json:"isFinished"`
	Bookmarks     []Bookmark `json:"bookmarks"`
}

MediaProgressWithBookmarks is the body of GET /api/me/progress/{id}. ABS gives no key "bookmarks" in that body, so Bookmarks is always empty. GetBookmarks reads the bookmarks.

type PersonalizedResponse

type PersonalizedResponse struct {
	ID       string        `json:"id"` // e.g. "continue-listening"
	Entities []LibraryItem `json:"entities"`
}

PersonalizedResponse is a section returned by GET /api/libraries/{id}/personalized.

type PlaySession

type PlaySession struct {
	ID            string          `json:"id"`
	AudioTracks   []AudioTrack    `json:"audioTracks"`
	CurrentTime   float64         `json:"currentTime"`
	EpisodeID     string          `json:"episodeId,omitempty"`
	MediaMetadata MediaMetadata   `json:"mediaMetadata"`
	Chapters      []Chapter       `json:"chapters,omitempty"`
	LibraryItem   PlaySessionItem `json:"libraryItem"`
}

PlaySession is returned by POST /api/items/{id}/play or /api/items/{id}/play/{episodeId}.

func (PlaySession) TranscriptIno added in v0.6.0

func (s PlaySession) TranscriptIno(audioFilename string) string

TranscriptIno returns the VTT inode for audioFilename from the session item.

type PlaySessionItem added in v0.6.0

type PlaySessionItem struct {
	LibraryFiles []LibraryFile `json:"libraryFiles,omitempty"`
}

PlaySessionItem is the nested library item on a play-session response.

type PodcastEpisode

type PodcastEpisode struct {
	ID          string     `json:"id"`
	Index       *int       `json:"index"`
	Title       string     `json:"title"`
	Description string     `json:"description,omitempty"`
	Season      string     `json:"season,omitempty"`
	Episode     string     `json:"episode,omitempty"`
	EpisodeType string     `json:"episodeType,omitempty"`
	Duration    float64    `json:"duration"`
	Size        int64      `json:"size,omitempty"`
	AudioTrack  AudioTrack `json:"audioTrack,omitempty"`
	PublishedAt *int64     `json:"publishedAt,omitempty"`
	AddedAt     int64      `json:"addedAt,omitempty"`
}

PodcastEpisode represents a single episode of a podcast.

type Series

type Series struct {
	ID          string       `json:"id"`
	Name        string       `json:"name"`
	Description string       `json:"description,omitempty"`
	LibraryID   string       `json:"libraryId,omitempty"`
	AddedAt     int64        `json:"addedAt,omitempty"`
	UpdatedAt   int64        `json:"updatedAt,omitempty"`
	Books       []SeriesBook `json:"books,omitempty"`
}

Series contains series metadata returned by ABS. Only the series list of a library has the books.

type SeriesBook

type SeriesBook struct {
	ID string `json:"id"`
}

SeriesBook is a book in the series list of a library.

type SeriesContents

type SeriesContents struct {
	Series Series
	Items  []LibraryItem
}

SeriesContents combines series metadata with the library items in that series.

type SeriesSequence

type SeriesSequence struct {
	ID       string `json:"id,omitempty"`
	Name     string `json:"name"`
	Sequence string `json:"sequence,omitempty"`
}

SeriesSequence is the minimal series context attached to a library item.

type UpdateMediaMetadata added in v0.3.0

type UpdateMediaMetadata struct {
	Title   *string           `json:"title,omitempty"`
	Authors *[]Author         `json:"authors,omitempty"`
	Series  *[]SeriesSequence `json:"series,omitempty"`
}

UpdateMediaMetadata contains only metadata fields pine intentionally edits.

type UpdateMediaRequest added in v0.3.0

type UpdateMediaRequest struct {
	Metadata UpdateMediaMetadata `json:"metadata"`
}

UpdateMediaRequest is the body for PATCH /api/items/{id}/media.

type UpdatePodcastEpisodeRequest added in v0.3.0

type UpdatePodcastEpisodeRequest struct {
	Title       *string `json:"title,omitempty"`
	Description *string `json:"description,omitempty"`
	Season      *string `json:"season,omitempty"`
	Episode     *string `json:"episode,omitempty"`
	EpisodeType *string `json:"episodeType,omitempty"`
}

UpdatePodcastEpisodeRequest is the body for PATCH /api/podcasts/{id}/episode/{episodeId}.

type UserMediaProgress

type UserMediaProgress struct {
	CurrentTime float64 `json:"currentTime"` // seconds
	Progress    float64 `json:"progress"`    // 0.0 - 1.0
	IsFinished  bool    `json:"isFinished"`
}

UserMediaProgress tracks a user's progress on a media item.

Jump to

Keyboard shortcuts

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