itunes

package module
v0.0.0-...-ae62cf9 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2017 License: MIT Imports: 8 Imported by: 1

README

Go Itunes Library Parser

Due to the unique way that Apple uses the XML format to save iTunes libraries, I have created this small go library to handle parsing the data.

I will be using this library in my own tool for exporting itunes libraries to Spotify, and hopefully you will find uses for this code as well.

Usage

import (
    "fmt"
    "github.com/rydrman/go-itunes-library"
)

libraryFilePath := "path/to/library.xml"

// parse the library file and check for errors
lib, err := itunes.ParseFile(libraryFilePath)
if err != nil {
    panic(err)
}

// print a nice string for each track in the library
for _, track := range lib.Tracks {
    fmt.Println(track)
}

// print a nice string for each playlist in the library
for _, playlist := range lib.Playlists {
    fmt.Println(playlist)
}

Contributing

Please do! If you could run everything through gofmt before submission that would be great, but as this is a tiny library I am not going to be picky.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrInvalidFormat

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

ErrInvalidFormat is returned when an input file does not meet the expected itune library xml format

func NewInvalidFormatError

func NewInvalidFormatError(s string) ErrInvalidFormat

NewInvalidFormatError created a new invalid format error that formats to the given string

func (ErrInvalidFormat) Error

func (err ErrInvalidFormat) Error() string

type Key

type Key struct {
	Value string `xml:"key"`
}

Key is the key of a key value pair in the library xml

type Library

type Library struct {
	MajorVersion        int
	MinorVersion        int
	ApplicationVersion  string
	Date                time.Time
	Features            int
	ShowContentRatings  bool
	LibraryPersistentID string
	MusicFolder         string
	Tracks              []*Track

	Playlists []*Playlist
	// contains filtered or unexported fields
}

Library represents an entire iTunes library data structure

func ParseFile

func ParseFile(filename string) (*Library, error)

ParseFile parses the file at the given filepath as an itunes library file

func ParseReader

func ParseReader(input io.Reader) (*Library, error)

ParseReader parses the given readers bytes as an library xml file

func (*Library) String

func (lib *Library) String() string

String returns a nice string representation of this Library

func (*Library) UnmarshalXML

func (lib *Library) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

UnmarshalXML is a custom unmarshaller function for itunes library xml format

type Playlist

type Playlist struct {
	Master               bool
	PlaylistID           int
	PlaylistPersistentID string
	AllItems             bool
	Visible              bool
	Protected            bool
	Name                 string
	SmartInfo            []byte
	SmartCriteria        []byte
	ParentPersistentID   string
	DistinguishedKind    int
	PurchasedMusic       bool
	Music                bool
	Movies               bool
	TVShows              bool
	Podcasts             bool
	ITunesU              bool
	Audiobooks           bool
	Books                bool
	Folder               bool
	PlaylistItems        []*Track
}

Playlist represents an entire iTunes Playlist data structure

func (*Playlist) String

func (p *Playlist) String() string

func (*Playlist) UnmarshalXML

func (p *Playlist) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

UnmarshalXML is a custom unmarshaller function for itunes Track xml format

type Track

type Track struct {
	TrackID             int
	Size                int
	TotalTime           int
	DiscNumber          int
	DiscCount           int
	TrackNumber         int
	TrackCount          int
	Year                int
	ReleaseDate         time.Time
	DateModified        time.Time
	DateAdded           time.Time
	BitRate             int
	SampleRate          int
	PlayCount           int
	PlayDate            int
	PlayDateUTC         time.Time
	SkipCount           int
	SkipDate            time.Time
	Rating              int
	RatingComputed      bool
	AlbumRating         int
	AlbumRatingComputed bool
	ArtworkCount        int
	PersistentID        string
	TrackType           string
	FileFolderCount     int
	LibraryFolderCount  int
	Compilation         bool
	Name                string
	Artist              string
	AlbumArtist         string
	Composer            string
	Album               string
	Genre               string
	Kind                string
	Location            string
	Podcast             bool
	Unplayed            bool
	SortArtist          string
	SortName            string
	SortAlbum           string
	SortAlbumArtist     string
	SortComposer        string
	Purchased           bool
	Explicit            bool
	Comments            string
	Loved               bool
	Grouping            string
	BPM                 int
	Protected           bool
	HasVideo            bool
	VolumeAdjustment    int
	StartTime           int
	StopTime            int
	Movie               bool
	ITunesU             bool
	Disabled            bool
	PartOfGaplessAlbum  bool
	Series              string
	Episode             string
	EpisodeOrder        int
	TVShow              bool
	Season              string
	ContentRating       string
	Equalizer           string
}

Track represents an entire iTunes Track data structure

func (*Track) String

func (t *Track) String() string

func (*Track) UnmarshalXML

func (t *Track) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

UnmarshalXML is a custom unmarshaller function for itunes Track xml format

Jump to

Keyboard shortcuts

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