norkunas / youtube-dl-php

A PHP wrapper for youtube-dl or yt-dlp.
MIT License
456 stars 158 forks source link

Authentication not working #163

Closed Write closed 3 years ago

Write commented 3 years ago

i'm trying to download a video from facebook, with authentication(username, password) function. But it seems youtube-dl isn't seeing the parameters

                    $options =
                    Options::create()
                    ->downloadPath($downloadDir)
                    ->extractAudio(false)
                    ->cacheDir($cacheDir)
                    ->addMetadata(false)
                    ->continue(false)
                    ->ffmpegLocation($ffmpeg_location)
                    ->preferFFmpeg(true)
                    ->hlsPreferNative(true)
                    ->format($format)
                    ->output('%(id)s.%(ext)s')
                    ->url($url)
                    ->authenticate("fbemail", "fbpaswsord");

Returns :

Error downloading video: This video is only available for registered users. Use --username and --password or --netrc to provide account credentials..

norkunas commented 3 years ago

Could you debug what command line is built before running the process?

Write commented 3 years ago

$ while; do; ps aux | grep youtube; done; www-data 65921 34.3 0.9 47252 37864 ? R 09:38 0:02 /usr/bin/python3 /usr/local/bin/youtube-dl --ignore-config --ignore-errors --write-info-json --hls-prefer-native --output=/home/web/socialspill/yt/downloads/%(id)s.%(ext)s --cache-dir=/home/web/socialspill/yt/cache --username=mycorrectfbusername --password=mycorrectfbpassword --prefer-ffmpeg --ffmpeg-location=/usr/bin/ffmpeg https://www.facebook.com/W9/videos/1582413528636185/

Ok so thise one is weird, since it seems the arguments are added to the command

EDIT : Running the command trough the console show a warning message that credentials are wrong, which weren't in my debug output with

    $yt->debug(function ($type, $buffer) {
        echo "[$type]: $buffer<br/>";
    });

For now it seems to be my mistake but it's weird since i'm almost sure it's the correct credentials. i'll update my comment.

norkunas commented 3 years ago

Don't know then :) Another alternative would be to try Authentication with .netrc file

Write commented 3 years ago

Thanks a lot for you work on this project, It was my mistake indeed, do you know how to catch WARNING message too with $yt->debug ? Otherwise the issue is closed, my credentials were indeed wrong. Thanks a lot.

norkunas commented 3 years ago

Could you give the output what yt-dl says when it's wrong? :) I've never tried yt-dl where I needed authentication so can't say why it was not passed to debug callback

Write commented 3 years ago

This is the output, the WARNING message isn't shown

[facebook] Downloading login page
[facebook] Logging in
WARNING: unable to log in: bad username/password, or exceeded login rate limit (~3/min). Check credentials or wait.
[facebook] 1582413528636185: Downloading webpage
ERROR: This video is only available for registered users. Use --username and --password or --netrc to provide account credentials.
norkunas commented 3 years ago

Ok so this library implementation uses the message from ERROR, which is the final message but doesn't include warnings, maybe you want to contribute to improve this situation? :)

Write commented 3 years ago

PR made #167