audioprobe

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package audioprobe reads what an audio file's container says about it, a few kilobytes at a time: which container it really is, whatever its extension says, and whether its audio is locked to a store's player. The server's own probe names the codec, and a FairPlay book from the iTunes store reads there as plain AAC: the lock shows only in the container, as the sample description "drms" where a playable file says "mp4a".

It never decodes anything and needs no ffmpeg. A file is read through a Fetch, which the caller points at the server's file route with byte ranges, so a long book costs its header and, when the header sits at the end, a few more small reads.

Index

Constants

View Source
const (
	MP4  = "mp4"  // MPEG-4 / QuickTime: m4a, m4b, mp4, aax
	MP3  = "mp3"  // MPEG audio, with or without an ID3 tag in front
	AAC  = "aac"  // raw AAC in ADTS frames
	FLAC = "flac" // FLAC
	Ogg  = "ogg"  // Ogg: Vorbis, Opus, or FLAC in Ogg
	WAV  = "wav"  // RIFF WAVE
	ASF  = "asf"  // Windows Media: wma
	MKV  = "mkv"  // Matroska / WebM
	AIFF = "aiff" // AIFF
	CAF  = "caf"  // Apple Core Audio Format
)

Containers, as Report names them.

Variables

View Source
var ErrMalformed = errors.New("the file cannot be read as audio")

ErrMalformed is what every error the file itself causes wraps: a header that makes no sense, or one this reading cannot follow. Any other error is the read failing, which says nothing of the file.

View Source
var ErrTooScattered = fmt.Errorf("%w: its header is scattered past what a readable file needs", ErrMalformed)

ErrTooScattered is returned when a file's header needs more reads than a sane one does.

Functions

This section is empty.

Types

type Fetch

type Fetch func(ctx context.Context, off, n int64) (data []byte, size int64, err error)

Fetch reads up to n bytes of a file from off, and says how long the whole file is. Fewer bytes come back only at the end of the file.

func ItemFile

func ItemFile(client *abs.Client, itemID, fileID string) Fetch

ItemFile is a Fetch over one file of an item, through the server's file route with byte ranges.

type Report

type Report struct {
	// Container is what the file holds, read from its first bytes; "" when
	// they match nothing known.
	Container string
	// Locked says how the audio is locked, and is "" for audio any player
	// can play: "Apple FairPlay (drms)".
	Locked string
	// Size is the file's length in bytes, and Want what its container says
	// it should be when that is more: a download or a copy that broke off.
	// Want is 0 for a file that is whole, or whose container does not say.
	Size, Want int64
}

Report is what a file's container says.

func Probe

func Probe(ctx context.Context, fetch Fetch) (Report, error)

Probe reads a file's container and whether its audio is locked.

Jump to

Keyboard shortcuts

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