Skip to content

Commit

Permalink
Merge pull request #18 from hanafizaki/hanafizaki-patch-1
Browse files Browse the repository at this point in the history
FIX + ADD EXTENDED METADATA
  • Loading branch information
zhaarey authored May 4, 2024
2 parents a04ea01 + fd690cd commit 3f285da
Showing 1 changed file with 73 additions and 33 deletions.
106 changes: 73 additions & 33 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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

Expand Down

0 comments on commit 3f285da

Please sign in to comment.