mp4tag

package module
v0.0.0-...-68ce31d Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 9 Imported by: 5

README

go-mp4tag

MP4 tag library written in Go.

Setup
go get github.com/Sorrow446/go-mp4tag
Usage Examples
import "github.com/Sorrow446/go-mp4tag"

Opening is omitted from the examples.

mp4, err := mp4tag.Open("1.m4a")
if err != nil {
	panic(err)
}
defer mp4.Close()

Read album title:

tags, err := mp4.Read()
if err != nil {
	panic(err)
}
fmt.Println(tags.Album)

Extract all covers:

tags, err := mp4.Read()
if err != nil {
	panic(err)
}

for idx, pic := range tags.Pictures {
	fname := fmt.Sprintf("out_%03d.jpg", idx+1)
	err = os.WriteFile(fname, pic.Data, 0666)
	if err != nil {
		panic(err)
	}
}

Write two covers:

picOneData, err := os.ReadFile("1.jpg")
if err != nil {
	panic(err)
}

picTwoData, err := os.ReadFile("2.jpg")
if err != nil {
	panic(err)
}

picOne := &mp4tag.MP4Picture{Data: picOneData}
picTwo := &mp4tag.MP4Picture{Data: picTwoData}

tags := &mp4tag.MP4Tags{
	Pictures: []*mp4tag.MP4Picture{picOne, picTwo},
}

err = mp4.Write(tags, []string{})
if err != nil {
	panic(err)
}

Write track number and total:

tags := &mp4tag.MP4Tags{
	TrackNumber: 1,
	TrackTotal: 10,
}

err = mp4.Write(tags, []string{})
if err != nil {
	panic(err)
}

Delete comment:

err = mp4.Write(&mp4tag.MP4Tags{}, []string{"comment"})
if err != nil {
	panic(err)
}
Deletion Strings

Case insensitive.

  • album
  • albumartist
  • albumrtistsort
  • albumsort
  • allcustom
  • allothercustom
  • allpictures
  • alltags
  • artist
  • artistsort
  • bpm
  • comment
  • composer
  • composersort
  • conductor
  • copyright
  • customgenre
  • date
  • description
  • director
  • discnumber/disknumber
  • disctotal/disktotal
  • genre
  • itunesadvisory
  • itunesalbumid
  • itunesartistid
  • lyrics
  • narrator
  • picture:<position index starting from 1>
  • publisher
  • title
  • titlesort
  • tracknumber
  • tracktotal
  • year

Documentation

Index

Constants

View Source
const BufSize = 4096 * 1024

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrBoxNotPresent

type ErrBoxNotPresent struct {
	Msg string
}

func (*ErrBoxNotPresent) Error

func (e *ErrBoxNotPresent) Error() string

type ErrInvalidMagic

type ErrInvalidMagic struct{}

func (*ErrInvalidMagic) Error

func (_ *ErrInvalidMagic) Error() string

type ErrInvalidStcoSize

type ErrInvalidStcoSize struct{}

func (*ErrInvalidStcoSize) Error

func (_ *ErrInvalidStcoSize) Error() string

type ErrUnsupportedFtyp

type ErrUnsupportedFtyp struct {
	Msg string
}

func (*ErrUnsupportedFtyp) Error

func (e *ErrUnsupportedFtyp) Error() string

type Genre

type Genre int8

GenreNone

const (
	GenreNone Genre = iota
	GenreBlues
	GenreClassicRock
	GenreCountry
	GenreDance
	GenreDisco
	GenreFunk
	GenreGrunge
	GenreHipHop
	GenreJazz
	GenreMetal
	GenreNewAge
	GenreOldies
	GenreOther
	GenrePop
	GenreRhythmAndBlues
	GenreRap
	GenreReggae
	GenreRock
	GenreTechno
	GenreIndustrial
	GenreAlternative
	GenreSka
	GenreDeathMetal
	GenrePranks
	GenreSoundtrack
	GenreEurotechno
	GenreAmbient
	GenreTripHop
	GenreVocal
	GenreJassAndFunk
	GenreFusion
	GenreTrance
	GenreClassical
	GenreInstrumental
	GenreAcid
	GenreHouse
	GenreGame
	GenreSoundClip
	GenreGospel
	GenreNoise
	GenreAlternativeRock
	GenreBass
	GenreSoul
	GenrePunk
	GenreSpace
	GenreMeditative
	GenreInstrumentalPop
	GenreInstrumentalRock
	GenreEthnic
	GenreGothic
	GenreDarkwave
	GenreTechnoindustrial
	GenreElectronic
	GenrePopFolk
	GenreEurodance
	GenreSouthernRock
	GenreComedy
	GenreCull
	GenreGangsta
	GenreTop40
	GenreChristianRap
	GenrePopSlashFunk
	GenreJungleMusic
	GenreNativeUS
	GenreCabaret
	GenreNewWave
	GenrePsychedelic
	GenreRave
	GenreShowtunes
	GenreTrailer
	GenreLofi
	GenreTribal
	GenreAcidPunk
	GenreAcidJazz
	GenrePolka
	GenreRetro
	GenreMusical
	GenreRockNRoll
	GenreHardRock
)

type ImageType

type ImageType int8
const (
	ImageTypeJPEG ImageType = iota + 13
	ImageTypePNG
	ImageTypeAuto
)

type ItunesAdvisory

type ItunesAdvisory int8
const (
	ItunesAdvisoryNone ItunesAdvisory = iota
	ItunesAdvisoryExplicit
	ItunesAdvisoryClean
)

type MP4

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

func Open

func Open(trackPath string) (*MP4, error)

func (*MP4) Close

func (mp4 *MP4) Close() error

func (*MP4) Read

func (mp4 *MP4) Read() (*MP4Tags, error)

func (*MP4) UpperCustom

func (mp4 *MP4) UpperCustom(b bool)

func (*MP4) Write

func (mp4 *MP4) Write(tags *MP4Tags, delStrings []string) error

type MP4Box

type MP4Box struct {
	StartOffset int64
	EndOffset   int64
	BoxSize     int64
	Path        string
}

type MP4Boxes

type MP4Boxes struct {
	Boxes []*MP4Box
}

type MP4Picture

type MP4Picture struct {
	Format ImageType
	Data   []byte
}

type MP4Tags

type MP4Tags struct {
	Album           string
	AlbumSort       string
	AlbumArtist     string
	AlbumArtistSort string
	Artist          string
	ArtistSort      string
	BPM             int16
	Comment         string
	Composer        string
	ComposerSort    string
	Conductor       string
	Copyright       string
	Custom          map[string]string
	CustomGenre     string
	Date            string
	Description     string
	Director        string
	DiscNumber      int16
	DiscTotal       int16
	Genre           Genre
	ItunesAdvisory  ItunesAdvisory
	ItunesAlbumID   int32
	ItunesArtistID  int32
	Lyrics          string
	Narrator        string
	OtherCustom     map[string][]string
	Pictures        []*MP4Picture
	Publisher       string
	Title           string
	TitleSort       string
	TrackNumber     int16
	TrackTotal      int16
	Year            int32
}

Jump to

Keyboard shortcuts

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