SuspiciousLookingOwl / scrape-yt

Simple lib to scrape information from youtube such as search results, video information, related videos, playlist information and up next video
https://www.npmjs.com/package/scrape-yt
MIT License
9 stars 3 forks source link

[ENHANCEMENT] Performance impact when getting playlist with high videos count #12

Closed SteeledSlagle13 closed 4 years ago

SteeledSlagle13 commented 4 years ago

Describe the bug Hey so I'm seeing when I call

scrapeYt.getPlaylist(playlistMatch[1]).then(playlist => {
    const playlistVideos: Video[] = playlist['videos'];

   console.log(playlistVideos);
});

Where playlistMatch[1] = PLqFSI8ggBE67YFjGyLykEqeh0c37uC8fi

My audio playing on discord has a gap when this is called

To Reproduce

Expected behavior No gap in audio when calling this method

Screenshots N/A

Additional context

sorry for opening so many issue man :/

i tried separating the call into a diff method that isnt connected to the player and calling the getPlaylist function while the something is playing and got the same issue.... I dont see the issue with getVideo() and im not seeing it with the search as well

SteeledSlagle13 commented 4 years ago

if u have discord i can invite u to my test server to show u

SuspiciousLookingOwl commented 4 years ago

Can you share your minimum code for discord bot with the command to play song and get playlist? (Don't forget to remove any sensitive data like discord token)

SteeledSlagle13 commented 4 years ago

ye :D ill get that up here in a bit

SteeledSlagle13 commented 4 years ago

are u on windows?

SuspiciousLookingOwl commented 4 years ago

Yes, but i also have VPS running on Ubuntu, if i can't reproduce it in my system, i will try to host it on my VPS.

SteeledSlagle13 commented 4 years ago

okie dokie ill remove the part with ffmpeg location instead of worrying about that

SteeledSlagle13 commented 4 years ago

hey u cool if i email it to u?

SuspiciousLookingOwl commented 4 years ago

Sure, me@vincentjonathan.com

SteeledSlagle13 commented 4 years ago

just sent email with code and steps lmk if you have questions!!!

SuspiciousLookingOwl commented 4 years ago

Try update to 1.2.5 (alpha), npm i scrape-yt@1.2.5 and try again.

SteeledSlagle13 commented 4 years ago

okie dokie give me like two minutes XD

SuspiciousLookingOwl commented 4 years ago

Oh nvm it didn't fixed it lol, i thought it did! I will take a look again on what causes it.

SteeledSlagle13 commented 4 years ago

XD hahahah sounds good im on 1.2.5 now and no dice I'll keep checking back here i appreciate you!

SuspiciousLookingOwl commented 4 years ago

This seems like a performance issue from the scraper (cheerio). I'm still looking for a lighter alternative to try.

SteeledSlagle13 commented 4 years ago

oof sounds good im not in a hurry for the fix i just wanted to bring it up thank you so much for looking into it i really appreciate it

SuspiciousLookingOwl commented 4 years ago

Np! One easy temporary solution that i can think of is just make a local HTTP server as an API to get youtube data using my library, so instead of using scrape-yt directly on the discord code, you just send a HTTP request to that local server so the scraper isn't hogging the discord node js thread.

SteeledSlagle13 commented 4 years ago

oh thats an idea i can look into that :D

SteeledSlagle13 commented 4 years ago

hey just to let you know.... i tried the node server... that works very nicely!!!! thank you very much

SuspiciousLookingOwl commented 4 years ago

I've added worker thread support which allows the lib to run the scraper in parallel. Tried it on my VPS and seems like it fixed the issue. It's not really a performance improvement, but still 😬. Update not yet published on npm.

SuspiciousLookingOwl commented 4 years ago

Published on npm (@1.3.2). You just need to add options on the second parameter and add useWorkerThread: true

import scrapeYt from "scrape-yt";
// Changed from -> import { scrapeYt } from "scrape-yt";

scrapeYt.getPlaylist("PLx65qkgCWNJIgVrndMrhsedBz1VDp0kfm", { useWorkerThread: true }).then(playlist => {
  console.log(playlist);
});
SteeledSlagle13 commented 4 years ago

dang thats awesome!!!! thank you so much ill get this implemented this week 😀