diff --git a/src/classes/track.ts b/src/classes/track.ts index 9ef4e95e..caf306b8 100644 --- a/src/classes/track.ts +++ b/src/classes/track.ts @@ -15,30 +15,6 @@ interface ScrobbleObject { duration?:number; } -interface ScrobbleArrayed { - artist:string[]; - track:string[]; - timestamp:number[]; - album?:string[]; - chosenByUser?:(0|1)[]; - trackNumber?:number[]; - mbid?:string[]; - albumArtist?:string[]; - duration?:number[]; -} - -interface ScrobbleArrayStringified { - artist:string; - track:string; - timestamp:string; - album?:string; - chosenByUser?:string; - trackNumber?:string; - mbid?:string; - albumArtist?:string; - duration?:string; -} - export default class TrackClass extends Base { public async addTags(artist:string, track:string, tags:string[]|string, sk:string) { @@ -102,12 +78,12 @@ export default class TrackClass extends Base { let params:any = {}; for (let [index, scrobble] of scrobbles.entries()) { - for (let [key, value] of Object.keys(scrobble)) { + for (let [key, value] of Object.entries(scrobble)) { params[`${key}[${index}]`] = value; } } - return await new LFMRequest(this.key, this.secret, {method: "track.scrobble", ...params, sk}).execute(true) as any; + return (await new LFMRequest(this.key, this.secret, {method: "track.scrobble", ...params, sk}).execute()).scrobbles as TrackInterface.scrobble; } diff --git a/src/interfaces/trackInterface.ts b/src/interfaces/trackInterface.ts index 1a579358..a6c58d6f 100644 --- a/src/interfaces/trackInterface.ts +++ b/src/interfaces/trackInterface.ts @@ -75,6 +75,29 @@ export interface getTopTags { "@attr":TrackMetadata; } +interface ScrobbleEntry { + corrected:string; + "#text":string; +} + +export interface scrobble { + "@attr": { + accepted:number; + ignored:number; + } + scrobble: { + artist:ScrobbleEntry; + ignoredMessage: { + code:string; + "#text":string; + } + albumArtist:ScrobbleEntry; + timestamp:string; + album:ScrobbleEntry; + track:ScrobbleEntry; + } +} + export interface search { "opensearch:Query": { "#text":string; diff --git a/src/request.ts b/src/request.ts index 72799bad..3da0e7b9 100644 --- a/src/request.ts +++ b/src/request.ts @@ -46,7 +46,7 @@ export default class LFMRequest { } - public async execute(isScrobble = false) { + public async execute() { const isPostRequest = this.isPostRequest(); @@ -56,7 +56,7 @@ export default class LFMRequest { throw new SyntaxError("Please enter an api secret key to use post requests with session key."); } - this.response = await this.post(isScrobble); + this.response = await this.post(); } else { @@ -105,14 +105,14 @@ export default class LFMRequest { } - private async post(isScrobble:boolean) { + private async post() { if (this.params.hasOwnProperty("user")) { this.params.sk = this.params.user; delete this.params.user; } - const api_sig = this.getSignature(isScrobble); + const api_sig = this.getSignature(); const requestParam = { ...this.params, @@ -146,7 +146,7 @@ export default class LFMRequest { } - private getSignature(isScrobble:boolean) { + private getSignature() { const paramObj:any = { ...this.params, @@ -155,7 +155,7 @@ export default class LFMRequest { const args = Object.keys(paramObj).sort().map((e) => [e, paramObj[e]]) as string[][]; - let sig = args.reduce((acc, cur) => acc + (isScrobble && !["api_key", "sk"].includes(cur[0]) ? "" : cur[0]) + cur[1], ""); + let sig = args.reduce((acc, cur) => `${acc}${cur[0]}${cur[1]}`, ""); sig = md5(sig + this.secret);