-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitl.go
155 lines (130 loc) · 4.49 KB
/
itl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2014, David Howden
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package itl defines data types for importing iTunes Library XML (plist) files.
package itl
import (
"io"
"io/ioutil"
"time"
"github.com/dhowden/plist"
)
// Library represents the root iTunes library entity which includes a map of tracks and slice of
// playlists.
type Library struct {
MajorVersion int `plist:"Major Version"`
MinorVersion int `plist:"Minor Version"`
Date time.Time
ApplicationVersion string `plist:"Application Version"`
Features int
ShowContentRatings bool `plist:"Show Content Ratings"`
MusicFolder string `plist:"Music Folder"`
LibraryPersistentID string `plist:"Library Persistent ID"`
Tracks map[string]Track
Playlists []Playlist
}
// Track represents an iTunes library track, which is a media file which can either be music or video.
// Items are identified in iTunes using the TrackID.
type Track struct {
TrackID int `plist:"Track ID"`
Name string
Artist string
Composer string
Year int
Genre string
Kind string
Size int
BPM int
TrackNumber int `plist:"Track Number"`
TrackCount int `plist:"Track Count"`
DiscNumber int `plist:"Disc Number"`
DiscCount int `plist:"Disc Count"`
PartOfGaplessAlbum bool `plist:"Part Of Gapless Album"`
ContentRating string `plist:"Content Rating"`
Rating int
RatingComputed bool `plist:"Rating Computed"`
Disabled bool
Loved bool `plist:"Loved"`
Album string
AlbumArtist string `plist:"Album Artist"`
AlbumRating int `plist:"Album Rating"`
AlbumRatingComputed bool `plist:"Album Rating Computed"`
AlbumLoved bool `plist:"Album Loved"`
SortName string `plist:"Sort Name"`
SortArtist string `plist:"Sort Artist"`
SortAlbumArtist string `plist:"Sort Album Artist"`
SortAlbum string `plist:"Sort Album"`
SortComposer string `plist:"Sort Composer"`
Clean bool
Series string
TotalTime int `plist:"Total Time"`
DateModified time.Time `plist:"Date Modified"`
DateAdded time.Time `plist:"Date Added"`
BitRate int `plist:"Bit Rate"`
SampleRate int `plist:"Sample Rate"`
VolumeAdjustment int `plist:"Volume Adjustment"`
Comments string
PlayCount int `plist:"Play Count"`
PlayDate int `plist:"Play Date"`
PlayDateUTC time.Time `plist:"Play Date UTC"`
Protected bool
Purchased bool
SkipCount int `plist:"Skip Count"`
SkipDate time.Time `plist:"Skip Date"`
ArtworkCount int `plist:"Artwork Count"`
Episode string
EpisodeOrder int `plist:"Episode Order"`
TVShow bool `plist:"TV Show"`
Season int
Podcast bool
ITunesU bool `plist:"iTunesU"`
Unplayed bool
PersistentID string `plist:"Persistent ID"`
TrackType string `plist:"Track Type"`
Location string
FileType int `plist:"File Type"`
Movie bool
MusicVideo bool `plist:"Music Video"`
HD bool
HasVideo bool `plist:"Has Video"`
VideoHeight int `plist:"Video Height"`
VideoWidth int `plist:"Video Width"`
Grouping string
Compilation bool
ReleaseDate time.Time `plist:"Release Date"`
FileFolderCount int `plist:"File Folder Count"`
LibraryFolderCount int `plist:"Library Folder Count"`
}
// Playlist represents an iTunes playlist.
type Playlist struct {
Name string
Master bool
PlaylistID int `plist:"Playlist ID"`
ParentPersistentID string `plist:"Parent Persistent ID"`
PlaylistPersistentID string `plist:"Playlist Persistent ID"`
DistinguishedKind int `plist:"Distinguished Kind"`
Visible bool
Music bool
Movies bool
TVShows bool `plist:"TV Shows"`
Podcasts bool
ITunesU bool `plist:"iTunesU"`
Audiobooks bool
AllItems bool `plist:"All Items"`
Folder bool
PlaylistItems []PlaylistItem `plist:"Playlist Items"`
}
// PlaylistItem represents an individual track in a an iTunes playlist.
type PlaylistItem struct {
TrackID int `plist:"Track ID"`
}
// ReadFromXML reads iTunes XML (plist) data from the underlying io.Reader
// returning the resuling Library.
func ReadFromXML(r io.Reader) (l Library, err error) {
b, err := ioutil.ReadAll(r)
if err != nil {
return
}
err = plist.Unmarshal(b, &l)
return
}