dongzecai0684 2013-07-13 04:10
浏览 28
已采纳

能够在2分钟内发布YouTube视频

Is there any way for a website to let users embed ONLY short youtube videos. Let's say 2min or shorter.

So when they try to embed the youtube video and if it's over 2 minutes they get an error that tells them "Your video is too long, please choose another" etc...

Is this possible?

Just to be clear, I'm not looking to edit the youtube video length, just prohibit users from posting of videos that are too long.

Thank you very much.

  • 写回答

2条回答 默认 最新

  • doublel83422 2013-07-13 04:31
    关注

    Here's to help you get started:

    The base api URL is http://gdata.youtube.com/feeds/api/videos/VIDEO_ID?v=2&alt=json.

    <?php
    
    $video_data = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/videos/a_kAUiJwRs0?v=2&alt=json"),true);
    
    echo $video_data['entry']['title']['$t']." is ".$video_data['entry']['media$group']['yt$duration']['seconds']." seconds long.";
    

    Output:

    Love, Fate, Love - Final Approach ED Single Love, Fate, Love Original Soundtrack is 283 seconds long.

    Replace a_kAUiJwRs0 with your video ID. You may print_r on $video_data to see all the values you get.

    Once you have their video ID, you may check if their duration (in seconds) is longer or shorter than 120 seconds, and reject or accept based on that.

    I would recommending reading this to see what video responses will have. (You can always var_dump to see exactly what it returns)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?