Jump to content

Youtube And Vimeo Thumbnail Grabber


Recommended Posts

This is a very simple module that I put together for @Zahari Majini from a PM request.

It allows you to enter a URL to a YouTube or Vimeo video in a specified field and when you save the page, it will grab thumbnails for the video and add them to a specified images field.

Check the module configuration options for:

  • the field(s) to search for videos
  • name of the video images field
  • which thumbnail(s) you want grabbed
  • whether to grab the first available or all available thumbnails based on those that you list

As always, an feedback for improvements is very welcome!


Modules Directory: http://modules.processwire.com/modules/process-get-video-thumbs/

Github: https://github.com/adrianbj/GetVideoThumbs



  • Like 13
Link to comment
Share on other sites

Hey Ryan,

I have come up against that wireEncodeJSON issue with a leading 0 (that I had in the phone field module) again with this module. I guess I will need to implement the same workaround, appending a tilde and stripping on loading again.

Any chance you could make that change to allow for leading zeros so we don't have to do this forever?


  • Like 1
Link to comment
Share on other sites

Thanks Martijn,

That high res version is great - "maxresdefault". It is the only one that doesn't get letterboxed, which actually makes it useful, unlike the other ones! 

I also added "hqdefault" and "default" as other default options. I also added checks to make sure an image exists before trying to add it to the images field.

Now along with Antti's thumbnail module, Horst's PIM module, or your Image Interceptor module it should be possible to manipulate that high res version however the user wants!

  • Like 1
Link to comment
Share on other sites

Ok, just added another new option (v5). You can now decide whether you want to grab all the available images listed, or just the first available one (default).

This way you can list all available images, but if one doesn't exist, it will move onto the next in the comma separated list until it finds one that does exist. List them in your order of preference.

Link to comment
Share on other sites

Wow! Isn't this a truely amazing community!!!

I am so so so grateful to Adrian for having created this!

I'm trying to create a site that will help categorize and show videos from my Vimeo account. The oembed module from Ryan makes it so easy to just copy the url and paste it into our text editor. This was one great great step forward.

The thing that was missing / needed imho was a way of automatically fetching the thumbnails of these videos so that when we create a list of video episodes with a title and description, we could make these excerpts and our page of results way more interesting and media rich by displaying a thumbnail of our video as well!!

I'm one slow learner. Go ahead and laugh... but the first thing I thought of to do all this was create an image field and then looked for a screen capture program that could take a picture of the oembeded video showing on my page at full size, and then manually feeding that screen grab into a custom image field for the page to subsequently display it resized into a thumbnail. So i thought after doing this the manual way, surely the video hosters might give you a way of extracting an image from the video and sure enough, looking at the Vimeo API, they did.

And so I wrote to Adrian asking him if he could help me / point me into the right direction as to how to go about doing this. I initially thought that we needed to modify Ryans oembed module. But Adrian explained to me that way to go about it conceptually was to create a hook before you save the page, get the image from Vimeo or whoever, and use the PW API to save this to an image field.

Ahhh... an Eureka moment for me! Now hooks in PW make more sense to me and of course having the obvious need for this hook, we now know that we need our PW API for saving an image so the API's relevance seems much greater now too!! Somethings abstract instantly become a developers best friends!!

BTW, I used hooks in WordPress quite a bit as basically there were so many things you wanted WP to do differently, and so hooks are typically used there to swap out and change the behaviour of a particular function. But I never really looked at hooks in PW as it seems to do everything right in the first place and as a result never really had any reason to even look into them :biggrin:

Anyways... can't wait to try this module and see how it works!

Thank you Adrian !!!!!!!

  • Like 1
Link to comment
Share on other sites

v6 now has optional (default) automatic file renaming.

Images will be named with this format: videoID-ImageName.jpg 

where, the videoID is the ID of video from YouTube or Vimeo and ImageName is the name of the image and matches those names that are in the Youtube Image Names and Vimeo Image Names config fields.

I think this standardized format will make it much easier to call the images via the API in templates.

Ok, hopefully that is it for a while unless anyone else has any other suggestions :)

  • Like 1
Link to comment
Share on other sites

Hey Adrian

I just downloaded version 5 and one minute later I came back here to report how awesome it is and that it works!!!

But now, what do I see? There is now a version 6!

You are truly prolific and awesome!

Just as a note, Video Image Names lists as its placeholder text: thumbnail_large, thumbnail_medium, thumbnail_small.

Perhaps this placeholder list needs to be swapped around as it says below this:

Default: thumbnail_small, thumbnail_medium, thumbnail_large

What I did was I swapped around the placeholder text to match your default description text, that is to say I entered thumbnail_small, thumbnail_medium, thumbnail_large

and then I selected First Image under Which Images.

This works great!!

Your idea of adding the video ID to the thumbnail was brilliant too Adrian!!

AWESOME!!!!!!! :-) :-) :-)

Link to comment
Share on other sites

v6 takes care of the inconsistent order between default and the labeling. I still have the default order with large first though as I figure you can always resize with the PW API, but obviously it comes down to each use case, which is why the order is configurable :)

I'll add to the modules directory now, so updating to new versions will be easy :)

Thanks for the kudos.

Link to comment
Share on other sites

Just pushed a new update that supports multiple videos in multiple fields on a page, so this should now work seamlessly with the VideoEmbed module.

Also, you can now select the fields to search and the images field to populate using dropdown selects, rather than manually entering. The list of fields is limited to appropriate field types.

Thumbnails in first post have been updated to show new functionality.

  • Like 1
Link to comment
Share on other sites

Adrian, I must admit, I didn't install/test your module yet. But I love it as it works the way you told us.

Within the next 2 or 3 weeks or so I gonna start a bigger project. A thing it need, is to find articles containing a video.

Your module will be installed for that, as I can query for images, thus containing a video.

I thing I wish ( Maybe I can build, or it's already in there ) is that it deletes the images if the url to the video is gone.

I hope I will find time to work on it this week. 

Are you open for additions to this module ?

Link to comment
Share on other sites

Hey Martijn,

I have made some substantial changes and pushed to github:

  • Images are no longer deleted and repopulated by default - makes saving the page when there are no changes to the videos much faster as this module doesn't have to do much.
  • Any images that are from videos that have been removed from the page are now deleted on a per video basis (ie if the URL is now gone)
  • I have removed the option to disable image renaming - renaming proved essential to make the above two options work properly. I don't think this should be a problem.
  • Renaming is handled slightly differently now
    • if you choose "First Available" for Which Images, it will name the image like so: videoID.jpg (eg: pmqzchx-mtc.jpg)
    • if you choose "All Available" images it will append the name to the videoID: videoID-imageName.jpg (eg: pmqzchx-mtc-maxresdefault.jpg)
    • I think this change will make it even easier to call the image from the API as you can directly match the image name to the video ID without knowing which one was grabbed. You just need to do a strtolower on the video ID as image names in PW must be lowercase.

I think that's it, but definitely open to additions if you have ideas / code.

EDIT: v0.1.3 limits module to page edit process only - prevents php notices on other admin pages.

Edited by adrian
  • Like 2
Link to comment
Share on other sites

Another small update. Images now have "video-" prefixed to their filenames. This allows the images field to also store user uploaded images, in addition to the video images. When the module checks for videos that are no longer present on the page, it will no longer delete images that the user has uploaded, unless of course they happen to have "video-" in the filename as well. Hopefully this is a reasonable approach to this. Let me know if it causes anyone any problems and I'll revisit.

  • Like 1
Link to comment
Share on other sites

  • 5 months later...

@videokid - thanks for the report.

I have just committed a quick fix for this. I am not sure on the best solution, but the Custom Upload Names module will now ignore any images with an initial filename that contains "youtube" or "vimeo". Of course that means that these won't get renamed at all, but I think that is probably the best behavior at the moment.

Please let me know how it works for you.

EDIT: Just to clarify - it is Custom Upload Names that got the update, not GetVideoThumbs

Edited by adrian
  • Like 1
Link to comment
Share on other sites

Wow, quick response and action!

Actually I just wanted to report, @the moment it wasn't a very big deal for me. Kinda heads up for future reference.

But because of your quick modification I've tried it out... and it seems to work just fine, so :ThumbsUp: [there should be a emoticon ;) ]

Kind regards!

  • Like 1
Link to comment
Share on other sites

Well, while we're at it.... 

Not as much as a problem, something I noticed. I also use the module 'Images With Cropping' [inputfieldCropImage].

I have a field called 'images' and if you select in the 'basics' 'CropImage', the module 'Get Video Thumbnails' doesn't recognize the created field 'images'.

Of course I choose 'images' in the 'basics' and in 'details' I choose Inputfield type 'CropImage'.

I haven't examined both modules [the coding I mean], again, I'm already happy everything works as expected... Could be 'CropImage' shouldn't even be selectable in the basics.

But since I'm in reporting/noticing modus... lol

Again, big appreciation for the work you've done!

  • Like 1
Link to comment
Share on other sites

Actually, that was an oversight on my part. I have just committed an update so that GetVideoThumbs now supports CropImage fieldtypes, and any other fieldtypes that are an instanceof FieldtypeImage. Before I was limiting it just to FieldtypeImage. 

Let me know if it works ok for you.

As for the configuration options of CropImage - ie changing the fieldtype (basics tab) vs the inputfield (details tab). I haven't tested, but I always assumed you needed to change both. Might be a more appropriate question for the support thread for that module though.

  • Like 2
Link to comment
Share on other sites

As soon as I have time I will test the update, it works anyhow for the moment. Once the site I'm working on is done and online, I will test on the dev one.

Why you may wonder... it's almost done and I don't want to break things for the moment [you never know]... and on top of that, this is the only 2.4.1 version running atm, so you'll be up-to-speed also.

I had the same assumption btw, but in September/November last year I found out that actually worked... and if it's working, no need fixing things, right?

Will report back ASAP. Thank you already!

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.

      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
    • By tcnet
      This module implements the website live chat service from tawk.to. Actually the module doesn't have to do much. It just need to inserted a few lines of JavaScript just before the closing body tag </body> on each side. However, the module offers additional options to display the widget only on certain pages.
      Create an account
      Visit https://www.tawk.to and create an account. It's free! At some point you will reach a page where you can copy the required JavaScript-code.

      Open the module settings and paste the JavaScript-code into the field as shown below. Click "Submit" and that's all.

      Open the module settings
      The settings for this module are located int the menu Modules=>Configure=>LiveChatTawkTo.

  • Create New...