How do I get the Video Id from the URL? (DailyMotion)

前端 未结 5 1836
北恋
北恋 2020-12-30 14:10

Example:

http://www.dailymotion.com/video/x4xvnz_the-funny-crash-compilation_fun

How do I get x4xvnz?

相关标签:
5条回答
  • 2020-12-30 14:30

    I use this:

    function getDailyMotionId($url)
    {
    
        if (preg_match('!^.+dailymotion\.com/(video|hub)/([^_]+)[^#]*(#video=([^_&]+))?|(dai\.ly/([^_]+))!', $url, $m)) {
            if (isset($m[6])) {
                return $m[6];
            }
            if (isset($m[4])) {
                return $m[4];
            }
            return $m[2];
        }
        return false;
    }
    

    It can handle various urls:

    $dailymotion = [
        'http://www.dailymotion.com/video/x2jvvep_coup-incroyable-pendant-un-match-de-ping-pong_tv',
        'http://www.dailymotion.com/video/x2jvvep_rates-of-exchange-like-a-renegade_music',
        'http://www.dailymotion.com/video/x2jvvep',
        'http://www.dailymotion.com/hub/x2jvvep_Galatasaray',
        'http://www.dailymotion.com/hub/x2jvvep_Galatasaray#video=x2jvvep',
        'http://www.dailymotion.com/video/x2jvvep_hakan-yukur-klip_sport',
        'http://dai.ly/x2jvvep',
    ];
    

    Check out my github (https://github.com/lingtalfi/video-ids-and-thumbnails/blob/master/testvideo.php), I provide functions to get ids (and also thumbnails) from youtube, vimeo and dailymotion.

    0 讨论(0)
  • 2020-12-30 14:31
    preg_match('#<object[^>]+>.+?http://www.dailymotion.com/swf/video/([A-Za-z0-9]+).+?</object>#s', $dailymotionurl, $matches);
    
            // Dailymotion url
            if(!isset($matches[1])) {
                preg_match('#http://www.dailymotion.com/video/([A-Za-z0-9]+)#s', $dailymotionurl, $matches);
            }
    
            // Dailymotion iframe
            if(!isset($matches[1])) {
                preg_match('#http://www.dailymotion.com/embed/video/([A-Za-z0-9]+)#s', $dailymotionurl, $matches);
            }
     $id =  $matches[1];
    
    0 讨论(0)
  • 2020-12-30 14:40

    You can use basename [docs] to get the last part of the URL and then strtok [docs] to get the ID (all characters up to the first _):

    $id = strtok(basename($url), '_');
    
    0 讨论(0)
  • 2020-12-30 14:55
    <?php
    $output = parse_url("http://www.dailymotion.com/video/x4xvnz_the-funny-crash-compilation_fun");
    
    // The part you want
    $url= $output['path'];
    $parts = explode('/',$url);
    $parts = explode('_',$parts[2]);
    
    echo $parts[0];
    

    http://php.net/manual/en/function.parse-url.php

    0 讨论(0)
  • 2020-12-30 14:57
    /video\/([^_]+)/
    

    should do the trick. This grabs in the first capture all text after video/ up till the first _.

    0 讨论(0)
提交回复
热议问题