0

Posting a video on tumblr.com allows you to just paste the URL of the video on youtube, vimeo, whatever and tumblr automatically does the embedding for you.

I assume that this would be nothing more than a mapping between an URL-regex and the belonging HTML construct for embedding the video. Or it is just parsing the response of the URL and getting the construct from there.

Is there already any utility, preferably in Java, for doing this? If not, how would you do it?

Markus
  • 1,772
  • 1
  • 12
  • 20

2 Answers2

0

I don't know utilities that will automate this for you. I use 3 REGEX to find video ID for youtube, vimeo and dailymotion that I map with the embedding code.

This is the 3 REGEX that I use:

Pattern YOUTUBE_PATTERN     = Pattern.compile("^.*(?:youtu.be\\/|v\\/|e\\/|u\\/\\w+\\/|embed\\/|v=)([^#\\&\\?]*).*");
Pattern VIMEO_PATTERN       = Pattern.compile("^.*(?:vimeo.com)\\/(?:channels\\/|groups\\/[^\\/]*\\/videos\\/|album\\/\\d+\\/video\\/|video\\/|)(\\d+)(?:$|\\/|\\?)");
Pattern DAILYMOTION_PATTERN = Pattern.compile("^.*(?:dailymotion.com)(?:\\/embed)?\\/(video|hub)\\/([^_#\\&\\?]*)[^#]*(?:#video=([^_&]+))?.*");

The video ID for youtube and vimeo is found in the first group.

For dailymotion, there is a little twist, the video ID is found in group 2 or 3.

service-paradis
  • 3,333
  • 4
  • 34
  • 43
0

I don't know any utilities to do this. I doubt that there are no standard way to do this across sites.

I would just go through the most popular video sites and check how embedding is done in each one. It should be rather straight forward to map a URL to video to embedded. You could check how tumblr does it.

Juha Syrjälä
  • 33,425
  • 31
  • 131
  • 183