Jump to content
adrian

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

post-985-0-42973500-1381164961_thumb.png

post-985-0-01921900-1381164969_thumb.png

  • Like 13

Share this post


Link to post
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?

Thanks

  • Like 1

Share this post


Link to post
Share on other sites

There's also a highres if the upload is HD and Youtube has processed the video. But you need to check, before using.

My experience is that YouTube doesn't always provide every image. If the image is not available, google gives a smaller image back then expected.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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!!!!!!! :-) :-) :-)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Ahah...

What you say makes great sense Adrian about grabbing the bigger / biggest one so that we can subsequently resize it smaller should the need arise.

Thanks again Adrian!

:-)

Share this post


Link to post
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

Share this post


Link to post
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 ?

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I'd like to report this module in addition with Customn Upload Names obviously result in strange things :-)

Cheers!

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

No worries - we aim to please :)

Thanks again for letting me know about the problem!

  • Like 2

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

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

give mqdefault a try. doesn't get letterboxed for me :)

Share this post


Link to post
Share on other sites

Thanks @woop. I hadn't seen that option before. I just committed a small update that includes that in the default list of thumbnails to grab.

Share this post


Link to post
Share on other sites

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 Paul Greinke
      Hi there. I wrote a custom module for one of my projects. In fact I maybe want to use my module in other projects too. In order to be variable and customizable  I need to implement some custom hooks into my module. So I can afterwards hook into the my functions in order to modify them to match the needs of the new project.
      I tried simply defining functions with the '__' prefix. But that did not work. I'm imagining something like the following:
      <?php class MyClass { public function ___someFunction() { // Do something } } // ready.php $this->addHookBefore('MyClass::someFunction', function($event) { // some customization }); Is there a way to accomplish that? 
    • By adrian
      Hi everyone,
      Here's a new module that I have been meaning to build for a long time.
      http://modules.processwire.com/modules/process-admin-actions/
      https://github.com/adrianbj/ProcessAdminActions
       
      What does it do?
      Do you have a bunch of admin snippets laying around, or do you recreate from them from scratch every time you need them, or do you try to find where you saw them in the forums, or on the ProcessWire Recipes site?
      Admin Actions lets you quickly create actions in the admin that you can use over and over and even make available to your site editors (permissions for each action are assigned to roles separately so you have full control over who has access to which actions).
       
      Included Actions
      It comes bundled with several actions and I will be adding more over time (and hopefully I'll get some PRs from you guys too). You can browse and sort and if you have @tpr's Admin on Steroid's datatables filter feature, you can even filter based on the content of all columns. 

      The headliner action included with the module is: PageTable To RepeaterMatrix which fully converts an existing (and populated) PageTable field to either a Repeater or RepeaterMatrix field. This is a huge timesaver if you have an existing site that makes heavy use of PageTable fields and you would like to give the clients the improved interface of RepeaterMatrix.
      Copy Content To Other Field
      This action copies the content from one field to another field on all pages that use the selected template.
      Copy Field Content To Other Page
      Copies the content from a field on one page to the same field on another page.
      Copy Repeater Items To Other Page
      Add the items from a Repeater field on one page to the same field on another page.
      Copy Table Field Rows To Other Page
      Add the rows from a Table field on one page to the same field on another page.
      Create Users Batcher
      Allows you to batch create users. This module requires the Email New User module and it should be configured to generate a password automatically.
      Delete Unused Fields
      Deletes fields that are not used by any templates.
      Delete Unused Templates
      Deletes templates that are not used by any pages.
      Email Batcher
      Lets you email multiple addresses at once.
      Field Set Or Search And Replace
      Set field values, or search and replace text in field values from a filtered selection of pages and fields.
      FTP Files to Page
      Add files/images from a folder to a selected page.
      Page Active Languages Batcher
      Lets you enable or disable active status of multiple languages on multiple pages at once.
      Page Manipulator
      Uses an InputfieldSelector to query pages and then allows batch actions on the matched pages.
      Page Table To Repeater Matrix
      Fully converts an existing (and populated) PageTable field to either a Repeater or RepeaterMatrix field.
      Template Fields Batcher
      Lets you add or remove multiple fields from multiple templates at once.
      Template Roles Batcher
      Lets you add or remove access permissions, for multiple roles and multiple templates at once.
      User Roles Permissions Batcher
      Lets you add or remove permissions for multiple roles, or roles for multiple users at once.
       
      Creating a New Action
      If you create a new action that you think others would find useful, please add it to the actions subfolder of this module and submit a PR. If you think it is only useful for you, place it in /site/templates/AdminActions/ so that it doesn't get lost on module updates.
      A new action file can be as simple as this:
      class UnpublishAboutPage extends ProcessAdminActions { protected function executeAction() { $p = $this->pages->get('/about/'); $p->addStatus(Page::statusUnpublished); $p->save(); return true; } } Each action:
      class must extend "ProcessAdminActions" and the filename must match the class name and end in ".action.php" like: UnpublishAboutPage.action.php the action method must be: executeAction() As you can see there are only a few lines needed to wrap the actual API call, so it's really worth the small extra effort to make an action.
      Obviously that example action is not very useful. Here is another more useful one that is included with the module. It includes $description, $notes, and $author variables which are used in the module table selector interface. It also makes use of the defineOptions() method which builds the input fields used to gather the required options before running the action.
      class DeleteUnusedFields extends ProcessAdminActions { protected $description = 'Deletes fields that are not used by any templates.'; protected $notes = 'Shows a list of unused fields with checkboxes to select those to delete.'; protected $author = 'Adrian Jones'; protected $authorLinks = array( 'pwforum' => '985-adrian', 'pwdirectory' => 'adrian-jones', 'github' => 'adrianbj', ); protected function defineOptions() { $fieldOptions = array(); foreach($this->fields as $field) { if ($field->flags & Field::flagSystem || $field->flags & Field::flagPermanent) continue; if(count($field->getFieldgroups()) === 0) $fieldOptions[$field->id] = $field->label ? $field->label . ' (' . $field->name . ')' : $field->name; } return array( array( 'name' => 'fields', 'label' => 'Fields', 'description' => 'Select the fields you want to delete', 'notes' => 'Note that all fields listed are not used by any templates and should therefore be safe to delete', 'type' => 'checkboxes', 'options' => $fieldOptions, 'required' => true ) ); } protected function executeAction($options) { $count = 0; foreach($options['fields'] as $field) { $f = $this->fields->get($field); $this->fields->delete($f); $count++; } $this->successMessage = $count . ' field' . _n('', 's', $count) . ' ' . _n('was', 'were', $count) . ' successfully deleted'; return true; } }  
      This defineOptions() method builds input fields that look like this:

      Finally we use $options array in the executeAction() method to get the values entered into those options fields to run the API script to remove the checked fields.
      There is one additional method that I didn't outline called: checkRequirements() - you can see it in action in the PageTableToRepeaterMatrix action. You can use this to prevent the action from running if certain requirements are not met.
      At the end of the executeAction() method you can populate $this->successMessage, or $this->failureMessage which will be returned after the action has finished.
       
      Populating options via URL parameters
      You can also populate the option parameters via URL parameters. You should split multiple values with a “|” character.
      You can either just pre-populate options:
      http://mysite.dev/processwire/setup/admin-actions/options?action=TemplateFieldsBatcher&templates=29|56&fields=219&addOrRemove=add
      or you can execute immediately:
      http://mysite.dev/processwire/setup/admin-actions/execute?action=TemplateFieldsBatcher&templates=29|56&fields=219&addOrRemove=add

      Note the “options” vs “execute” as the last path before the parameters.
       
      Automatic Backup / Restore
      Before any action is executed, a full database backup is automatically made. You have a few options to run a restore if needed:
      Follow the Restore link that is presented after an action completes Use the "Restore" submenu: Setup > Admin Actions > Restore Move the restoredb.php file from the /site/assets/cache/AdminActions/ folder to the root of your site and load in the browser Manually restore using the AdminActionsBackup.sql file in the /site/assets/cache/AdminActions/ folder I think all these features make it very easy to create custom admin data manipulation methods that can be shared with others and executed using a simple interface without needing to build a full Process Module custom interface from scratch. I also hope it will reduce the barriers for new ProcessWire users to create custom admin functionality.
      Please let me know what you think, especially if you have ideas for improving the interface, or the way actions are defined.
       
       
    • By joshua
      ---
      Module Directory: https://modules.processwire.com/modules/privacy-wire/
      Github: https://github.com/blaueQuelle/privacywire/
      Packagist:https://packagist.org/packages/blauequelle/privacywire
      Module Class Name: PrivacyWire
      Changelog: https://github.com/blaueQuelle/privacywire/blob/master/Changelog.md
      ---
      This module is (yet another) way for implementing a cookie management solution.
      Of course there are several other possibilities:
      - https://processwire.com/talk/topic/22920-klaro-cookie-consent-manager/
      - https://github.com/webmanufaktur/CookieManagementBanner
      - https://github.com/johannesdachsel/cookiemonster
      - https://www.oiljs.org/
      - ... and so on ...
      In this module you can configure which kind of cookie categories you want to manage:

      You can also enable the support for respecting the Do-Not-Track (DNT) header to don't annoy users, who already decided for all their browsing experience.
      Currently there are four possible cookie groups:
      - Necessary (always enabled)
      - Functional
      - Statistics
      - Marketing
      - External Media
      All groups can be renamed, so feel free to use other cookie group names. I just haven't found a way to implement a "repeater like" field as configurable module field ...
      When you want to load specific scripts ( like Google Analytics, Google Maps, ...) only after the user's content to this specific category of cookies, just use the following script syntax:
      <script type="text/plain" data-type="text/javascript" data-category="statistics" data-src="/path/to/your/statistic/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="marketing" data-src="/path/to/your/mareketing/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="external_media" data-src="/path/to/your/external-media/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="marketing">console.log("Inline scripts are also working!");</script> The data-attributes (data-type and data-category) are required to get recognized by PrivacyWire. the data-attributes are giving hints, how the script shall be loaded, if the data-category is within the cookie consents of the user. These scripts are loaded asynchronously after the user made the decision.
      If you want to give the users the possibility to change their consent, you can use the following Textformatter:
      [[privacywire-choose-cookies]] It's planned to add also other Textformatters to opt-out of specific cookie groups or delete the whole consent cookie.
      You can also add a custom link to output the banner again with a link / button with following class:
      <a href="#" class="privacywire-show-options">Show Cookie Options</a> <button class="privacywire-show-options">Show Cookie Options</button>  
      I would love to hear your feedback 🙂
      CHANGELOG
      You can find the always up-to-date changelog file here.
    • By joshua
      As we often use Matomo (former known as Piwik) instead of Google Analytics we wanted to embed Matomo not only in the template code but also via the ProcessWire backend.
      That's why I developed a tiny module for the implementation.
      The module provides the possibility to connect to an existing Matomo installation with the classical site tracking and also via the Matomo Tag Manager.
      If you have also PrivacyWire installed, you can tell MatomoWire to only load the script, if the user has accepted cookies via PrivacyWire.
      To offer an Opt-Out solution you can choose between the simple Opt-Out iFrame, delivered by your Matomo installation, or a button to choose cookies via PrivacyWire.
      You'll find the module both in the module directory and via github:
      ProcessWire Module Directory MatomoWire @ GitHub MatomoWire @ Packagist ->installable via composer require blauequelle/matomowire I'm looking forward to hear your feedback!


    • By Robin S
      If your module has a lot of config fields you might want to divide them into groups inside a tabbed interface. Here is a demonstration module showing how this can be done.
      https://github.com/Toutouwai/ModuleConfigTabs

      Thanks to @kixe for providing my starting point in this forum topic.
×
×
  • Create New...