mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Scrobble on completion of song if song was listened to
This commit is contained in:
58
src/smapi.ts
58
src/smapi.ts
@@ -242,6 +242,10 @@ export const album = (
|
||||
title: album.name,
|
||||
albumArtURI: defaultAlbumArtURI(webAddress, accessToken, album),
|
||||
canPlay: true,
|
||||
// defaults
|
||||
// canScroll: false,
|
||||
// canEnumerate: true,
|
||||
// canAddToFavorites: true
|
||||
});
|
||||
|
||||
export const track = (
|
||||
@@ -487,6 +491,26 @@ function bindSmapiSoapServiceToExpress(
|
||||
},
|
||||
},
|
||||
}));
|
||||
case "album":
|
||||
return musicLibrary.album(typeId).then((it) => ({
|
||||
getExtendedMetadataResult: {
|
||||
mediaCollection: {
|
||||
attributes: {
|
||||
readOnly: true,
|
||||
userContent: false,
|
||||
renameable: false,
|
||||
},
|
||||
...album(webAddress, accessToken, it),
|
||||
},
|
||||
// <mediaCollection readonly="true">
|
||||
// </mediaCollection>
|
||||
// <relatedText>
|
||||
// <id>AL:123456</id>
|
||||
// <type>ALBUM_NOTES</type>
|
||||
// </relatedText>
|
||||
// </getExtendedMetadataResult>
|
||||
},
|
||||
}));
|
||||
default:
|
||||
throw `Unsupported getExtendedMetadata id=${id}`;
|
||||
}
|
||||
@@ -784,10 +808,42 @@ function bindSmapiSoapServiceToExpress(
|
||||
}
|
||||
})
|
||||
.then((_) => ({ removeFromContainerResult: { updateId: "" } })),
|
||||
setPlayedSeconds: async (
|
||||
{ id, seconds }: { id: string; seconds: string },
|
||||
_,
|
||||
headers?: SoapyHeaders
|
||||
) =>
|
||||
auth(musicService, accessTokens, headers)
|
||||
.then(splitId(id))
|
||||
.then(({ musicLibrary, type, typeId }) => {
|
||||
switch (type) {
|
||||
case "track":
|
||||
musicLibrary.track(typeId).then(({ duration }) => {
|
||||
if (
|
||||
(duration < 30 && +seconds >= 10) ||
|
||||
(duration >= 30 && +seconds >= 30)
|
||||
) {
|
||||
musicLibrary.scrobble(typeId);
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
logger.info("Unsupported scrobble", { id, seconds });
|
||||
break;
|
||||
}
|
||||
})
|
||||
.then((_) => ({
|
||||
setPlayedSecondsResult: {},
|
||||
})),
|
||||
},
|
||||
},
|
||||
},
|
||||
readFileSync(WSDL_FILE, "utf8")
|
||||
readFileSync(WSDL_FILE, "utf8"),
|
||||
(err: any, res: any) => {
|
||||
if (err) {
|
||||
logger.error("BOOOOM", { err, res });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
soapyService.log = (type, data) => {
|
||||
|
||||
Reference in New Issue
Block a user