libgpod

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: AGPL-3.0 Imports: 20 Imported by: ? 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

View Source
const (
	MarkUnplayed_Unplayed = MarkUnplayed(0x2)
	MarkUnplayed_Played   = MarkUnplayed(0x1)
)

Variables

View Source
var SerialToModel = map[string]string{}/* 243 elements not displayed */

SerialToModel is straight off libgpod. They don't (i think?) expose this through the API. I've also added an M in front of the model number, which seems needed. I've added some serials I've encountered myself but were missing.

Functions

func InitDevice added in v0.4.0

func InitDevice(
	logger *slog.Logger,
	mountpoint string,
	device string,
	serial string,
	force bool,
) error

InitDevice initialises an iPod.

func IsDeviceInitialised added in v0.4.0

func IsDeviceInitialised(mountpoint string) (bool, error)

func ModifyTrack added in v0.3.0

func ModifyTrack(logger *slog.Logger, t *C.Itdb_Track, mods ...TrackModifier)

ModifyTrack changes values in t using mods. This is just to get around the fact that since the struct fields start with a lowercase letter they're not visible outside package. Nice one.

Types

type GPod

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

func OpenMount

func OpenMount(
	logger *slog.Logger,
	mountpoint string,
) (*GPod, error)

func (*GPod) Cleanup added in v0.3.0

func (g *GPod) Cleanup(
	logger *slog.Logger,
	orphaned bool,
	invalid func(comment string) error,
) error

Cleanup cleans up the iPod. The orphaned option removes tracks from the database that don't have a file, or that have a file that's zero bytes in size. The invalid function, if not nil, will be called to check if a track is invalid to your application.

func (*GPod) Close added in v0.8.0

func (g *GPod) Close()

Close the database without saving it. This frees the memory taken by OpenMount, so it must be called even if the database is saved.

func (*GPod) ResetRecentPlaycount added in v0.3.0

func (g *GPod) ResetRecentPlaycount(comment string)

ResetPlaycount resets the recent playcount of a track by comment.

func (*GPod) Save

func (g *GPod) Save() error

Save the database to the device.

func (*GPod) SortAlbums added in v0.5.0

func (g *GPod) SortAlbums(how SortMethod)

SortAlbums sorts the albums according to SortMethod.

func (*GPod) SyncTracks

func (g *GPod) SyncTracks(
	ctx context.Context,
	logger *slog.Logger,
	want []Track,
	validateComment func(comment string) error,
) error

SyncTracks makes sure the iPod has all the wanted tracks in it. It uses Track.Comment as an unique key, so make sure that's unique. The optional function validateComment is to ignore tracks not managed by your application.

func (*GPod) TrackByComment added in v0.3.0

func (g *GPod) TrackByComment(comment string) *C.Itdb_Track

func (*GPod) Tracks

func (g *GPod) Tracks() iter.Seq[Track]

type MarkUnplayed

type MarkUnplayed int

func (MarkUnplayed) String added in v0.3.0

func (m MarkUnplayed) String() string

type MediaType

type MediaType uint32

func (MediaType) Is added in v0.3.0

func (t MediaType) Is(w MediaType) bool

func (MediaType) String added in v0.3.0

func (t MediaType) String() string

type PlaylistMeta

type PlaylistMeta struct {
	Name       string
	Position   int
	IsMPL      bool // Only for diagnostics.
	IsPodcasts bool // Only for diagnostics.
}

type SortMethod added in v0.5.0

type SortMethod uint8
const (
	SortMethod_Alphabetically SortMethod = iota
	SortMethod_RecentlyAddedFirst
)

type Track

type Track struct {
	WriteFile    Writer   `json:"-"`
	WriteArtwork WriterTo `json:"-"`
	Filename     string   `json:"filename"`

	// Song metadata.
	Artist         string        `json:"artist"`
	Album          string        `json:"album"`
	AlbumArtist    string        `json:"album_artist"`
	Title          string        `json:"title"`
	Genere         string        `json:"genere"`
	Composer       string        `json:"composer"`
	Year           int           `json:"year"`
	Comment        string        `json:"comment"`
	TrackLen       time.Duration `json:"track_len_ms"`
	CDNumber       int           `json:"cd_number"`
	NumberOfCDs    int           `json:"number_of_cds"`
	TrackNumber    int           `json:"track_number"`
	NumberOfTracks int           `json:"number_of_tracks"`
	BPM            int           `json:"bpm"`
	Compilation    int           `json:"compilation"`
	// For adults=1.
	ExplicitFlag int `json:"explicit_flag"`

	// Podcast Specific
	PodcastURL string `json:"podcast_url"`
	PodcastRSS string `json:"podcast_rss"`
	// From libgpod:
	// Used for podcasts, 0x00 otherwise.  If set to
	// 0x01 the "Now Playing" page will show
	// Title/Album, when set to 0x00 it will also show
	// the Artist.  When set to 0x02 a sub-page
	// (middle button) with further information about
	// the track will be shown.
	Flag4                    int          `json:"flag_4"`
	TimeReleased             time.Time    `json:"time_released"`
	MarkUnplayed             MarkUnplayed `json:"mark_unplayed"`
	RememberPlaybackPosition bool         `json:"remember_playback_position"`

	// TV Show Specific
	TVShow        string `json:"tv_show"`
	TVEpisode     string `json:"tv_episode"`
	TVNetwork     string `json:"tv_network"`
	SeasonNumber  int    `json:"season_number"`
	EpisodeNumber int    `json:"episode_number"`

	// Movie stuff
	MovieFlag bool `json:"movie_flag"` // True if movie.

	Filetype   string `json:"filetype"`
	Size       int    `json:"size"` // In bytes
	BitRate    int    `json:"bit_rate"`
	SampleRate int    `json:"sample_rate"`
	// Number of samples in track.
	SampleCount int `json:"sample_count"`
	// Start offset for gapless playback, ms.
	StartTime time.Duration `json:"start_time"`
	// End offset for gapless playback, ms.
	StopTime  time.Duration `json:"stop_time"`
	MediaType MediaType     `json:"media_type"`

	// Unique ID in the iPod DB.
	DBID         uint64    `json:"dbid"`
	TimeAdded    time.Time `json:"time_added"`
	TimeModified time.Time `json:"time_modified"`
	TimePlayed   time.Time `json:"time_played"`
	BookmarkTime time.Time `json:"bookmark_time"`
	// TODO, there's a formula for this.
	Rating    int `json:"rating"`
	Playcount int `json:"playcount"`
	// Times played since last sync.
	RecentPlaycount int `json:"recent_playcount"`
	// File transferred to ipod?
	Transferred bool `json:"transferred"`
	AppRating   int  `json:"app_rating"`
	// CBR MP3s and AAC are 0x00, VBR MP3s are 0x01
	Type1 int `json:"type_1"`
	// MP3s are 0x01, AAC are 0x00
	Type2        int `json:"type_2"`
	Checked      int `json:"checked"`
	Visible      int `json:"visible"`
	ArtworkCount int `json:"artwork_count"`
	ArtworkSize  int `json:"artwork_size"`
	HasArtwork   int `json:"has_artwork"`
	// Volume stuff. TODO
	SoundCheck int `json:"sound_check"`
	// Used to sort albums in menus.
	SortAlbum *string

	Playlists []PlaylistMeta `json:"playlists"`
}

type TrackModifier added in v0.3.0

type TrackModifier func(t *C.Itdb_Track) string

func TrackModifier_MPL added in v0.3.0

func TrackModifier_MPL(want bool) TrackModifier

func TrackModifier_SetMediaType added in v0.3.0

func TrackModifier_SetMediaType(mt MediaType) TrackModifier

type Writer

type Writer func(ctx context.Context, filename string) (int64, error)

type WriterTo added in v0.3.0

type WriterTo func(ctx context.Context, w io.Writer) (int64, error)

Jump to

Keyboard shortcuts

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