From fd690cd0a3fdfb09437ee93318e4112e703e5eaf Mon Sep 17 00:00:00 2001 From: hanafizaki <168611060+hanafizaki@users.noreply.github.com> Date: Fri, 3 May 2024 09:19:56 +0800 Subject: [PATCH] FIX + ADD EXTENDED METADATA + Fix Disk Number Metadata !!!NEED FIX (TOTAL DISKNUMBER)!!! + Change Released Date Year = [full released year] + Add ArtistID (atID) + Add AlbumID (plID) + Add Publisher (A9pub) + Add Album Sort (soaa) + Add TrackID (cnID) + Add Composer Sort (soco) + Add Performer (A9prf) + Performer =[add both (mp3tag cannot read mp4TAG)] + Add Artist Sort (soar) + Album Sort (soal) + Title Sort (sonm) --- main.go | 106 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 33 deletions(-) diff --git a/main.go b/main.go index b0d5ba9..196af98 100644 --- a/main.go +++ b/main.go @@ -674,35 +674,65 @@ func writeM4a(w *mp4.Writer, info *SongInfo, meta *AutoGenerated, data []byte, t return err } + err = addMeta(mp4.BoxType{'s', 'o', 'n', 'm'}, meta.Data[0].Relationships.Tracks.Data[index].Attributes.Name) + if err != nil { + return err + } + err = addMeta(mp4.BoxType{'\251', 'a', 'l', 'b'}, meta.Data[0].Attributes.Name) if err != nil { return err } + err = addMeta(mp4.BoxType{'s', 'o', 'a', 'l'}, meta.Data[0].Attributes.Name) + if err != nil { + return err + } + err = addMeta(mp4.BoxType{'\251', 'A', 'R', 'T'}, meta.Data[0].Relationships.Tracks.Data[index].Attributes.ArtistName) if err != nil { return err } + err = addMeta(mp4.BoxType{'s', 'o', 'a', 'r'}, meta.Data[0].Relationships.Tracks.Data[index].Attributes.ArtistName) + if err != nil { + return err + } + + err = addMeta(mp4.BoxType{'\251', 'p', 'r', 'f'}, meta.Data[0].Relationships.Tracks.Data[index].Attributes.ArtistName) + if err != nil { + return err + } + + err = addExtendedMeta("PERFORMER", meta.Data[0].Relationships.Tracks.Data[index].Attributes.ArtistName) + if err != nil { + return err + } + err = addMeta(mp4.BoxType{'\251', 'w', 'r', 't'}, meta.Data[0].Relationships.Tracks.Data[index].Attributes.ComposerName) if err != nil { return err } - err = addMeta(mp4.BoxType{'\251', 'd', 'a', 'y'}, strings.Split(meta.Data[0].Attributes.ReleaseDate, "-")[0]) + err = addMeta(mp4.BoxType{'s', 'o', 'c', 'o'}, meta.Data[0].Relationships.Tracks.Data[index].Attributes.ComposerName) if err != nil { return err } - // cnID, err := strconv.ParseUint(meta.Data[0].Relationships.Tracks.Data[index].ID, 10, 32) - // if err != nil { - // return err - // } + err = addMeta(mp4.BoxType{'\251', 'd', 'a', 'y'}, meta.Data[0].Attributes.ReleaseDate) + if err != nil { + return err + } + + cnID, err := strconv.ParseUint(meta.Data[0].Relationships.Tracks.Data[index].ID, 10, 32) + if err != nil { + return err + } - // err = addMeta(mp4.BoxType{'c', 'n', 'I', 'D'}, uint32(cnID)) - // if err != nil { - // return err - // } + err = addMeta(mp4.BoxType{'c', 'n', 'I', 'D'}, uint32(cnID)) + if err != nil { + return err + } err = addExtendedMeta("ISRC", meta.Data[0].Relationships.Tracks.Data[index].Attributes.Isrc) if err != nil { @@ -724,6 +754,11 @@ func writeM4a(w *mp4.Writer, info *SongInfo, meta *AutoGenerated, data []byte, t return err } + err = addMeta(mp4.BoxType{'s', 'o', 'a', 'a'}, album.Attributes.ArtistName) + if err != nil { + return err + } + err = addMeta(mp4.BoxType{'c', 'p', 'r', 't'}, album.Attributes.Copyright) if err != nil { return err @@ -738,6 +773,11 @@ func writeM4a(w *mp4.Writer, info *SongInfo, meta *AutoGenerated, data []byte, t return err } + err = addMeta(mp4.BoxType{'\251', 'p', 'u', 'b'}, album.Attributes.RecordLabel) + if err != nil { + return err + } + err = addExtendedMeta("LABEL", album.Attributes.RecordLabel) if err != nil { return err @@ -748,28 +788,28 @@ func writeM4a(w *mp4.Writer, info *SongInfo, meta *AutoGenerated, data []byte, t return err } - // plID, err := strconv.ParseUint(album.ID, 10, 32) - // if err != nil { - // return err - // } + plID, err := strconv.ParseUint(meta.Data[0].ID, 10, 32) + if err != nil { + return err + } - // err = addMeta(mp4.BoxType{'p', 'l', 'I', 'D'}, uint32(plID)) - // if err != nil { - // return err - // } + err = addMeta(mp4.BoxType{'p', 'l', 'I', 'D'}, uint32(plID)) + if err != nil { + return err + } } - // if len(meta.Data[0].Relationships.Artists.Data) > 0 { - // atID, err := strconv.ParseUint(meta.Data[0].Relationships.Artists.Data[index].ID, 10, 32) - // if err != nil { - // return err - // } + if len(meta.Data[0].Relationships.Tracks.Data[index].Relationships.Artists.Data[0].ID) > 0 { + atID, err := strconv.ParseUint(meta.Data[0].Relationships.Tracks.Data[index].Relationships.Artists.Data[0].ID, 10, 32) + if err != nil { + return err + } - // err = addMeta(mp4.BoxType{'a', 't', 'I', 'D'}, uint32(atID)) - // if err != nil { - // return err - // } - // } + err = addMeta(mp4.BoxType{'a', 't', 'I', 'D'}, uint32(atID)) + if err != nil { + return err + } + } trkn := make([]byte, 8) binary.BigEndian.PutUint32(trkn, uint32(trackNum)) @@ -779,12 +819,12 @@ func writeM4a(w *mp4.Writer, info *SongInfo, meta *AutoGenerated, data []byte, t return err } - // disk := make([]byte, 8) - // binary.BigEndian.PutUint32(disk, uint32(meta.Attributes.DiscNumber)) - // err = addMeta(mp4.BoxType{'d', 'i', 's', 'k'}, disk) - // if err != nil { - // return err - // } + disk := make([]byte, 8) + binary.BigEndian.PutUint32(disk, uint32(meta.Data[0].Relationships.Tracks.Data[index].Attributes.DiscNumber)) + err = addMeta(mp4.BoxType{'d', 'i', 's', 'k'}, disk) + if err != nil { + return err + } ctx.UnderIlst = false