itunes

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package itunes-win enables you to handle iTunes on Windows in Go. This is a thin wrapper of iTunes COM interface.

Note this library doesn't relect all of the methods and the properties of iTunes COM interface.

Initialization must be done first of all by Init. Exit also must be called at the end:

it, err := itunes.Init()
defer it.Exit()

For control over iTunes application, use ITunes object returned:

it.Play()

For control over main library playlist, get Playlist via GetMainPlaylist:

p, err := it.GetMainPlaylist()
if err != nil {
	// handle error
}
p.PlayFirstTrack()

For control over tracks in the playlist, get Tracks via GetTracks. Likewise, you can control each track in the tracks via Track got by GetTrackByIndex or GetTrackByName:

t, err := p.GetTracks()
// ...
c64, _ := tracks.GetCount()
count := int(c64)
for i := 1; i <= count; i++ {
	track, _ := tracks.GetTrackByIndex(i)
}

Index

Constants

View Source
const (
	// RepeatOff sets repeat mode off.
	RepeatOff = iota
	// RepeatSong repeats the song.
	RepeatSong
	// RepeatAll repeats the playlist.
	RepeatAll
)

Variables

This section is empty.

Functions

This section is empty.

Types

type COM

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

COM is just an abstraction for *ole.IDispatch.

func (*COM) IsNil

func (c *COM) IsNil() bool

func (*COM) Name added in v0.2.1

func (c *COM) Name() string

func (*COM) ObjectIDs added in v0.2.1

func (c *COM) ObjectIDs() (sourceID int, playlistID int, trackID int, databaseID int, err error)

type ITPlaylistKind added in v0.2.1

type ITPlaylistKind int
const (
	ITPlaylistKindUnknown ITPlaylistKind = iota
	ITPlaylistKindLibrary
	ITPlaylistKindUser
	ITPlaylistKindCD
	ITPlaylistKindDevice
	ITPlaylistKindRadioTuner
)

func (ITPlaylistKind) String added in v0.2.1

func (i ITPlaylistKind) String() string

type ITRatingKind added in v0.2.1

type ITRatingKind int
const (
	ITRatingKindUser ITRatingKind = iota
	ITRatingKindComputed
)

func (ITRatingKind) String added in v0.2.1

func (i ITRatingKind) String() string

type ITSourceKind added in v0.2.1

type ITSourceKind int
const (
	ITSourceKindUnknown ITSourceKind = iota
	ITSourceKindLibrary
	ITSourceKindIPod
	ITSourceKindAudioCD
	ITSourceKindMP3CD
	ITSourceKindDevice
	ITSourceKindRadioTuner
	ITSourceKindSharedLibrary
)

func (ITSourceKind) String added in v0.2.1

func (i ITSourceKind) String() string

type ITTrackKind added in v0.2.1

type ITTrackKind int
const (
	ITTrackKindUnknown ITTrackKind = iota
	ITTrackKindFile
	ITTrackKindCD
	ITTrackKindURL
	ITTrackKindDevice
	ITTrackKindSharedLibrary
)

func (ITTrackKind) String added in v0.2.1

func (i ITTrackKind) String() string

type ITUserPlaylistSpecialKind added in v0.2.1

type ITUserPlaylistSpecialKind int
const (
	ITUserPlaylistSpecialKindNone ITUserPlaylistSpecialKind = iota
	ITUserPlaylistSpecialKindPurchasedMusic
	ITUserPlaylistSpecialKindPartyShuffle
	ITUserPlaylistSpecialKindPodcasts
	ITUserPlaylistSpecialKindFolder
	ITUserPlaylistSpecialKindVideos
	ITUserPlaylistSpecialKindMusic
	ITUserPlaylistSpecialKindMovies
	ITUserPlaylistSpecialKindTVShows
	ITUserPlaylistSpecialKindAudiobooks
)

func (ITUserPlaylistSpecialKind) String added in v0.2.1

func (i ITUserPlaylistSpecialKind) String() string

type ITVideoKind added in v0.2.1

type ITVideoKind int
const (
	ITVideoKindNone ITVideoKind = iota
	ITVideoKindMovie
	ITVideoKindMusicVideo
	ITVideoKindTVShow
)

type ITunes

type ITunes struct {
	COM
}

ITunes is an object to abstract top level iTunes application. This represents IiTunes object in COM interface.

func Init

func Init() (*ITunes, error)

Init initializes COM library and returns ITunes reference. This must be called at the beginning.

func (*ITunes) BackTrack

func (i *ITunes) BackTrack() error

BackTrack repositions to the beginning of the current track or go to the previous track if already at start of current track.

func (*ITunes) CreateFolder added in v0.2.1

func (i *ITunes) CreateFolder(name string) (*Playlist, error)

func (*ITunes) CreatePlaylist added in v0.2.1

func (i *ITunes) CreatePlaylist(name string) (*Playlist, error)

func (*ITunes) CurrentEncoder

func (i *ITunes) CurrentEncoder() (string, error)

CurrentEncoder returns the currently selected encoder (AAC, MP3, AIFF, WAV, etc).

func (*ITunes) Exit

func (i *ITunes) Exit()

Exit does uninitialization of COM library. This must be called at the end.

func (*ITunes) GetMainPlaylist

func (i *ITunes) GetMainPlaylist() (*Playlist, error)

GetMainPlaylist returns main library playlist, Playlist.

func (*ITunes) Mute

func (i *ITunes) Mute(val bool) error

Mute sets sound output mute state, depending on val (true sets mute on, false sets it off).

func (*ITunes) NextTrack

func (i *ITunes) NextTrack() error

NextTrack advances to the next track in the current playlist.

func (*ITunes) ObjectPersistentID

func (i *ITunes) ObjectPersistentID(obj interface{}) (PersistentID, error)

func (*ITunes) Pause

func (i *ITunes) Pause() error

Pause pauses current track play.

func (*ITunes) Play

func (i *ITunes) Play() error

Play plays the currently targeted track.

func (*ITunes) Playlist added in v0.2.1

func (i *ITunes) Playlist(pid PersistentID) (*Playlist, error)

func (*ITunes) Playlists added in v0.2.1

func (i *ITunes) Playlists() (*PlaylistCollection, error)

func (*ITunes) PreviousTrack

func (i *ITunes) PreviousTrack() error

PreviousTrack returns to the previous track in the current playlist.

func (*ITunes) QuitApp

func (i *ITunes) QuitApp() error

QuitApp makes iTunes appilcation exit.

func (*ITunes) SoundVolume

func (i *ITunes) SoundVolume(val int) error

SoundVolume sets the sound output volue. You can set from 0 (minimum) to 100 (maximum).

func (*ITunes) Stop

func (i *ITunes) Stop() error

Stop stops the playback.

func (*ITunes) SubscribeToPodcast

func (i *ITunes) SubscribeToPodcast(u string) error

SubscribeToPodcast subscribes to the specified podcast url u.

func (*ITunes) UpdatePodcastFeeds

func (i *ITunes) UpdatePodcastFeeds() error

UpdatePodcastFeeds updates all podcast feeds.

type OperationStatus added in v0.2.3

type OperationStatus struct {
	COM
}

func (*OperationStatus) GetTracks added in v0.2.3

func (o *OperationStatus) GetTracks() (*TrackCollection, error)

type PersistentID added in v0.2.1

type PersistentID uint64

func ParsePersistentID added in v0.2.1

func ParsePersistentID(str string) (PersistentID, error)

func (PersistentID) High added in v0.2.1

func (p PersistentID) High() int

func (PersistentID) Low added in v0.2.1

func (p PersistentID) Low() int

func (PersistentID) String added in v0.2.1

func (p PersistentID) String() string

type Playlist

type Playlist struct {
	COM
}

Playlist is an object to abstract the main library playlist. This is child for ITunes struct and represents IITPlaylist object in COM interface.

func (*Playlist) AddFile

func (p *Playlist) AddFile(path string) (*OperationStatus, error)

AddFile adds path to this playlist.

func (*Playlist) AddTrack added in v0.2.1

func (p *Playlist) AddTrack(track *Track) error

func (*Playlist) CreateFolder added in v0.2.1

func (p *Playlist) CreateFolder(name string) (*Playlist, error)

func (*Playlist) CreatePlaylist added in v0.2.1

func (p *Playlist) CreatePlaylist(name string) (*Playlist, error)

func (*Playlist) Delete

func (p *Playlist) Delete() error

Delete deletes this playlist.

func (*Playlist) Duration added in v0.2.1

func (p *Playlist) Duration() (time.Duration, error)

func (*Playlist) GetTracks

func (p *Playlist) GetTracks() (*TrackCollection, error)

GetTracks returns Tracks in this playlist.

func (*Playlist) IsSmart added in v0.2.1

func (p *Playlist) IsSmart() (bool, error)

func (*Playlist) Kind added in v0.2.1

func (p *Playlist) Kind() ITPlaylistKind

func (*Playlist) Parent added in v0.2.1

func (p *Playlist) Parent() (*Playlist, error)

func (*Playlist) PlayFirstTrack

func (p *Playlist) PlayFirstTrack() error

PlayFirstTrack starts play the first track in this playlist.

func (*Playlist) SearchAlbums

func (p *Playlist) SearchAlbums(word string) (int, *TrackCollection, error)

SearchAlbums searches only the album field of each track. It returns the number of track found, tracks found as *Tracks and error if any.

func (*Playlist) SearchAll

func (p *Playlist) SearchAll(word string) (int, *TrackCollection, error)

SearchAll searches all fields of each track. It returns the number of track found, tracks found as *Tracks and error if any.

func (*Playlist) SearchArtists

func (p *Playlist) SearchArtists(word string) (int, *TrackCollection, error)

SearchArtists searches only the artist field of each track. It returns the number of track found, tracks found as *Tracks and error if any.

func (*Playlist) SearchComposers

func (p *Playlist) SearchComposers(word string) (int, *TrackCollection, error)

SearchComposers searches only the composer field of each track. It returns the number of track found, tracks found as *Tracks and error if any.

func (*Playlist) SearchSongNames

func (p *Playlist) SearchSongNames(word string) (int, *TrackCollection, error)

SearchSongNames searches only the song name field of each track. It returns the number of track found, tracks found as *Tracks and error if any.

func (*Playlist) SearchVisible

func (p *Playlist) SearchVisible(word string) (int, *TrackCollection, error)

SearchVisible searches only the fields with columns that are currently visible in the display for the playlist. It returns the number of track found, tracks found as *Tracks and error if any.

func (*Playlist) SetParent added in v0.2.1

func (p *Playlist) SetParent(parent *Playlist) error

func (*Playlist) SetRepeat

func (p *Playlist) SetRepeat(mode int) error

SetRepeat sets playlist repeat mode. Please specify any one of RepeatOff, RepeatSong or RepeatAll.

func (*Playlist) SetShuffle

func (p *Playlist) SetShuffle(val bool) error

SetShuffle sets this playlist shuffle mode (played in random order).

func (*Playlist) Shuffle added in v0.2.1

func (p *Playlist) Shuffle() (bool, error)

func (*Playlist) Size added in v0.2.1

func (p *Playlist) Size() (uint64, error)

func (*Playlist) SpecialKind added in v0.2.1

func (p *Playlist) SpecialKind() (ITUserPlaylistSpecialKind, error)

type PlaylistCollection added in v0.2.1

type PlaylistCollection struct {
	COM
}

Playlist is an object to abstract the collection of library playlists. This is child for ITunes struct and represents IITPlaylistCollection object in COM interface.

func (*PlaylistCollection) ByIndex added in v0.2.1

func (p *PlaylistCollection) ByIndex(idx int) (*Playlist, error)

func (*PlaylistCollection) ByName added in v0.2.1

func (p *PlaylistCollection) ByName(name string) (*Playlist, error)

func (*PlaylistCollection) ByPersistentID added in v0.2.1

func (p *PlaylistCollection) ByPersistentID(pid PersistentID) (*Playlist, error)

func (*PlaylistCollection) Count added in v0.2.1

func (p *PlaylistCollection) Count() (int64, error)

type Track

type Track struct {
	COM
}

Track is an object to abstract a music track. This is child for Track struct and represents IITTrack object in COM interface.

func (*Track) AddArtwork

func (t *Track) AddArtwork(file string) error

AddArtwork adds artwork from an image file to this track.

func (*Track) Delete

func (t *Track) Delete() error

Delete deletes this track.

func (*Track) GetAlbum

func (t *Track) GetAlbum() (string, error)

GetAlbum returns the name of the album containing the track.

func (*Track) GetAlbumArtist

func (t *Track) GetAlbumArtist() (string, error)

GetAlbumArtist returns the name of the album artist of the track.

func (*Track) GetAlbumRating

func (t *Track) GetAlbumRating() (int64, error)

GetAlbumRating returns the user or computed rating of the album that this track belongs to (0 to 100). If the album rating has never been set, or has been set to 0.

func (*Track) GetArtist

func (t *Track) GetArtist() (string, error)

GetArtist returns the name of the artist of the track.

func (*Track) GetBPM

func (t *Track) GetBPM() (int64, error)

GetBPM returns the BPM of the track.

func (*Track) GetBitRate

func (t *Track) GetBitRate() (int64, error)

GetBitRate returns the bit rate of the track (in kbps).

func (*Track) GetCategory

func (t *Track) GetCategory() (string, error)

GetCategory returns the category for the track.

func (*Track) GetComment

func (t *Track) GetComment() (string, error)

GetComment returns the comment of the track.

func (*Track) GetComposer

func (t *Track) GetComposer() (string, error)

GetComposer returns the composer of the track.

func (*Track) GetDateAdded

func (t *Track) GetDateAdded() (time.Time, error)

func (*Track) GetDescription

func (t *Track) GetDescription() (string, error)

GetDescription returns the description for the track.

func (*Track) GetDuration

func (t *Track) GetDuration() (int64, error)

GetDuration returns the length of the track.

func (*Track) GetExcludeFromShuffle

func (t *Track) GetExcludeFromShuffle() (bool, error)

GetExcludeFromShuffle true if this track is skipped when shuffling.

func (*Track) GetGenre

func (t *Track) GetGenre() (string, error)

GetGenre returns the genre of the track.

func (*Track) GetLocation

func (t *Track) GetLocation() (string, error)

GetLocation returns the full path to the file represented by this track.

func (*Track) GetLylics

func (t *Track) GetLylics() (string, error)

GetLylics returns the lyrics for the track.

func (*Track) GetName

func (t *Track) GetName() (string, error)

GetName returns the name of the track.

func (*Track) GetPersistentIDHigh

func (t *Track) GetPersistentIDHigh() (int64, error)

func (*Track) GetPersistentIDLow

func (t *Track) GetPersistentIDLow() (int64, error)

func (*Track) GetPlayedCount

func (t *Track) GetPlayedCount() (int64, error)

GetPlayedCount returns the number of times the track has been played.

func (*Track) GetRating

func (t *Track) GetRating() (int64, error)

func (*Track) GetRememberBookmark

func (t *Track) GetRememberBookmark() (bool, error)

GetRememberBookmark returns true if playback position is remembered for this track.

func (*Track) GetSize

func (t *Track) GetSize() (int64, error)

GetSize returns the size of the track (in bytes).

func (*Track) GetTrackNumber

func (t *Track) GetTrackNumber() (int64, error)

GetTrackNumber returns the index of the track on album.

func (*Track) GetURL

func (t *Track) GetURL() (string, error)

GetURL returns the URL of the stream represented by this track.

func (*Track) GetYear

func (t *Track) GetYear() (int64, error)

GetYear returns the year the track was recorded/released.

func (*Track) Kind added in v0.2.1

func (t *Track) Kind() ITTrackKind

GetKind returns the kind of the track in string.

func (*Track) Play

func (t *Track) Play() error

Play plays this track.

func (*Track) SetAlbum

func (t *Track) SetAlbum(val string) error

SetAlbum sets the name of the album containing the track.

func (*Track) SetAlbumRating

func (t *Track) SetAlbumRating(val int) error

SetAlbumRating sets the user or computed rating of the album that this track belongs to (0 to 100). If the album rating is set to 0, it will be computed based on the ratings of tracks in the album.

func (*Track) SetArtist

func (t *Track) SetArtist(val string) error

SetArtist sets the name of the artist of the track.

func (*Track) SetBPM

func (t *Track) SetBPM(val int) error

SetBPM sets the BPM of the track.

func (*Track) SetCategory

func (t *Track) SetCategory(val string) error

SetCategory sets the category for the track.

func (*Track) SetComment

func (t *Track) SetComment(val string) error

SetComment sets the comment of the track.

func (*Track) SetComposer

func (t *Track) SetComposer(val string) error

SetComposer sets the composer of the track.

func (*Track) SetDescription

func (t *Track) SetDescription(val string) error

SetDescription the description for the track.

func (*Track) SetGenre

func (t *Track) SetGenre(val string) error

SetGenre sets the genre of the track.

func (*Track) SetLocation added in v0.2.0

func (t *Track) SetLocation(location string) error

func (*Track) SetName

func (t *Track) SetName(val string) error

SetName sets the name of the track.

func (*Track) SetPlayedCount

func (t *Track) SetPlayedCount(val int) error

SetPlayedCount sets the number of times the track has been played.

func (*Track) SetRating

func (t *Track) SetRating(val int) error

func (*Track) SetRememberBookmark

func (t *Track) SetRememberBookmark(val bool) error

SetRememberBookmark sets whether the playback position is remembered for this track.

func (*Track) SetTrackNumber

func (t *Track) SetTrackNumber(val int) error

SetTrackNumber sets the index of the track on album.

func (*Track) SetURL

func (t *Track) SetURL(url string) error

SetURL sets the URL of the stream represented by this track.

func (*Track) SetYear

func (t *Track) SetYear(val int) error

SetYear sets the year the track was recorded/released.

type TrackCollection added in v0.2.1

type TrackCollection struct {
	COM
}

TrackCollection is an object to abstract a collection of music track. This is child for Playlist struct and represents IITTrackCollection object in COM interface.

func (*TrackCollection) ByIndex added in v0.2.1

func (t *TrackCollection) ByIndex(index int) (*Track, error)

GetTrackByIndex returns Track in t, corresponding to the given index (1-based).

func (*TrackCollection) ByName added in v0.2.1

func (t *TrackCollection) ByName(name string) (*Track, error)

GetTrackByName returns Track in t with the specified name.

func (*TrackCollection) ByPersistentID added in v0.2.1

func (t *TrackCollection) ByPersistentID(pid PersistentID) (*Track, error)

GetTrackByName returns Track in t with the specified name.

func (*TrackCollection) ByPlayOrder added in v0.2.3

func (t *TrackCollection) ByPlayOrder(order int) (*Track, error)

func (*TrackCollection) Count added in v0.2.1

func (t *TrackCollection) Count() (int64, error)

GetCount returns the number of track in this tracks.

Jump to

Keyboard shortcuts

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