Video Thumbnails - Version 0.5.1

Version Description

  • Added a test to make sure the YouTube thumbnail actually exists. This prevents you from getting that ugly default thumbnail from YouTube.
Download this release

Release Info

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

Code changes from version 0.2 to 0.5.1

Files changed (3) hide show
  1. readme.txt +49 -12
  2. screenshot-1.gif +0 -0
  3. video-thumbnails.php +129 -39
readme.txt CHANGED
@@ -1,10 +1,10 @@
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.2
8
 
9
  Video Thumbnails is a simple plugin that makes it easier to display video thumbnails in your template.
10
 
@@ -14,16 +14,16 @@ Video Thumbnails makes it simple to display video thumbnails in your templates.
14
 
15
  Video Thumbnails currently supports:
16
 
17
- * YouTube
18
- * Vimeo
19
- * JR Embed (uses `[youtube id=VIDEO_ID]` to embed videos, I've modified mine to also allow `[vimeo id=VIDEO_ID]`)
 
 
20
 
21
  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.
22
 
23
  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 . "' />"; } ?>`
24
 
25
- This is just a start, so don't hesitate to share suggestions and let me know if you find any problems.
26
-
27
  == Installation ==
28
 
29
  1. Upload the `/video-thumbnails/` directory to the `/wp-content/plugins/` directory
@@ -32,7 +32,11 @@ This is just a start, so don't hesitate to share suggestions and let me know if
32
 
33
  == Frequently Asked Questions ==
34
 
35
- = My video service isn't included, can you add it? =
 
 
 
 
36
 
37
  If the service allows a way to retrieve thumbnails, I'll do my best to add it.
38
 
@@ -42,10 +46,29 @@ In version 0.2 `get_video_thumbnail()` was added which returns null when no thum
42
 
43
  == Screenshots ==
44
 
45
- Coming Soon
46
 
47
  == Changelog ==
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  = 0.2 =
50
  * 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.
51
 
@@ -62,7 +85,21 @@ Coming Soon
62
  = 0.1 =
63
  * Initial release
64
 
 
 
 
 
 
65
  == Known Issues ==
66
 
67
- * 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.
68
- * 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.
 
 
 
 
 
 
 
 
 
1
  === Video Thumbnails ===
2
  Contributors: sutherlandboswell
3
  Donate link: http://sutherlandboswell.com
4
+ Tags: Video, YouTube, Vimeo, Blip.tv, Thumbnails
5
  Requires at least: 3.0
6
+ Tested up to: 3.0.2
7
+ Stable tag: 0.5.1
8
 
9
  Video Thumbnails is a simple plugin that makes it easier to display video thumbnails in your template.
10
 
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
  == Installation ==
28
 
29
  1. Upload the `/video-thumbnails/` directory to the `/wp-content/plugins/` directory
32
 
33
  == Frequently Asked Questions ==
34
 
35
+ = Why doesn't the thumbnail show up in the meta box on the Edit Post page after I save it? =
36
+
37
+ This is probably happening because `video_thumbnail()` or `get_video_thumbnail()` has not be used in a loop for that post yet. Try loading a page that calls for the thumbnail then checking the Edit Post page again. This will be fixed in a future version.
38
+
39
+ = My video service/embedding plugin isn't included, can you add it? =
40
 
41
  If the service allows a way to retrieve thumbnails, I'll do my best to add it.
42
 
46
 
47
  == Screenshots ==
48
 
49
+ 1. The Video Thumbnail meta box on the Edit Post page
50
 
51
  == Changelog ==
52
 
53
+ = 0.5.1 =
54
+ * Added a test to make sure the YouTube thumbnail actually exists. This prevents you from getting that ugly default thumbnail from YouTube.
55
+
56
+ = 0.5 =
57
+ * Thumbnail URLs are now stored in a custom field with each post, meaning the plugin only has to interact with outside APIs once per post.
58
+ * Added a "Video Thumbnail" meta box to the edit screen for each post, which can be manually set or will be set automatically once `video_thumbnail()` or `get_video_thumbnail()` is called in a loop for that post.
59
+
60
+ = 0.3 =
61
+ * Added basic support for Blip.tv auto embedded using URLs in this format: http://blip.tv/file/12345
62
+
63
+ = 0.2.3 =
64
+ * Added support for any Vimeo URL
65
+
66
+ = 0.2.2 =
67
+ * Added support for [Vimeo Shortcode](http://blog.esimplestudios.com/2010/08/embedding-vimeo-videos-in-wordpress/)
68
+
69
+ = 0.2.1 =
70
+ * Added support for Vimeo players embedded using an iframe
71
+
72
  = 0.2 =
73
  * 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.
74
 
85
  = 0.1 =
86
  * Initial release
87
 
88
+ == Upgrade Notice ==
89
+
90
+ = 0.5 =
91
+ This version adds the thumbnail URL to the post's meta data, meaning any outside APIs only have to be queried once per post. Vimeo's rate limit was easily exceeded, so this should fix that problem.
92
+
93
  == Known Issues ==
94
 
95
+ * Thumbnail URLs are not found and stored until `video_thumbnail()` or `get_video_thumbnail()` is called in a loop for that post. Future versions will handle this at the time of publishing.
96
+ * While not really an issue, the current method for only displaying a thumbnail if one is found seems like it could be streamlined for less experienced users, so if you have any suggestions let me know.
97
+
98
+ == Roadmap ==
99
+
100
+ 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:
101
+
102
+ * More comprehensive Blip.tv support
103
+ * Local thumbnail caching
104
+ * More services
105
+ * Compatibility with more plugins
screenshot-1.gif ADDED
Binary file
video-thumbnails.php CHANGED
@@ -2,10 +2,10 @@
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.2
9
  License: GPL2
10
  */
11
  /* Copyright 2010 Sutherland Boswell (email : sutherland.boswell@gmail.com)
@@ -38,56 +38,113 @@ function getVimeoInfo($id, $info = 'thumbnail_large') {
38
  return $output;
39
  };
40
 
 
 
 
 
 
 
 
 
41
  // The Main Event
42
  function get_video_thumbnail() {
43
-
44
- // Gets the post's content
45
- $markup = get_the_content();
46
-
47
- // Checks for a standard YouTube embed
48
- preg_match('#<object[^>]+>.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?</object>#s', $markup, $matches);
49
-
50
- // Checks for any YouTube URL
51
- if(!isset($matches[1])) {
52
- preg_match('#http://www.youtube.com/watch\?v=([A-Za-z0-9\-_]+)#s', $markup, $matches);
53
- }
54
 
55
- // If no standard YouTube embed is found, checks for one embedded with JR_embed
56
- if(!isset($matches[1])) {
57
- preg_match('#\[youtube id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
 
58
  }
59
-
60
- // If we've found a YouTube video ID, return the thumbnail URL
61
- if(isset($matches[1])) {
62
- return 'http://img.youtube.com/vi/' . $matches[1] . '/0.jpg';
63
- }
64
-
65
- // If we didn't find anything, check for a standard Vimeo embed
66
  else {
67
- preg_match('#<object[^>]+>.+?http://vimeo.com/moogaloop.swf\?clip_id=([A-Za-z0-9\-_]+)&.+?</object>#s', $markup, $matches);
 
 
 
68
 
69
- // If we still haven't found anything, check for Vimeo embedded with JR_embed
70
- if(!isset($matches[1])) {
71
- preg_match('#\[vimeo id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
72
- };
73
 
74
- // Now if we've found a Vimeo ID, let's return the thumbnail
 
 
 
 
 
 
 
 
 
 
75
  if(isset($matches[1])) {
76
- $vimeo_thumbnail = getVimeoInfo($matches[1], $info = 'thumbnail_large');
77
- if(isset($vimeo_thumbnail)) {
78
- return $vimeo_thumbnail;
79
- } else {
80
- // If we can't find the Vimeo thumbnail, display default
81
- return null;
 
 
 
 
 
82
  }
83
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
- // If nothing has been found, show the default
86
- else {
87
- return null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
- }
 
 
 
 
 
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  };
92
 
93
  // Echo thumbnail
@@ -96,4 +153,37 @@ function video_thumbnail() {
96
  else { echo $video_thumbnail; }
97
  };
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  ?>
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. Add <code>&lt;?php video_thumbnail(); ?&gt;</code> to your loop to return a thumbnail, or check the FAQ section for more advanced uses. Currently works with YouTube, Vimeo, and Blip.tv, with other services coming soon.
6
  Author: Sutherland Boswell
7
  Author URI: http://sutherlandboswell.com
8
+ Version: 0.5.1
9
  License: GPL2
10
  */
11
  /* Copyright 2010 Sutherland Boswell (email : sutherland.boswell@gmail.com)
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
+ $thumbnail = (string) $result[0]['url'];
46
+ return $thumbnail;
47
+ }
48
+
49
  // The Main Event
50
  function get_video_thumbnail() {
 
 
 
 
 
 
 
 
 
 
 
51
 
52
+ // Check to see if thumbnail has already been found
53
+ $postid = get_the_ID();
54
+ if( ($thumbnail_meta = get_post_meta($postid, '_video_thumbnail', true)) != '' ) {
55
+ return $thumbnail_meta;
56
  }
57
+ // If the thumbnail isn't stored in custom meta, fetch a thumbnail
 
 
 
 
 
 
58
  else {
59
+
60
+ // Gets the post's content
61
+ $markup = get_the_content();
62
+ $new_thumbnail = null;
63
 
64
+ // Checks for a standard YouTube embed
65
+ preg_match('#<object[^>]+>.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?</object>#s', $markup, $matches);
 
 
66
 
67
+ // Checks for any YouTube URL
68
+ if(!isset($matches[1])) {
69
+ preg_match('#http://w?w?w?.?youtube.com/watch\?v=([A-Za-z0-9\-_]+)#s', $markup, $matches);
70
+ }
71
+
72
+ // If no standard YouTube embed is found, checks for one embedded with JR_embed
73
+ if(!isset($matches[1])) {
74
+ preg_match('#\[youtube id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
75
+ }
76
+
77
+ // If we've found a YouTube video ID, create the thumbnail URL
78
  if(isset($matches[1])) {
79
+ $youtube_thumbnail = 'http://img.youtube.com/vi/' . $matches[1] . '/0.jpg';
80
+
81
+ // Check to make sure it's an actual thumbnail
82
+ $ch = curl_init($youtube_thumbnail);
83
+ curl_setopt($ch, CURLOPT_NOBODY, true);
84
+ curl_exec($ch);
85
+ $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
86
+ // $retcode > 400 -> not found, $retcode = 200, found.
87
+ curl_close($ch);
88
+ if($retcode==200) {
89
+ $new_thumbnail = $youtube_thumbnail;
90
  }
91
  }
92
+
93
+ // Vimeo
94
+ if($new_thumbnail==null) {
95
+
96
+ // Standard embed code
97
+ preg_match('#<object[^>]+>.+?http://vimeo.com/moogaloop.swf\?clip_id=([A-Za-z0-9\-_]+)&.+?</object>#s', $markup, $matches);
98
+
99
+ // Find Vimeo embedded with iframe code
100
+ if(!isset($matches[1])) {
101
+ preg_match('#http://player.vimeo.com/video/([0-9]+)#s', $markup, $matches);
102
+ }
103
+
104
+ // If we still haven't found anything, check for Vimeo embedded with JR_embed
105
+ if(!isset($matches[1])) {
106
+ preg_match('#\[vimeo id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
107
+ }
108
 
109
+ // If we still haven't found anything, check for Vimeo URL
110
+ if(!isset($matches[1])) {
111
+ preg_match('#http://w?w?w?.?vimeo.com/([A-Za-z0-9\-_]+)#s', $markup, $matches);
112
+ }
113
+
114
+ // If we still haven't found anything, check for Vimeo shortcode
115
+ if(!isset($matches[1])) {
116
+ preg_match('#\[vimeo clip_id="([A-Za-z0-9\-_]+)"[^>]*]#s', $markup, $matches);
117
+ }
118
+
119
+ // Now if we've found a Vimeo ID, let's set the thumbnail URL
120
+ if(isset($matches[1])) {
121
+ $vimeo_thumbnail = getVimeoInfo($matches[1], $info = 'thumbnail_large');
122
+ if(isset($vimeo_thumbnail)) {
123
+ $new_thumbnail = $vimeo_thumbnail;
124
+ }
125
+ }
126
  }
127
+
128
+ // Blip.tv
129
+ if($new_thumbnail==null) {
130
+
131
+ // Blip.tv file URL
132
+ preg_match('#http://blip.tv/file/([0-9]+)#s', $markup, $matches);
133
 
134
+ // Now if we've found a Blip.tv file URL, let's set the thumbnail URL
135
+ if(isset($matches[1])) {
136
+ $blip_thumbnail = getBliptvInfo($matches[1]);
137
+ $new_thumbnail = $blip_thumbnail;
138
+ }
139
+ }
140
+
141
+ // Return the new thumbnail variable and update meta if one is found
142
+ if($new_thumbnail!=null) {
143
+ if(!update_post_meta($postid, '_video_thumbnail', $new_thumbnail)) add_post_meta($postid, '_video_thumbnail', $new_thumbnail);
144
+ }
145
+ return $new_thumbnail;
146
+
147
+ }
148
  };
149
 
150
  // Echo thumbnail
153
  else { echo $video_thumbnail; }
154
  };
155
 
156
+ // Create Meta Fields on Edit Page
157
+
158
+ add_action("admin_init", "admin_init");
159
+
160
+ function admin_init(){
161
+ add_meta_box("video_thumbnail", "Video Thumbnail", "video_thumbnail_admin", "post", "side", "low");
162
+ }
163
+
164
+ function video_thumbnail_admin(){
165
+ global $post;
166
+ $custom = get_post_custom($post->ID);
167
+ $video_thumbnail = $custom["_video_thumbnail"][0];
168
+ ?>
169
+ <p><label>Video Thumbnail URL:</label></p>
170
+ <p><input type="text" size="16" name="video_thumbnail" style="width:250px;" value="<?php echo $video_thumbnail; ?>" /></p>
171
+ <?php if(isset($video_thumbnail) && $video_thumbnail!='') { ?><p><img src="<?php echo $video_thumbnail; ?>" width="100%" /></p><?php } ?>
172
+ <?php
173
+ }
174
+
175
+ // Save Meta Details
176
+
177
+ add_action('save_post', 'save_details');
178
+
179
+ function save_details(){
180
+ global $post;
181
+ if(isset($_POST["video_thumbnail"]) && $_POST["video_thumbnail"]!='') {
182
+ if(!update_post_meta($post->ID, "_video_thumbnail", $_POST["video_thumbnail"])) add_post_meta($post->ID, "_video_thumbnail", $_POST["video_thumbnail"]);
183
+ }
184
+ if(isset($_POST["video_thumbnail"]) && $_POST["video_thumbnail"]=='') {
185
+ delete_post_meta($post->ID, "_video_thumbnail");
186
+ }
187
+ }
188
+
189
  ?>