Youtube PHP APi Check VIdeo Is Duplicate Or Not

前端 未结 2 1948
天命终不由人
天命终不由人 2021-01-01 11:26

Hi I am using Google PHP API to upload video in PHP. I have followed this tutorial to implement this and it is working fine. But there is a problem if video is already exist

2条回答
  •  温柔的废话
    2021-01-01 11:47

    Without the ability to run a cron job, you'll probably have to check if it's a duplicate the next time you try to access the video.

    Alternatively, after the video is uploaded you could launch another php script that a while loop checking the status periodically (sleeping for a time before making another API request to check.)

    do
    {
        $videos = $youtubeClient->videos->listVideos('status', ['id' => $videoId]);
        $video = $videos['items'][0]; // assuming you want one video. Iterate over the items array otherwise
    
        if($video['status']['uploadStatus'] == 'rejected' && $video['status']['rejectionReason'] == 'duplicate') {
            // Notify user of duplicate and/or note failed upload in DB
        }
        else {
            sleep(180);
        }
    } while ($video['status']['uploadStatus'] == 'processing')
    

    You'll need to make sure that script can be run from the command line and can accept arguments to get the video ID from the original upload script. http://php.net/manual/en/function.getopt.php

    Personally I don't like the idea of launching additional scripts with loops like this as you can end up with rouge processes if you don't check all your edge cases, but without cron jobs your options are limited.

提交回复
热议问题