mirror of
https://github.com/gabehf/Koito.git
synced 2026-04-22 12:01:52 -07:00
Pre-release version v0.0.13 (#52)
* feat: search/merge items by id * feat: update track duration using musicbrainz * chore: changelog * fix: make username updates case insensitive * feat: add minutes listened to ui and fix image drop * chore: changelog * fix: embed db migrations (#37) * feat: Add support for ARM in publish workflow (#51) * chore: changelog * docs: search by id and custom theme support --------- Co-authored-by: potatoattack <lvl70nub@gmail.com> Co-authored-by: Benjamin Jonard <benjaminjonard@users.noreply.github.com>
This commit is contained in:
parent
5537b6fb89
commit
5419178012
32 changed files with 1252 additions and 100 deletions
|
|
@ -134,15 +134,35 @@ func SubmitListen(ctx context.Context, store db.DB, opts SubmitListenOpts) error
|
|||
}
|
||||
l.Debug().Any("track", track).Msg("Matched listen to track")
|
||||
|
||||
if track.Duration == 0 && opts.Duration != 0 {
|
||||
err := store.UpdateTrack(ctx, db.UpdateTrackOpts{
|
||||
ID: track.ID,
|
||||
Duration: opts.Duration,
|
||||
})
|
||||
if err != nil {
|
||||
l.Err(err).Msgf("Failed to update duration for track %s", track.Title)
|
||||
if track.Duration == 0 {
|
||||
if opts.Duration != 0 {
|
||||
l.Debug().Msg("Updating duration using request information")
|
||||
err := store.UpdateTrack(ctx, db.UpdateTrackOpts{
|
||||
ID: track.ID,
|
||||
Duration: opts.Duration,
|
||||
})
|
||||
if err != nil {
|
||||
l.Err(err).Msgf("Failed to update duration for track %s", track.Title)
|
||||
} else {
|
||||
l.Info().Msgf("Duration updated to %d for track '%s'", opts.Duration, track.Title)
|
||||
}
|
||||
} else if track.MbzID != nil && *track.MbzID != uuid.Nil {
|
||||
l.Debug().Msg("Attempting to update duration using MusicBrainz ID")
|
||||
mbztrack, err := opts.MbzCaller.GetTrack(ctx, *track.MbzID)
|
||||
if err != nil {
|
||||
l.Err(err).Msg("Failed to make request to MusicBrainz")
|
||||
} else {
|
||||
err = store.UpdateTrack(ctx, db.UpdateTrackOpts{
|
||||
ID: track.ID,
|
||||
Duration: int32(mbztrack.LengthMs / 1000),
|
||||
})
|
||||
if err != nil {
|
||||
l.Err(err).Msgf("Failed to update duration for track %s", track.Title)
|
||||
} else {
|
||||
l.Info().Msgf("Duration updated to %d for track '%s'", mbztrack.LengthMs/1000, track.Title)
|
||||
}
|
||||
}
|
||||
}
|
||||
l.Info().Msgf("Duration updated to %d for track '%s'", opts.Duration, track.Title)
|
||||
}
|
||||
|
||||
if opts.SkipSaveListen {
|
||||
|
|
|
|||
|
|
@ -134,7 +134,8 @@ var (
|
|||
}
|
||||
mbzTrackData = map[uuid.UUID]*mbz.MusicBrainzTrack{
|
||||
uuid.MustParse("00000000-0000-0000-0000-000000001001"): {
|
||||
Title: "Tokyo Calling",
|
||||
Title: "Tokyo Calling",
|
||||
LengthMs: 191000,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -554,6 +554,43 @@ func TestSubmitListen_UpdateTrackDuration(t *testing.T) {
|
|||
assert.Equal(t, 1, count, "expected duration to be updated")
|
||||
}
|
||||
|
||||
func TestSubmitListen_UpdateTrackDurationWithMbz(t *testing.T) {
|
||||
setupTestDataSansMbzIDs(t)
|
||||
|
||||
ctx := context.Background()
|
||||
mbzc := &mbz.MbzMockCaller{
|
||||
Tracks: mbzTrackData,
|
||||
}
|
||||
opts := catalog.SubmitListenOpts{
|
||||
MbzCaller: mbzc,
|
||||
ArtistNames: []string{"ATARASHII GAKKO!"},
|
||||
Artist: "ATARASHII GAKKO!",
|
||||
TrackTitle: "Tokyo Calling",
|
||||
RecordingMbzID: uuid.MustParse("00000000-0000-0000-0000-000000001001"),
|
||||
ReleaseTitle: "AG! Calling",
|
||||
Time: time.Now(),
|
||||
UserID: 1,
|
||||
}
|
||||
|
||||
err := catalog.SubmitListen(ctx, store, opts)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify that the listen was saved
|
||||
exists, err := store.RowExists(ctx, `
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM listens
|
||||
WHERE track_id = $1
|
||||
)`, 1)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, exists, "expected listen row to exist")
|
||||
|
||||
count, err := store.Count(ctx, `
|
||||
SELECT COUNT(*) FROM tracks_with_title WHERE title = $1 AND duration = 191
|
||||
`, "Tokyo Calling")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, count, "expected duration to be updated")
|
||||
}
|
||||
|
||||
func TestSubmitListen_MatchFromTrackTitleNoMbzIDs(t *testing.T) {
|
||||
setupTestDataSansMbzIDs(t)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue