mirror of
https://github.com/gabehf/Koito.git
synced 2026-04-22 12:01:52 -07:00
feat: v0.0.5
This commit is contained in:
parent
4c4ebc593d
commit
242a82ad8c
36 changed files with 694 additions and 174 deletions
|
|
@ -42,8 +42,19 @@ type LbzTrackMeta struct {
|
|||
ArtistName string `json:"artist_name"` // required
|
||||
TrackName string `json:"track_name"` // required
|
||||
ReleaseName string `json:"release_name,omitempty"`
|
||||
MBIDMapping LbzMBIDMapping `json:"mbid_mapping"`
|
||||
AdditionalInfo LbzAdditionalInfo `json:"additional_info,omitempty"`
|
||||
}
|
||||
type LbzArtist struct {
|
||||
ArtistMBID string `json:"artist_mbid"`
|
||||
ArtistName string `json:"artist_credit_name"`
|
||||
}
|
||||
type LbzMBIDMapping struct {
|
||||
ReleaseMBID string `json:"release_mbid"`
|
||||
RecordingMBID string `json:"recording_mbid"`
|
||||
ArtistMBIDs []string `json:"artist_mbids"`
|
||||
Artists []LbzArtist `json:"artists"`
|
||||
}
|
||||
|
||||
type LbzAdditionalInfo struct {
|
||||
MediaPlayer string `json:"media_player,omitempty"`
|
||||
|
|
@ -128,17 +139,30 @@ func LbzSubmitListenHandler(store db.DB, mbzc mbz.MusicBrainzCaller) func(w http
|
|||
if err != nil {
|
||||
l.Debug().Err(err).Msg("LbzSubmitListenHandler: Failed to parse one or more UUIDs")
|
||||
}
|
||||
if len(artistMbzIDs) < 1 {
|
||||
l.Debug().Err(err).Msg("LbzSubmitListenHandler: Attempting to parse artist UUIDs from mbid_mapping")
|
||||
utils.ParseUUIDSlice(payload.TrackMeta.MBIDMapping.ArtistMBIDs)
|
||||
if err != nil {
|
||||
l.Debug().Err(err).Msg("LbzSubmitListenHandler: Failed to parse one or more UUIDs")
|
||||
}
|
||||
}
|
||||
rgMbzID, err := uuid.Parse(payload.TrackMeta.AdditionalInfo.ReleaseGroupMBID)
|
||||
if err != nil {
|
||||
rgMbzID = uuid.Nil
|
||||
}
|
||||
releaseMbzID, err := uuid.Parse(payload.TrackMeta.AdditionalInfo.ReleaseMBID)
|
||||
if err != nil {
|
||||
releaseMbzID = uuid.Nil
|
||||
releaseMbzID, err = uuid.Parse(payload.TrackMeta.MBIDMapping.ReleaseMBID)
|
||||
if err != nil {
|
||||
releaseMbzID = uuid.Nil
|
||||
}
|
||||
}
|
||||
recordingMbzID, err := uuid.Parse(payload.TrackMeta.AdditionalInfo.RecordingMBID)
|
||||
if err != nil {
|
||||
recordingMbzID = uuid.Nil
|
||||
recordingMbzID, err = uuid.Parse(payload.TrackMeta.MBIDMapping.RecordingMBID)
|
||||
if err != nil {
|
||||
recordingMbzID = uuid.Nil
|
||||
}
|
||||
}
|
||||
|
||||
var client string
|
||||
|
|
@ -160,20 +184,33 @@ func LbzSubmitListenHandler(store db.DB, mbzc mbz.MusicBrainzCaller) func(w http
|
|||
listenedAt = time.Unix(payload.ListenedAt, 0)
|
||||
}
|
||||
|
||||
var artistMbidMap []catalog.ArtistMbidMap
|
||||
for _, a := range payload.TrackMeta.MBIDMapping.Artists {
|
||||
if a.ArtistMBID == "" || a.ArtistName == "" {
|
||||
continue
|
||||
}
|
||||
mbid, err := uuid.Parse(a.ArtistMBID)
|
||||
if err != nil {
|
||||
l.Err(err).Msgf("LbzSubmitListenHandler: Failed to parse UUID for artist '%s'", a.ArtistName)
|
||||
}
|
||||
artistMbidMap = append(artistMbidMap, catalog.ArtistMbidMap{Artist: a.ArtistName, Mbid: mbid})
|
||||
}
|
||||
|
||||
opts := catalog.SubmitListenOpts{
|
||||
MbzCaller: mbzc,
|
||||
ArtistNames: payload.TrackMeta.AdditionalInfo.ArtistNames,
|
||||
Artist: payload.TrackMeta.ArtistName,
|
||||
ArtistMbzIDs: artistMbzIDs,
|
||||
TrackTitle: payload.TrackMeta.TrackName,
|
||||
RecordingMbzID: recordingMbzID,
|
||||
ReleaseTitle: payload.TrackMeta.ReleaseName,
|
||||
ReleaseMbzID: releaseMbzID,
|
||||
ReleaseGroupMbzID: rgMbzID,
|
||||
Duration: duration,
|
||||
Time: listenedAt,
|
||||
UserID: u.ID,
|
||||
Client: client,
|
||||
MbzCaller: mbzc,
|
||||
ArtistNames: payload.TrackMeta.AdditionalInfo.ArtistNames,
|
||||
Artist: payload.TrackMeta.ArtistName,
|
||||
ArtistMbzIDs: artistMbzIDs,
|
||||
TrackTitle: payload.TrackMeta.TrackName,
|
||||
RecordingMbzID: recordingMbzID,
|
||||
ReleaseTitle: payload.TrackMeta.ReleaseName,
|
||||
ReleaseMbzID: releaseMbzID,
|
||||
ReleaseGroupMbzID: rgMbzID,
|
||||
ArtistMbidMappings: artistMbidMap,
|
||||
Duration: duration,
|
||||
Time: listenedAt,
|
||||
UserID: u.ID,
|
||||
Client: client,
|
||||
}
|
||||
|
||||
if req.ListenType == ListenTypePlayingNow {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package handlers
|
|||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gabehf/koito/internal/db"
|
||||
"github.com/gabehf/koito/internal/logger"
|
||||
|
|
@ -67,9 +68,16 @@ func MergeReleaseGroupsHandler(store db.DB) http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
var replaceImage bool
|
||||
replaceImgStr := r.URL.Query().Get("replace_image")
|
||||
if strings.ToLower(replaceImgStr) == "true" {
|
||||
l.Debug().Msg("MergeReleaseGroupsHandler: Merge will replace image")
|
||||
replaceImage = true
|
||||
}
|
||||
|
||||
l.Debug().Msgf("MergeReleaseGroupsHandler: Merging release groups from ID %d to ID %d", fromId, toId)
|
||||
|
||||
err = store.MergeAlbums(r.Context(), int32(fromId), int32(toId))
|
||||
err = store.MergeAlbums(r.Context(), int32(fromId), int32(toId), replaceImage)
|
||||
if err != nil {
|
||||
l.Err(err).Msg("MergeReleaseGroupsHandler: Failed to merge release groups")
|
||||
utils.WriteError(w, "Failed to merge release groups: "+err.Error(), http.StatusInternalServerError)
|
||||
|
|
@ -103,9 +111,16 @@ func MergeArtistsHandler(store db.DB) http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
var replaceImage bool
|
||||
replaceImgStr := r.URL.Query().Get("replace_image")
|
||||
if strings.ToLower(replaceImgStr) == "true" {
|
||||
l.Debug().Msg("MergeReleaseGroupsHandler: Merge will replace image")
|
||||
replaceImage = true
|
||||
}
|
||||
|
||||
l.Debug().Msgf("MergeArtistsHandler: Merging artists from ID %d to ID %d", fromId, toId)
|
||||
|
||||
err = store.MergeArtists(r.Context(), int32(fromId), int32(toId))
|
||||
err = store.MergeArtists(r.Context(), int32(fromId), int32(toId), replaceImage)
|
||||
if err != nil {
|
||||
l.Err(err).Msg("MergeArtistsHandler: Failed to merge artists")
|
||||
utils.WriteError(w, "Failed to merge artists: "+err.Error(), http.StatusInternalServerError)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue