Getting a thumbnail for an external video as the thumbnail for a custom post type?

wordpress.stackexchange https://wordpress.stackexchange.com/questions/9929

  •  16-10-2019
  •  | 
  •  

سؤال

I saw some other similar threads but they were all for YouTube videos. I was wondering if the same could be done for videos hosted on other servers like blip. Here is an example of a blip video: http://blip.tv/file/4778330

This is how I currently have things set up:

I have a custom post type for Videos with a meta box for the src (video_src) from the embed code so all I have to do is enter the src and it gets displayed from my single-videos.php template like this:

<embed src="<?=$video_src?>" type="application/x-shockwave-flash" width="400" height="200" allowscriptaccess="always" allowfullscreen="true" />

It would be awesome if somehow a frame of the video became the featured thumbnail of its post. Any idea on how something like this could be done?

هل كانت مفيدة؟

المحلول

You can use the Blip TV API:

http://wiki.blip.tv/index.php/Blip.tv_API

Look for "How do I find the thumbnail for an item?" Examples of the API can be found in the wiki e.g. the PHP Example:

include_once("blipPHP.php");
$blipPHP = new blipPHP("username", "password");
$respond = $blipPHP->info(4794325);

returns a LONG array. Inside this you find:

[3] => SimpleXMLElement Object
                                    (
                                        [@attributes] => Array
                                            (
                                                [rel] => alternate
                                                [type] => application/rss+xml
                                                [href] => http://blip.tv/rss/4812438
                                            )

                                    )

Now make a call to get http://blip.tv/rss/4812438 (you can check this one in your browser)

And you can parse the returned content for the thumnail as in the xpath expression given as you find:

<media:thumbnail url="http://a.images.blip.tv/Oldjewstellingjokes-AdrianeBergPastorFuzz165.jpg"/>

Now... maybe you have some questions:

1 how do i program something to get a url (URI) in a string?

WordPress provides a default method for that: wp_remote_get : READ: http://codex.wordpress.org/HTTP_API (see also http://core.trac.wordpress.org/ticket/4779)

2 Ok... now I have some website in a string what do i do with it?

Whatever you can think of, if it is stuff that is not "XML" related you will probably use smart regex to parse the content out of the string. (see php regex)

But.... to make stuff more readable for yourself, read the string in a DOM and then use XPath to quickly scan for the content. (see google:xpath or php.net: xpath)

$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->strictErrorChecking = false;
if (!$dom->loadHTML($data)) 
{
   foreach (libxml_get_errors() as $error) 
   {
     //     handle errors here
    }
    libxml_clear_errors();      
} 
else
{
   $xpath = new DOMXPath($dom);
   $elements = $xpath->query('/rss/channel/item/media:thumbnail/@url');

TADA! the thumbnail we found:

نصائح أخرى

Bottom line is that there is probably no generic way to do it, because every service has its own API and methods and such.

If you want a more generic method, you could try oEmbed, which supports a thumbnail_url property for videos. Many sites have oEmbed support built in, but oohEmbed or Embedly offer many more services through the same API.

For example, the oohEmbed request for your video returns the following information:

{
    "type": "video",
    "version": "1.0",
    "title": "WEBISODE 14 - The Bay - Chapter 4 - Part 2",
    "author_name": "TheBaytheSeries",
    "author_url": "http://TheBaytheSeries.blip.tv",
    "provider_name": "blip.tv",
    "provider_url": "http://blip.tv",
    "width": 720,
    "height": 436,
    "html": "<embed src=\"http://blip.tv/play/AYKk4RQC\" type=\"application/x-shockwave-flash\" width=\"720\" height=\"436\" allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed>",
    "thumbnail_url": "http://a.images.blip.tv/Thebaytheseries-WEBISODE14TheBayChapter4Part2721.png",
    "thumbnail_width": 720,
    "thumbnail_height": 436 
}

It would seem that the thumbnail blip creates for each video isn't like youtube, where you can use the videoid to figure it out.

Here are two of your videos/thumbs from blip:

http://blip.tv/file/4778330 http://a.images.blip.tv/Thebaytheseries-WEBISODE14TheBayChapter4Part2721-711.jpg

http://blip.tv/file/4690791 http://a.images.blip.tv/Thebaytheseries-THEBAYTheSeriesSOMETHINGSADMusicVideoByTedKorsmo777-169.jpg

So it doesn't look possible.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى wordpress.stackexchange
scroll top