Athlon1600 / youtube-downloader

:tv: PHP based alternative to youtube-dl and yt-dlp. Active and frequently updated! :star:
https://unblockvideos.com/
MIT License
805 stars 316 forks source link

Couldn't parse id #129

Closed MeShootIn closed 1 year ago

MeShootIn commented 3 years ago

Method Utils::extractVideoId doesn't parse correctly some links (tested on https://gist.github.com/rodrigoborgesdeoliveira/987683cfbfcc8d800192da1e73adc486):

So, maybe use another method like below?

public static function extractVideoId($str) { if (pregmatch('/(?:\/|%3D|v=|vi=)([0-9A-z-]{11})(?:[%#?&]|$)/ui', $str, $matches)) { return $matches[1]; }

return false; }

AgentSmith0 commented 3 years ago

I would recommend creating a seperate function for this. The getDownloadLinks() function should then only accept the returned youtube id. This would slightly increase the performance when only the id is given.

Athlon1600 commented 3 years ago

yeah, the existing ID parsing logic is pretty weak... your regex solution is much better. So we'll just use that in the next release: https://github.com/Athlon1600/youtube-downloader/commit/250f575cd82d39f8248dd07b0cf126fe3a1bd459

https://github.com/Athlon1600/youtube-downloader/blob/250f575cd82d39f8248dd07b0cf126fe3a1bd459/src/Utils/Utils.php#L12-L23

I would recommend creating a seperate function for this. The getDownloadLinks() function should then only accept the returned youtube id. This would slightly increase the performance when only the id is given.

true. But a good solution to that is to first check if the string passed in is exactly 11 characters long (very efficient operation), and if so, assume that the ID itself was passed in rather than some URL