How to get the video thumbnail from Dailymotion vi

2019-02-03 02:45发布

问题:

For youtube I use something like this:

<img class="video-thumbnail" src="http://img.youtube.com/vi/<?php echo $video_id; ?>/0.jpg" alt="" width="190">

where

$video_id is the code of that video from url.

Can I do something similar for Dailymotion videos

回答1:

You just need to add an extra thumbnail into the link.

Video URL

https://www.dailymotion.com/video/{video_id}

Thumbnail URL

https://www.dailymotion.com/thumbnail/video/{video_id}


回答2:

Using the Dailymotion API

https://api.dailymotion.com/video/VIDEO_ID?fields=field1,field2,...

Replace field1,field2 with

thumbnail_large_url (320px by 240px)
thumbnail_medium_url (160px by 120px)
thumbnail_small_url (80px by 60px)

This API request does not require any Access Tokens.

Example : https://api.dailymotion.com/video/xjfn0s?fields=thumbnail_small_url

This HTTP request returns a JSON data with the image link of the video. For processing JSON data check PHP Manual - JSON Decode

EDIT As suggested by Ravi using http://www.dailymotion.com/thumbnail/video/video_id is pretty straight forward. But different resolution images use the API



回答3:

$id='xwxadz'; // ID DAILYMOTION EXAMPLE
$thumbnail_medium_url='https://api.dailymotion.com/video/'.$id.'?fields=thumbnail_medium_url';
$json_thumbnail = file_get_contents($thumbnail_medium_url);
$get_thumbnail = json_decode($json_thumbnail, TRUE);
$thumb=$get_thumbnail['thumbnail_medium_url'];
echo $thumb; // Output Example : http://s2.dmcdn.net/BJL4o/160x120-mzR.jpg


回答4:

Just a simpler way for above objective. Suppose following is the url that I want to download thumbnail

http://www.dailymotion.com/video/x17pcar_hadoop-tutorial-how-to-index-and-search-data-with-solr_tech

From this url get last string and Extract string id

x17pcar_hadoop-tutorial-how-to-index-and-search-data-with-solr_tech

Now split above string on underscorebasis (_). First one is video id i.e. x17pcar

Now run following url using id to get thumbnail

http://www.dailymotion.com/thumbnail/video/x17pcar