Video Thumbnails - Version 0.3

Version Description

  • Added basic support for Blip.tv auto embedded using URLs in this format: http://blip.tv/file/12345
Download this release

Release Info

Developer sutherlandboswell
Plugin Icon 128x128 Video Thumbnails
Version 0.3
Comparing to
See all releases

Version 0.3

Files changed (3) hide show
  1. default.jpg +0 -0
  2. readme.txt +91 -0
  3. video-thumbnails.php +130 -0
default.jpg ADDED
Binary file
readme.txt ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Video Thumbnails ===
2
+ Contributors: sutherlandboswell
3
+ Donate link: http://sutherlandboswell.com
4
+ Tags: Video, YouTube, Vimeo, Thumbnails
5
+ Requires at least: 3.0
6
+ Tested up to: 3.0.1
7
+ Stable tag: 0.3
8
+
9
+ Video Thumbnails is a simple plugin that makes it easier to display video thumbnails in your template.
10
+
11
+ == Description ==
12
+
13
+ Video Thumbnails makes it simple to display video thumbnails in your templates. Simply use `<?php video_thumbnail(); ?>` in a loop to find and echo the URL of the first video embedded in a post, or use `<?php $video_thumbnail = get_video_thumbnail(); ?>` if you want to return the URL for use as a variable.
14
+
15
+ Video Thumbnails currently supports:
16
+
17
+ * YouTube
18
+ * Vimeo
19
+ * Blip.tv
20
+ * JR Embed (this plugin seems to have disappeared)
21
+ * [Vimeo Shortcode](http://blog.esimplestudios.com/2010/08/embedding-vimeo-videos-in-wordpress/)
22
+
23
+ When using `video_thumbnail()` and no thumbnail is found, a default thumbnail is echoed, which can be changed by replacing the `default.jpg` file found in your `/plugins/video-thumbnails/` directory.
24
+
25
+ For more advanced users, the `get_video_thumbnail()` function will return null when no thumbnail is found so a conditional statement can be used to detect if a thumbnail is present and decide what to echo. Here's an example of how to only echo a thumbnail when one is found: `<?php if( ( $video_thumbnail = get_video_thumbnail() ) != null ) { echo "<img src='" . $video_thumbnail . "' />"; } ?>`
26
+
27
+ This is just a start, so don't hesitate to share suggestions and let me know if you find any problems.
28
+
29
+ == Installation ==
30
+
31
+ 1. Upload the `/video-thumbnails/` directory to the `/wp-content/plugins/` directory
32
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
33
+ 1. Use `<?php video_thumbnail(); ?>` in a loop inside your template to echo the thumbnail URL. Because this is only a URL, you should set it as an image tag's source. For example, `<img src="<?php video_thumbnail(); ?>" />`. If you'd like to return the URL for use in your PHP, use `get_video_thumbnail()`. For example, `<?php $video_thumbnail = get_video_thumbnail(); ?>`.
34
+
35
+ == Frequently Asked Questions ==
36
+
37
+ = My video service isn't included, can you add it? =
38
+
39
+ If the service allows a way to retrieve thumbnails, I'll do my best to add it.
40
+
41
+ = I only want a thumbnail when one is found, how would I do this? =
42
+
43
+ In version 0.2 `get_video_thumbnail()` was added which returns null when no thumbnail is found. This means you can use something like `<?php if( ( $video_thumbnail = get_video_thumbnail() ) != null ) { echo "<img src='" . $video_thumbnail . "' />"; } ?>` to only display a thumbnail when one exists.
44
+
45
+ == Screenshots ==
46
+
47
+ Coming Soon
48
+
49
+ == Changelog ==
50
+
51
+ = 0.3 =
52
+ * Added basic support for Blip.tv auto embedded using URLs in this format: http://blip.tv/file/12345
53
+
54
+ = 0.2.3 =
55
+ * Added support for any Vimeo URL
56
+
57
+ = 0.2.2 =
58
+ * Added support for [Vimeo Shortcode](http://blog.esimplestudios.com/2010/08/embedding-vimeo-videos-in-wordpress/)
59
+
60
+ = 0.2.1 =
61
+ * Added support for Vimeo players embedded using an iframe
62
+
63
+ = 0.2 =
64
+ * Added `get_video_thumbnail()` to return the URL without echoing or return null if no thumbnail is found, making it possible to only display a thumbnail if one is found.
65
+
66
+ = 0.1.3 =
67
+ * Fixed an issue where no URL was returned when Vimeo's rate limit had been exceeded. The default image URL is now returned, but a future version of the plugin will store thumbnails locally for a better fix.
68
+
69
+ = 0.1.2 =
70
+ * Fixed a possible issue with how the default image URL is created
71
+
72
+ = 0.1.1 =
73
+ * Fixed an issue with the plugin directory's name that caused the default URL to be broken
74
+ * Added support for YouTube URLs
75
+
76
+ = 0.1 =
77
+ * Initial release
78
+
79
+ == Known Issues ==
80
+
81
+ * The Vimeo API is rate limited, so the default image will be displayed when the limit has been exceeded. I'm planning to add local copies of files in a future release to solve this problem.
82
+ * While not really an issue, the current method for only displaying a thumbnail if one is found seems like it could be streamlined, so if you have any suggestions let me know.
83
+
84
+ == Roadmap ==
85
+
86
+ This plugin is still very young, and has a future planned as the ultimate plugin for video thumbnails. Here's some of the planned additions:
87
+
88
+ * More comprehensive Blip.tv support
89
+ * Local thumbnail storage
90
+ * More services
91
+ * More shortcode plugins
video-thumbnails.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Video Thumbnails
4
+ Plugin URI: http://sutherlandboswell.com/2010/11/wordpress-video-thumbnails/
5
+ Description: A plugin designed to fetch video thumbnails. Use <code>&lt;?php video_thumbnail(); ?&gt;</code> in a loop to return a URL for the thumbnail of the first video in a post. Currently works with YouTube and Vimeo, and with the JR_embed plugin.
6
+ Author: Sutherland Boswell
7
+ Author URI: http://sutherlandboswell.com
8
+ Version: 0.3
9
+ License: GPL2
10
+ */
11
+ /* Copyright 2010 Sutherland Boswell (email : sutherland.boswell@gmail.com)
12
+
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License, version 2, as
15
+ published by the Free Software Foundation.
16
+
17
+ This program is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU General Public License for more details.
21
+
22
+ You should have received a copy of the GNU General Public License
23
+ along with this program; if not, write to the Free Software
24
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
+ */
26
+
27
+ // Get Vimeo Thumbnail
28
+ function getVimeoInfo($id, $info = 'thumbnail_large') {
29
+ if (!function_exists('curl_init')) die('CURL is not installed!');
30
+ $ch = curl_init();
31
+ curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php");
32
+ curl_setopt($ch, CURLOPT_HEADER, 0);
33
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
34
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
35
+ $output = unserialize(curl_exec($ch));
36
+ $output = $output[0][$info];
37
+ curl_close($ch);
38
+ return $output;
39
+ };
40
+
41
+ // Blip.tv Functions
42
+ function getBliptvInfo($id) {
43
+ $xml = simplexml_load_file("http://blip.tv/file/$id?skin=rss");
44
+ $result = $xml->xpath("/rss/channel/item/media:thumbnail/@url");
45
+ foreach($result as $element) {
46
+ $thumbnail = $element["url"];
47
+ }
48
+ return $thumbnail;
49
+ }
50
+
51
+ // The Main Event
52
+ function get_video_thumbnail() {
53
+
54
+ // Gets the post's content
55
+ $markup = get_the_content();
56
+
57
+ // Checks for a standard YouTube embed
58
+ preg_match('#<object[^>]+>.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?</object>#s', $markup, $matches);
59
+
60
+ // Checks for any YouTube URL
61
+ if(!isset($matches[1])) {
62
+ preg_match('#http://www.youtube.com/watch\?v=([A-Za-z0-9\-_]+)#s', $markup, $matches);
63
+ }
64
+
65
+ // If no standard YouTube embed is found, checks for one embedded with JR_embed
66
+ if(!isset($matches[1])) {
67
+ preg_match('#\[youtube id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
68
+ }
69
+
70
+ // If we've found a YouTube video ID, return the thumbnail URL
71
+ if(isset($matches[1])) {
72
+ return 'http://img.youtube.com/vi/' . $matches[1] . '/0.jpg';
73
+ }
74
+
75
+ // If we didn't find anything, check for a standard Vimeo embed
76
+ else {
77
+ preg_match('#<object[^>]+>.+?http://vimeo.com/moogaloop.swf\?clip_id=([A-Za-z0-9\-_]+)&.+?</object>#s', $markup, $matches);
78
+
79
+ // Find Vimeo embedded with iframe code
80
+ if(!isset($matches[1])) {
81
+ preg_match('#http://player.vimeo.com/video/([0-9]+)#s', $markup, $matches);
82
+ }
83
+
84
+ // If we still haven't found anything, check for Vimeo embedded with JR_embed
85
+ if(!isset($matches[1])) {
86
+ preg_match('#\[vimeo id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
87
+ }
88
+
89
+ // If we still haven't found anything, check for Vimeo URL
90
+ if(!isset($matches[1])) {
91
+ preg_match('#http://www.vimeo.com/([A-Za-z0-9\-_]+)#s', $markup, $matches);
92
+ }
93
+
94
+ // If we still haven't found anything, check for Vimeo shortcode
95
+ if(!isset($matches[1])) {
96
+ preg_match('#\[vimeo clip_id="([A-Za-z0-9\-_]+)"[^>]*]#s', $markup, $matches);
97
+ }
98
+
99
+ // Now if we've found a Vimeo ID, let's return the thumbnail
100
+ if(isset($matches[1])) {
101
+ $vimeo_thumbnail = getVimeoInfo($matches[1], $info = 'thumbnail_large');
102
+ if(isset($vimeo_thumbnail)) {
103
+ return $vimeo_thumbnail;
104
+ } else {
105
+ // If we can't find the Vimeo thumbnail, display default
106
+ return null;
107
+ }
108
+ }
109
+
110
+ // If nothing has been found, look for Blip.tv
111
+ else {
112
+ preg_match('#http://blip.tv/file/([0-9]+)#s', $markup, $matches);
113
+ if(isset($matches[1])) {
114
+ return getBliptvInfo($matches[1]);
115
+ }
116
+ else {
117
+ return null;
118
+ }
119
+ }
120
+ }
121
+
122
+ };
123
+
124
+ // Echo thumbnail
125
+ function video_thumbnail() {
126
+ if( ( $video_thumbnail = get_video_thumbnail() ) == null ) { echo plugins_url() . "/video-thumbnails/default.jpg"; }
127
+ else { echo $video_thumbnail; }
128
+ };
129
+
130
+ ?>