Adjust scrobble duration to check in ms
This commit is contained in:
parent
5e1059870c
commit
cca6fa21db
1 changed files with 9 additions and 9 deletions
|
@ -34,21 +34,21 @@ Progress Events (Jellyfin only):
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const checkScrobbleConditions = (args: {
|
const checkScrobbleConditions = (args: {
|
||||||
scrobbleAtDuration: number;
|
scrobbleAtDurationMs: number;
|
||||||
scrobbleAtPercentage: number;
|
scrobbleAtPercentage: number;
|
||||||
songCompletedDurationMs: number;
|
songCompletedDurationMs: number;
|
||||||
songDurationMs: number;
|
songDurationMs: number;
|
||||||
}) => {
|
}) => {
|
||||||
const { scrobbleAtDuration, scrobbleAtPercentage, songCompletedDurationMs, songDurationMs } =
|
const { scrobbleAtDurationMs, scrobbleAtPercentage, songCompletedDurationMs, songDurationMs } =
|
||||||
args;
|
args;
|
||||||
const percentageOfSongCompleted = songDurationMs
|
const percentageOfSongCompleted = songDurationMs
|
||||||
? (songCompletedDurationMs / songDurationMs) * 100
|
? (songCompletedDurationMs / songDurationMs) * 100
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
return (
|
const shouldScrobbleBasedOnPercetange = percentageOfSongCompleted >= scrobbleAtPercentage;
|
||||||
percentageOfSongCompleted >= scrobbleAtPercentage ||
|
const shouldScrobbleBasedOnDuration = songCompletedDurationMs >= scrobbleAtDurationMs;
|
||||||
songCompletedDurationMs >= scrobbleAtDuration
|
|
||||||
);
|
return shouldScrobbleBasedOnPercetange || shouldScrobbleBasedOnDuration;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useScrobble = () => {
|
export const useScrobble = () => {
|
||||||
|
@ -103,7 +103,7 @@ export const useScrobble = () => {
|
||||||
// Send completion scrobble when song changes and a previous song exists
|
// Send completion scrobble when song changes and a previous song exists
|
||||||
if (previousSong?.id) {
|
if (previousSong?.id) {
|
||||||
const shouldSubmitScrobble = checkScrobbleConditions({
|
const shouldSubmitScrobble = checkScrobbleConditions({
|
||||||
scrobbleAtDuration: scrobbleSettings?.scrobbleAtDuration,
|
scrobbleAtDurationMs: (scrobbleSettings?.scrobbleAtDuration ?? 0) * 1000,
|
||||||
scrobbleAtPercentage: scrobbleSettings?.scrobbleAtPercentage,
|
scrobbleAtPercentage: scrobbleSettings?.scrobbleAtPercentage,
|
||||||
songCompletedDurationMs: previousSongTimeSec * 1000,
|
songCompletedDurationMs: previousSongTimeSec * 1000,
|
||||||
songDurationMs: previousSong.duration,
|
songDurationMs: previousSong.duration,
|
||||||
|
@ -227,7 +227,7 @@ export const useScrobble = () => {
|
||||||
|
|
||||||
// If not already scrobbled, send a 'submission' scrobble if conditions are met
|
// If not already scrobbled, send a 'submission' scrobble if conditions are met
|
||||||
const shouldSubmitScrobble = checkScrobbleConditions({
|
const shouldSubmitScrobble = checkScrobbleConditions({
|
||||||
scrobbleAtDuration: scrobbleSettings?.scrobbleAtDuration,
|
scrobbleAtDurationMs: (scrobbleSettings?.scrobbleAtDuration ?? 0) * 1000,
|
||||||
scrobbleAtPercentage: scrobbleSettings?.scrobbleAtPercentage,
|
scrobbleAtPercentage: scrobbleSettings?.scrobbleAtPercentage,
|
||||||
// If scrobbling the last song in the queue, use the previous time instead of the current time since otherwise time value will be 0
|
// If scrobbling the last song in the queue, use the previous time instead of the current time since otherwise time value will be 0
|
||||||
songCompletedDurationMs:
|
songCompletedDurationMs:
|
||||||
|
@ -273,7 +273,7 @@ export const useScrobble = () => {
|
||||||
currentSong?.serverType === ServerType.JELLYFIN ? currentTime * 1e7 : undefined;
|
currentSong?.serverType === ServerType.JELLYFIN ? currentTime * 1e7 : undefined;
|
||||||
|
|
||||||
const shouldSubmitScrobble = checkScrobbleConditions({
|
const shouldSubmitScrobble = checkScrobbleConditions({
|
||||||
scrobbleAtDuration: scrobbleSettings?.scrobbleAtDuration,
|
scrobbleAtDurationMs: (scrobbleSettings?.scrobbleAtDuration ?? 0) * 1000,
|
||||||
scrobbleAtPercentage: scrobbleSettings?.scrobbleAtPercentage,
|
scrobbleAtPercentage: scrobbleSettings?.scrobbleAtPercentage,
|
||||||
songCompletedDurationMs: currentTime,
|
songCompletedDurationMs: currentTime,
|
||||||
songDurationMs: currentSong.duration,
|
songDurationMs: currentSong.duration,
|
||||||
|
|
Reference in a new issue