Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/backend/common/vendor/ListenbrainzApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { stringSameness } from '@foxxmd/string-sameness';
import dayjs from "dayjs";
import request, { Request, Response } from 'superagent';
import { BrainzMeta, PlayObject, URLData } from "../../../core/Atomic.js";
import { BrainzMeta, PlayObject, SCROBBLE_TS_SOC_START, URLData } from "../../../core/Atomic.js";
import { combinePartsToString, slice } from "../../../core/StringUtils.js";
import {
findDelimiters,
Expand Down Expand Up @@ -263,7 +263,10 @@ export class ListenbrainzApiClient extends AbstractApiClient {
release_mbid,
release_group_mbid,
release_artist_name,
release_artist_names = []
release_artist_names = [],
scrobble_ts_soc = SCROBBLE_TS_SOC_START,
listened_for,
listened_at_completed
} = {}
} = {},
} = payload;
Expand All @@ -276,7 +279,7 @@ export class ListenbrainzApiClient extends AbstractApiClient {
albumArtists = unique([...(albumArtists ?? []), ...release_artist_names])
}

return {
const play: PlayObject = {
data: {
playDate: typeof listened_at === 'number' ? dayjs.unix(listened_at) : dayjs(listened_at),
track: track_name,
Expand All @@ -295,8 +298,18 @@ export class ListenbrainzApiClient extends AbstractApiClient {
},
meta: {
nowPlaying,
scrobbleTsSOC: scrobble_ts_soc
}
}

if(listened_at_completed !== undefined) {
play.data.playDateCompleted = dayjs.unix(listened_at_completed);
}
if(listened_for !== undefined) {
play.data.listenedFor = listened_for;
}

return play;
}

static listenResponseToPlay(listen: ListenResponse): PlayObject {
Expand Down
17 changes: 17 additions & 0 deletions src/backend/common/vendor/listenbrainz/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* https://musicbrainz.org/doc/MusicBrainz_Database/Schema#Overview
*/

import { ScrobbleTsSOC } from "../../../../core/Atomic.js";

/** A unique product a Recording is issued on.
*
* This is like an album (release group) but is specific to the type, year, catalog, etc... for this release
Expand Down Expand Up @@ -123,6 +125,21 @@ export interface SubmitListenAdditionalTrackInfo extends AdditionalTrackInfo {
spotify_album_artist_ids?: string[];
spotify_artist_ids?: string[];
albumartist?: string;
/** Is the timestamp (listened_at) from when the user started listening or when they stopped listening?
*
* Specific to multi-scrobbler
*/
scrobble_ts_soc?: ScrobbleTsSOC
/** Unix timestamp for when the user stopped listening
*
* Specific to multi-scrobbler
*/
listened_at_completed?: number
/** Number of seconds track was listened to
*
* Specific to multi-scrobbler
*/
listened_for?: number
}
export interface TrackPayload extends MinimumTrack {
additional_info?: SubmitListenAdditionalTrackInfo;
Expand Down