lonerunner
lonerunner

Reputation: 1322

Return id of video from metacafe using preg_match or something

Im trying to write plugin that will catch video details from various video websites simply by copy and paste url from browser.

But im having problems with metacafe videos. To fetch details from example this video url

http://www.metacafe.com/watch/cb-V9EJSvnKvTcH/confronting_fear_in_virtual_reality/

I need to go to metacafe http://www.metacafe.com/api/item/cb-V9EJSvnKvTcH/ and parse xml from this video id.

I thought it would be easy but problem is metacafe use only video id for xml data and url contains also video name after id.

To embed only video i use

$video_grab_url = 'http://www.metacafe.com/watch/cb-V9EJSvnKvTcH/confronting_fear_in_virtual_reality/';
$embed_vid_url = parse_url( $video_grab_url );
$metacafe = mb_substr( $embed_vid_url['path'], 7, -1 );

With this i get video id with name for embed. But as i said for other details i need to parse xml data from url and to get url of xml data i need only video id without name.

Im not php pro so i got little lost in using preg_match How do i use preg_match to get only this "cb-V9EJSvnKvTcH" so i can pull xml data and parse info like duration, thumb, tags, etc...

Upvotes: 1

Views: 776

Answers (2)

crash01
crash01

Reputation: 117

Or you can also use something like this:

$url = 'http://www.metacafe.com/watch/cb-V9EJSvnKvTcH/confronting_fear_in_virtual_reality/';
$path = parse_url($url, PHP_URL_PATH);
$pieces = explode('/', $path);

$video_id = $pieces[2];

Upvotes: 0

John Woo
John Woo

Reputation: 263693

Try this one. Maybe this can help you.

(?<=watch/).*?(?=/)

sample PHP code,

<?php
$subject = "theLINKhere";
$pattern = "#(?<=watch/).*?(?=/)#"; // edit: Added modifiers
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);
?>

Upvotes: 1

Related Questions