-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thoughts on 403/410 issue and my hacky solution. #1021
Comments
Just make it a Pull Request and you can then do install the package version from that pull request even if its not merged yet. |
Issue with making it a PR is that it's fundamentally changing the way the module works, and I don't know if it's the best way. |
@C-Lunn it even solves the 407/ECONNRESET error for me! Definetly would recommend you to do the pull request.
|
I don't use discord-plauet. Does that mean I just use ytdl-core-as |
Is it work without this error? |
There's semantic versioning to take care of this
there's the
no idea what that parameter is supposed to do - you pass it do An idea you might consider: the if (["youtube"].includes(track.raw.source)) {
ytdl.getInfo(track.url).then(info => {
let stream = ytdl.downloadFromInfo(info, { highWaterMark: 1 << 27 });
// start playing stream and other stuff
}).catch(err => {
// send message that it didn't work and other stuff
})
} |
still receiving the status code 403 while still using this version unfortunately |
i got error code 410 when using btw. how to get the error code data in I want to make a kind of ytdl.getBasicInfo(url).then(data => {
//do something
}).catch(err => {
switch (err) {
case 410:
//do something
break;
case 403:
//do something
break;
case 404:
//do something
break;
}
}) |
No problem
Just do
let e;
then when you do .catch do
e = error
And e is now the error
…On Thu, Nov 11, 2021, 9:48 AM Nyako!! ***@***.***> wrote:
i got error code 410 when using getBasicInfo(). and this happens in all
videos. but lucky me. This problem has been solved by changing the hosting
region [heroku] from US to Europe. but sometimes i get error 403
does ytdl get region lock in US?
btw. how to get the error code data in getBasicInfo.catch() and store to
variable?
I want to make a kind of switch..case for a specific error code and
execute code based on that error code
example:
ytdl.getBasicInfo(url).then(data => {
//do something}).catch(err => {
switch (err) {
case 410:
//do something
break;
case 430:
//do something
break;
}})
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1021 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APFJALXOAHE76KS7GLAD6G3ULPQVFANCNFSM5FSGDZUQ>
.
|
Okay. i think it will be like |
@Nyako01 nope |
closing since #1022 was merged |
Firstly, I am by no means an expert in JS/TS so there may be a much easier solution than the one outlined here.
I've been thinking about the 410 issue a lot. For me, modifying the URL didn't work, but that's not really good enough anyway as there are other reasons videos might not be able to be played. As such, this issue needs dealing with gracefully.
ytdl()
is synchronous, but thestream
object initialised and returned by it relies on an asyncgetInfo()
function. As a result, it's not possible to know (as far as I'm aware) the result of this promise and deal with it gracefully from the caller. Whilst yes, ifgetInfo()
rejects the promise the stream emits an error, there's no confirmation emitted on success, so there's no way to know that it was successful.In the case of discord-player (or more accurately the unofficial fix for discord-player that uses ytdl directly for videos that use old codecs, link the caller
queue.play()
function is, in practice, synchronous (I believe the TS implementation is written asynchronously but is compiled for an ES2015 target so we get this spaghetti mess of_awaiter()
functions that do not themselves supportasync/await
), and so I see no way out of this without changing both.However, this presents another issue -- ytdl-core has one default export (
ytdl()
) and other modules in the project (namely discord-ytdl-core) rely on that not changing. So, here's what I did.ytdl-core
folder in node-modules, and named itytdl-core-as
.package.json
file so the name matches the folder ("name": "ytdl-core-as",
).ytdl-core-as/lib/index.js
file, and replaced the ytdl function with an asynchronous variant as follows:It's important everything stays as
ytdl
to not break everything else in the module, but we can import it under a different name to avoid conflicts.In my solution, the promise is always accepted and if there is an issue it simply returns
null
(as personally I don't care what the issue was), but this is fairly trivial to also reject it with the error code if you need.discord-player/dist/Structures/Queue.js
, I can import my new module withconst ytdl_as = require("ytdl-core-as");
.However, like I mentioned earlier, discord-player's play function is effectively synchronous which means we'll need to double up some code -- namely leave the old playing stuff as it was, but duplicate it inside a
.then()
to deal with the newly asynchronous nature of my new ytdl.I modified the
play()
function like so:This, whilst hacky, works for me.
I hope someone more skilled than I can come up with a more elegant solution.
The text was updated successfully, but these errors were encountered: