libnp

package module
v0.0.0-...-0e45ece Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: MIT Imports: 5 Imported by: 2

README

go-libnp GoDoc stability-experimental

A tiny cross-platform library for extracting information about the music/image/video that is Now Playing on the system.

Supported OS:

  • Windows (using CGo: GlobalSystemMediaTransportControlsSessionManager)
  • Linux (using plain Go: DBus/MPRIS)

This is essentially Go bindings for libnp, but with the Linux implementation rewritten in plain Go.

Usage

The API is well-documented in its GoDoc

info, err := libnp.GetInfo(context.Background())
fmt.Println(info.Album)

Building

On Windows, building requires a MinGW toolchain, and the Windows SDK.

Make sure that GCC is in your path, and set CPATH to include the Windows SDK include folder:

set "CPATH=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621\winrt"

Replace the version above with your SDK version.

Otherwise, if you just want to build the library with the stub backend (always returning an empty song), just compile with CGO_ENABLED=0.

Status

Used in small-scale production environments.

The API could be slightly changed in backwards-incompatible ways for now.

  • Add darwin
  • Add web

License

MIT

Documentation

Overview

Package libnp offers information about the media that is currently being played. The main entrypoint is GetInfo, which returns an Info.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	AlbumArtists    []string
	Artists         []string
	Composers       []string  // linux only
	Genres          []string  // linux only
	Lyricists       []string  // linux only
	Created         time.Time // linux only
	FirstPlayed     time.Time // linux only
	LastPlayed      time.Time // linux only
	Album           string
	AlbumTrackCount int           // windows only
	ArtURL          string        // linux only
	BPM             int           // linux only
	DiscNumber      int           // linux only
	Length          time.Duration // linux only
	PlayCount       int           // linux only
	Subtitle        string        // windows only
	Title           string
	TrackNumber     int
	URL             string       // linux only
	PlaybackType    PlaybackType // windows only
}

Info stores information about the media being played.

func GetInfo

func GetInfo(ctx context.Context) (*Info, error)

GetInfo returns Info about the media currently being played.

An error is returned if the library has issues getting valid information about the song being played.

A nil Info with a nil error is returned if there is no media being played.

type PlaybackType

type PlaybackType int

PlaybackType represents the kind of media being played. PlaybackTypeUnknown is used on some platforms.

const (
	PlaybackTypeUnknown PlaybackType = iota
	PlaybackTypeMusic
	PlaybackTypeVideo
	PlaybackTypeImage
)

func (PlaybackType) String

func (p PlaybackType) String() string

Directories

Path Synopsis
cmd
np

Jump to

Keyboard shortcuts

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