twlite/soundcloud-scraper

.getPlaylist() still broken? Cannot read property 'split' of undefined.

Closed this issue · 3 comments

Hey there, I need some help figuring this out.

I have been trying to use the soundcloud-scraper module to get playlist track data but keep running into a problem.
I can get individual songs just fine using getSongInfo() but using getPlaylist() fail and throws an error.
I expected a response like what is mentioned here in the readme but instead I get this error message:
image
In this example, I was using this playlist as the source.

This is the code used to test this out:

const SoundCloud = require("soundcloud-scraper");
const client = new SoundCloud.Client();
let playlist;
(async function () {
  playlist = await client.getPlaylist("https://soundcloud.com/cg5-beats/sets/patiently-new-album");
  console.log(playlist);
})();

Version Information
Node v14.17.1
soundcloud-scraper v5.0.2

Can anyone help me and or provide fixes to resolve this?

Issue may be identical to #19 though not sure if they're using the same version.

Ok, after rolling back to v4.0.1 the aformentioned method works again.
It seems after version 5.0.0 getPlaylist() method stops working entirely.

Found out solution!

Change in Client.js in section getPlaylist
this:

try {
                    section = JSON.parse(`[{"id": ${raw.split(`{}})},[{"id":`)[1].split(");")[0]}`);
                } catch(e) {
                    throw new Error(`Could not parse playlist:\n${e.message}`);
                }

                const data = Util.last(section).data[0];

To this:

try {
                section = JSON.parse(`{"hydratable":"playlist" ${raw.split(`},{"hydratable":"playlist"`)[1].split(`"}}];`)[0] + `"}}`}`);
            } catch(e) {
                throw new Error(`Could not parse playlist:\n${e.message}`);
            }
            const data = section.data;

Then it works normally as before ;)

Great! But did you lint it correctly? Compared to current code, it looks like need to be linted, besides all good!

My edit is in pull requests