Convert this URL to another format

Hey guys, not really sure how to go about this.

var vimeoURL = "http://player.vimeo.com/video/35740045";
          //organic url - https://vimeo.com/127677319

I have that organic URL, and I need to convert it to the vimeoURL format. E.g. I need it to be player.vimeo.com, not vimeo.com, and I need the /video/ after .com. Could someone help me out? Are there tools online for this to automate this / make it easy?

Ignore the different numbers for the video IDs. Not relevant.

var organicURL = "https://vimeo.com/35740045";
var organicArray = organicURL.split('/');
organicArray[2] = "player." + organicArray[2];
organicArray[4] = organicArray[3];
organicArray[3] = "video";
var vimeoURL = organicArray.join('/');

??? Not tested.

HTH,

:slight_smile:

3 Likes

I LOVE YOU. Vimeo API is a huge PITA. Thank you very much!

Glad I could help. I was wondering if there might be an easier way via RegEx.

var organicURL = "https://vimeo.com/35740045";
var vimeoURL = organicURL.replace(/^(https?:\/\/)(vimeo.com\/)(\d+)$/,'$1player.$2video/$3');
alert(vimeoURL);

I tested this one. It works. And it keeps the protocol (http or https).

HTH,

:slight_smile:

@RyanReese, just curious if you tried my regex solution and what you thought of it.

Have a great weekend,

:slight_smile:

Well I didn’t try your most recent one, because the client decided he wanted something COMPLETELY DIFFERENT. So I wasted 3-4 hours :slight_smile: :slight_smile: . Thanks for your efforts though.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.