File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed
Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import dayjs from 'dayjs';
33
44import {
55 buildTrackString ,
6- playObjDataMatch ,
6+ playObjDataMatch , removeUndefinedKeys ,
77 setIntersection , sleep ,
88 sortByPlayDate ,
99 truncateStringToLength ,
@@ -259,13 +259,19 @@ export default class LastfmScrobbler extends AbstractScrobbleClient {
259259
260260 try {
261261 const response = await this . api . callApi ( client => client . trackScrobble (
262- {
262+ // i don't know if its lastfm-node-client building the request params incorrectly
263+ // or the last.fm api not handling the params correctly...
264+ //
265+ // ...but in either case if any of the below properties is undefined (possibly also null??)
266+ // then last.fm responds with an IGNORED scrobble and error code 1 (totally unhelpful)
267+ // so remove all undefined keys from the object before passing to the api client
268+ removeUndefinedKeys ( {
263269 artist : artists . join ( ', ' ) ,
264270 duration,
265271 track,
266272 album,
267273 timestamp : playDate . unix ( ) ,
268- } ) ) ;
274+ } ) ) ) ;
269275 const {
270276 scrobbles : {
271277 '@attr' : {
Original file line number Diff line number Diff line change @@ -327,3 +327,25 @@ export const spreadDelay = (retries, multiplier) => {
327327 }
328328 return s ;
329329}
330+
331+ export const removeUndefinedKeys = ( obj ) => {
332+ let newObj = { } ;
333+ Object . keys ( obj ) . forEach ( ( key ) => {
334+ if ( Array . isArray ( obj [ key ] ) ) {
335+ newObj [ key ] = obj [ key ] ;
336+ } else if ( obj [ key ] === Object ( obj [ key ] ) ) {
337+ newObj [ key ] = removeUndefinedKeys ( obj [ key ] ) ;
338+ } else if ( obj [ key ] !== undefined ) {
339+ newObj [ key ] = obj [ key ] ;
340+ }
341+ } ) ;
342+ if ( Object . keys ( newObj ) . length === 0 ) {
343+ return undefined ;
344+ }
345+ Object . keys ( newObj ) . forEach ( key => {
346+ if ( newObj [ key ] === undefined || ( null !== newObj [ key ] && typeof newObj [ key ] === 'object' && Object . keys ( newObj [ key ] ) . length === 0 ) ) {
347+ delete newObj [ key ]
348+ }
349+ } ) ;
350+ return newObj ;
351+ }
You can’t perform that action at this time.
0 commit comments