Plugin

Developer
Supported

URL Tube

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Mark Spurlock

     

You must be logged in to post.

Output thumbnail url only

General

artmem
artmem

Is there a way to only output the url of a video’s thumbnail, rather than a full image tag? I’d like to be able to pass the url to CE Image to do some manipulations.

Spurlock
# 1
Developer
Spurlock

Hello artmem, thanks for asking about this.

Currently URL Tube doesn’t have an option for outputting thumbnail URLs by themselves. I did some experiments trying to find a way to hack this together with existing tags, but came to an unfortunate conclusion:

As far as I can tell from looking at the template debugging, I think that even if I were to build in this feature, you still wouldn’t get CE Image to play nice with the thumbnail URL. This is because (again, as best I can tell from poking around a bit) the CE Image tag is going to try and parse its “src” attribute as text, not first check to see whether it’s another EE tag. So even if I build in a way for URL Tube to spit out thumbnail URLs, it wouldn’t matter because CE Image would try and do its thing before URL Tube could do its, causing CE Image to get confused and sputter out some nonsense.

Long story short… I don’t think outputting thumbnail URLs would let you accomplish what you’re trying to accomplish even if it were supported. Sorry.

My only suggestion would be to do the URL Tube part of the job with input-stage PHP parsing. If you know PHP well, let me know and I’ll suggest how I’d go about it. If not, probably more trouble than it’s worth.

artmem
# 2
artmem

I played around with it a bit and got it to work.

I added this to the plugin:

function thumburl() 
    
{
        $s 
$this->EE->TMPL->fetch_param('src');
        if (
$this->getVideoSite($s) != 'youtube')
            return;

        
$vid $this->getVideoID($s);
        
$sel $this->makeSelectorString();

        return 
"http://img.youtube.com/vi/$vid/0.jpg";
    

and used this as my CE image tag:

{exp:ce_img:single src="{exp:url_tube:thumburl src='{video}'}" max="300" crop="yes" parse="inward"

Adding parse=“inward” makes CE Image parse the URL Tube tag first.

Spurlock
# 3
Developer
Spurlock

Ah, I totally forgot “parse inward” was a thing. Clever, glad you got it working!

For anyone reading this who doesn’t want to write PHP, I think the following should also work if passed as CE Image’s src and used with parse=‘inward’:

http://img.youtube.com/vi/{exp:url_tube:id src='{whatever}'/0.jpg";