Search code examples
javascriptvimeo-api

How to get Vimeo video id from thumbnail url


I was testing Vimeo API and got stuck. I have a Vimeo video thumbnail url and I want to get video id from it. Is it even possible to do that? As far as I looked, thumbnails are generated randomly by frames.

Example: I have a thumbnail (https://i.vimeocdn.com/video/{id}) and I need to get real video id from it because id in this URL is only for thumbnail / randomly generated by frames.


Solution

  • In regards to my comment, parse the URL using Regex. This is parsing the id from an https URL.

    In regards to your updated post, it seem's that Vimeo dynamically updates the thumbnail filename's which makes sense, as there would be a need have more than one for each video. And in this regard, it does not seem to be easily relatable to reverse or conceive a video ID from the thumbnail.

    Obviously using a similar method below, you would be able to get the ID of a Viemo video, by the actually video permalink. But since you after editing your post clarified you are asking to retrieve a video ID from a thumbnail.

    I suggest you sign up for Vimeo's developer API.

    You then may retrieve information all at once in a proper fashion.

    http://vimeo.com/api/v2/video/9696328.xml

    Note: Or simply do it in reverse, video then retrieve the thumbnail if this is applicable for your situation.

    // Comment Suggestion GalaxyCat105: 
    // RegX: /(https|http):\/\/(www\.)?i.vimeocdn.com\/video\/(\d+)($|\/)/
    
    
    function thumbnail(url) 
    {       // Match ending, minus extension
            let m = url.match(/(?:[^/][\d\w\.]+).+?(?=_)/);
            url = m[0]
            // Strip URL
            m = url.match(/(https|http):\/\/(www\.)?i.vimeocdn.com\/video\/(\d+)($|\/)/);
            console.log(m[3]);
    }
    
    thumbnail('https://i.vimeocdn.com/video/834713810_260x147.jpg');