github.com/boki/go-xmp@v1.0.1/models/itunes/model.go (about) 1 // Copyright (c) 2017-2018 Alexander Eichhorn 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 // iTunes-style metadata as found in .mp4, .m4a, .m4p, .m4v, .m4b files 16 17 // Package itunes implements metadata models found in Apple iTunes audio and video files. 18 package itunes 19 20 import ( 21 "fmt" 22 23 "trimmer.io/go-xmp/xmp" 24 ) 25 26 var ( 27 NsITunes = xmp.NewNamespace("iTunes", "http://ns.apple.com/itunes/1.0/", NewModel) 28 ) 29 30 func init() { 31 xmp.Register(NsITunes, xmp.MusicMetadata) 32 } 33 34 func NewModel(name string) xmp.Model { 35 return &ITunesMetadata{} 36 } 37 38 func MakeModel(d *xmp.Document) (*ITunesMetadata, error) { 39 m, err := d.MakeModel(NsITunes) 40 if err != nil { 41 return nil, err 42 } 43 x, _ := m.(*ITunesMetadata) 44 return x, nil 45 } 46 47 func FindModel(d *xmp.Document) *ITunesMetadata { 48 if m := d.FindModel(NsITunes); m != nil { 49 return m.(*ITunesMetadata) 50 } 51 return nil 52 } 53 54 func (m *ITunesMetadata) Namespaces() xmp.NamespaceList { 55 return xmp.NamespaceList{NsITunes} 56 } 57 58 func (m *ITunesMetadata) Can(nsName string) bool { 59 return nsName == NsITunes.GetName() 60 } 61 62 func (x *ITunesMetadata) SyncModel(d *xmp.Document) error { 63 return nil 64 } 65 66 func (x *ITunesMetadata) SyncFromXMP(d *xmp.Document) error { 67 return nil 68 } 69 70 func (x ITunesMetadata) SyncToXMP(d *xmp.Document) error { 71 return nil 72 } 73 74 func (x *ITunesMetadata) CanTag(tag string) bool { 75 _, err := xmp.GetNativeField(x, tag) 76 return err == nil 77 } 78 79 func (x *ITunesMetadata) GetTag(tag string) (string, error) { 80 if v, err := xmp.GetNativeField(x, tag); err != nil { 81 return "", fmt.Errorf("%s: %v", NsITunes.GetName(), err) 82 } else { 83 return v, nil 84 } 85 } 86 87 func (x *ITunesMetadata) SetTag(tag, value string) error { 88 if err := xmp.SetNativeField(x, tag, value); err != nil { 89 return fmt.Errorf("%s: %v", NsITunes.GetName(), err) 90 } 91 return nil 92 } 93 94 // Lists all non-empty tags. 95 func (x *ITunesMetadata) ListTags() (xmp.TagList, error) { 96 if l, err := xmp.ListNativeFields(x); err != nil { 97 return nil, fmt.Errorf("%s: %v", NsITunes.GetName(), err) 98 } else { 99 return l, nil 100 } 101 } 102 103 // iTunes specific Quicktime metadata tags 104 // itms: iTunes storage format atom 105 // itlk: mdta-style atoms Reverse DNS (com.apple.itunes) 106 // itsk: udta-style FourCC atoms 107 type ITunesMetadata struct { 108 AccountKind AppleStoreAccountType `iTunes:"akID" xmp:"iTunes:AccountKind"` 109 Acknowledgement string `iTunes:"©cak" xmp:"iTunes:Acknowledgement"` 110 Album string `iTunes:"©alb" xmp:"iTunes:Album"` 111 AlbumArtist string `iTunes:"aART" xmp:"iTunes:AlbumArtist"` 112 AppleID string `iTunes:"apID" xmp:"iTunes:AppleID"` 113 Arranger string `iTunes:"©arg" xmp:"iTunes:Arranger"` 114 ArtDirector string `iTunes:"©ard" xmp:"iTunes:ArtDirector"` 115 Artist string `iTunes:"©ART" xmp:"iTunes:Artist"` 116 ArtistID string `iTunes:"atID" xmp:"iTunes:ArtistID"` 117 Author string `iTunes:"©aut" xmp:"iTunes:Author"` 118 BeatsPerMin int `iTunes:"tmpo" xmp:"iTunes:BeatsPerMin"` 119 Comment string `iTunes:"©cmt" xmp:"iTunes:Comment"` 120 Composer string `iTunes:"©wrt" xmp:"iTunes:Composer"` 121 Conductor string `iTunes:"©con" xmp:"iTunes:Conductor"` 122 IsExplicit RatingCode `iTunes:"rtng" xmp:"iTunes:IsExplicit"` 123 Copyright string `iTunes:"cprt" xmp:"iTunes:Copyright"` 124 CoverArt string `iTunes:"covr" xmp:"iTunes:CoverArt"` 125 CoverUrl xmp.Url `iTunes:"cvru" xmp:"iTunes:CoverUrl"` 126 Credits string `iTunes:"©src" xmp:"iTunes:Credits"` 127 Description string `iTunes:"©des" xmp:"iTunes:Description"` 128 Director string `iTunes:"©dir" xmp:"iTunes:Director"` 129 DiscNumber xmp.Rational `iTunes:"disk" xmp:"iTunes:DiscNumber"` 130 Duration int64 `iTunes:"dcfD" xmp:"iTunes:Duration"` 131 EncodedBy string `iTunes:"©enc" xmp:"iTunes:EncodedBy"` 132 EncodingTool string `iTunes:"©too" xmp:"iTunes:EncodingTool"` 133 EQ string `iTunes:"©equ" xmp:"iTunes:EQ"` 134 ExecProducer string `iTunes:"©xpd" xmp:"iTunes:ExecProducer"` 135 GenreCode GenreCode `iTunes:"gnre" xmp:"iTunes:GenreCode"` // Predefined, = ID3 genres 136 GenreID GenreID `iTunes:"geID" xmp:"iTunes:GenreID"` 137 GenreName string `iTunes:"©gen" xmp:"iTunes:GenreName"` // user defined 138 Grouping string `iTunes:"grup" xmp:"iTunes:Grouping"` // like TIT1 in ID3 139 IconUrl xmp.Url `iTunes:"icnu" xmp:"iTunes:IconUrl"` 140 InfoUrl xmp.Url `iTunes:"infu" xmp:"iTunes:InfoUrl"` 141 IsDiscCompilation Bool `iTunes:"cpil" xmp:"iTunes:IsDiscCompilation"` 142 IsGaplessPlayback PlayGapMode `iTunes:"pgap" xmp:"iTunes:IsGaplessPlayback"` 143 IsHDVideo Bool `iTunes:"hdvd" xmp:"iTunes:IsHDVideo"` 144 IsiTunesU string `iTunes:"itnu" xmp:"iTunes:IsiTunesU"` 145 IsPodcast Bool `iTunes:"pcst" xmp:"iTunes:IsPodcast"` 146 Keywords string `iTunes:"keyw" xmp:"iTunes:Keywords"` 147 LinerNotes string `iTunes:"©lnt" xmp:"iTunes:LinerNotes"` 148 Lyrics string `iTunes:"©lyr" xmp:"iTunes:Lyrics"` 149 LyricsUrl string `iTunes:"lrcu" xmp:"iTunes:LyricsUrl"` 150 MediaType MediaType `iTunes:"stik" xmp:"iTunes:MediaType"` 151 Narrator string `iTunes:"©nrt" xmp:"iTunes:Narrator"` 152 OnlineExtras string `iTunes:"©url" xmp:"iTunes:OnlineExtras"` 153 OriginalArtist string `iTunes:"©ope" xmp:"iTunes:OriginalArtist"` 154 Performer string `iTunes:"©prf" xmp:"iTunes:Performer"` 155 PhonogramRights string `iTunes:"©phg" xmp:"iTunes:PhonogramRights"` 156 PlaylistID string `iTunes:"plID" xmp:"iTunes:PlaylistID"` 157 PodcastCategory string `iTunes:"catg" xmp:"iTunes:PodcastCategory"` 158 PodcastGuid string `iTunes:"egid" xmp:"iTunes:PodcastGuid"` 159 PodcastUrl string `iTunes:"purl" xmp:"iTunes:PodcastUrl"` 160 Producer string `iTunes:"©prd" xmp:"iTunes:Producer"` 161 ProductID string `iTunes:"prID" xmp:"iTunes:ProductID"` 162 Publisher string `iTunes:"©pub" xmp:"iTunes:Publisher"` 163 PurchaseDate xmp.Date `iTunes:"purd" xmp:"iTunes:PurchaseDate"` 164 RatingPercent string `iTunes:"rate" xmp:"iTunes:RatingPercent"` 165 RecordCompany string `iTunes:"©mak" xmp:"iTunes:RecordCompany"` 166 ReleaseDate xmp.Date `iTunes:"©day" xmp:"iTunes:ReleaseDate"` 167 ShowEpisodeName string `iTunes:"tves" xmp:"iTunes:ShowEpisodeName"` 168 ShowEpisodeNum int `iTunes:"tven" xmp:"iTunes:ShowEpisodeNum"` 169 ShowName string `iTunes:"tvsh" xmp:"iTunes:ShowName"` 170 ShowSeasonNum int `iTunes:"tvsn" xmp:"iTunes:ShowSeasonNum"` 171 Soloist string `iTunes:"©sol" xmp:"iTunes:Soloist"` 172 SongID string `iTunes:"cnID" xmp:"iTunes:SongID"` // content ID, AppleStoreCatalogID 173 SortAlbum string `iTunes:"soal" xmp:"iTunes:SortAlbum"` 174 SortAlbumArtist string `iTunes:"soaa" xmp:"iTunes:SortAlbumArtist"` 175 SortArtist string `iTunes:"soar" xmp:"iTunes:SortArtist"` 176 SortComposer string `iTunes:"soco" xmp:"iTunes:SortComposer"` 177 SortName string `iTunes:"sonm" xmp:"iTunes:SortName"` 178 SortShow string `iTunes:"sosn" xmp:"iTunes:SortShow"` 179 SoundEngineer string `iTunes:"©sne" xmp:"iTunes:SoundEngineer"` 180 StoreFrontID string `iTunes:"sfID" xmp:"iTunes:StoreFrontID"` // apple store country 181 Synopsis string `iTunes:"ldes" xmp:"iTunes:Synopsis"` 182 Thanks string `iTunes:"©thx" xmp:"iTunes:Thanks"` 183 Title string `iTunes:"©nam" xmp:"iTunes:Title"` 184 ToolInfo string `iTunes:"tool" xmp:"iTunes:ToolInfo"` 185 TrackNumber int `iTunes:"trkn" xmp:"iTunes:TrackNumber"` 186 TrackSubTitle string `iTunes:"©st3" xmp:"iTunes:TrackSubTitle"` 187 TVNetworkName string `iTunes:"tvnn" xmp:"iTunes:TVNetworkName"` 188 XID string `iTunes:"xid " xmp:"iTunes:XID"` 189 190 ContentRating *ContentRating `iTunes:"iTunEXTC" xmp:"iTunes:ContentRating"` 191 SoundCheck []byte `iTunes:"iTunNORM" xmp:"iTunes:SoundCheck"` 192 SMPB *SMPB `iTunes:"iTunSMPB" xmp:"iTunes:SMPB"` 193 IsGaplessPlayback2 Bool `iTunes:"iTunPGAP" xmp:"iTunes:IsGaplessPlayback2"` 194 MovieInfo *MovieInfo `iTunes:"iTunMOVI" xmp:"iTunes:MovieInfo"` 195 CDDBToc string `iTunes:"iTunes_CDDB_1" xmp:"iTunes:CDDBToc"` 196 CDDBTrackNumber string `iTunes:"iTunes_CDDB_TrackNumber" xmp:"iTunes:CDDBTrackNumber"` 197 CDDBMediaID string `iTunes:"iTunes_CDDB_IDs" xmp:"iTunes:CDDBMediaID"` 198 EncodingParams []byte `iTunes:"Encoding Params" xmp:"iTunes:EncodingParams"` 199 200 Extension xmp.TagList `iTunes:",any" xmp:"iTunes:extension"` 201 }