Jump to content

Problems with strings and replacement


pspcrazy

Recommended Posts

Hi i've been working on a script to take in URLS of video site's and convert them to embed's for wordpress, and it's been successful for most sites, except myspacetv which contains ? = characters.

 

Here's my code so far veoh works, myspace doesn't thanks.

 

// myspace code

define("MYSP_WIDTH", 540);
define("MYSP_HEIGHT", 438);
define("MYSP_REGEXP", "/http:\/\/vids\.myspace\.com\/index\.cfm\?fuseaction=vids\.individual&VideoID=([[:print:]]+)/");
define("MYSP_TARGET", "<object type=\"application/x-shockwave-flash\" style=\"width:".MYSP_WIDTH."px; height:".MYSP_HEIGHT."px;\" data=\"http://lads.myspace.com/videos/vplayer.swf?m=###URL###&type=video\"><param name=\"movie\" value=\"http://lads.myspace.com/videos/vplayer.swf?m=###URL###&type=video\" /></object>");

function mysp_plugin_callback($match)
{
        $output = MYSP_TARGET;
        $output = str_replace("###URL###", strip_tags($match[1]), $output);
        return ($output);
}

function mysp_plugin($content)
{
        return (preg_replace_callback(MYSP_REGEXP, 'mysp_plugin_callback', $content));
}

add_filter('the_content', 'mysp_plugin');
add_filter('comment_text', 'mysp_plugin');

// Veoh code

define("VEOH_WIDTH", 540);
define("VEOH_HEIGHT", 438);
define("VEOH_REGEXP", "/http:\/\/www\.veoh\.com\/videos\/([[:print:]]+)/");
define("VEOH_TARGET", "<object type=\"application/x-shockwave-flash\" style=\"width:".VEOH_WIDTH."px; height:".VEOH_HEIGHT."px;\" data=\"http://www.veoh.com/videodetails2.swf?permalinkId=###URL###&id=11975851&player=videodetailsembedded&videoAutoPlay=0\"><param name=\"movie\" value=\"http://www.veoh.com/videodetails2.swf?permalinkId=###URL###&id=11975851&player=videodetailsembedded&videoAutoPlay=0\" /></object>");

function veoh_plugin_callback($match)
{
        $output = VEOH_TARGET;
        $output = str_replace("###URL###", strip_tags($match[1]), $output);
        return ($output);
}

function veoh_plugin($content)
{
        return (preg_replace_callback(VEOH_REGEXP, 'veoh_plugin_callback', $content));
}

add_filter('the_content', 'veoh_plugin');
add_filter('comment_text', 'veoh_plugin');

Link to comment
Share on other sites

oddly it still doesn't work for me :|

 

See: http://dramacrazy.net/?p=17

 

Also hres the code now for myspacetv

 

 

// myspace code

define("MYSP_WIDTH", 540);
define("MYSP_HEIGHT", 438);
define("MYSP_REGEXP", "/http:\/\/vids\.myspace\.com\/index\.cfm\?fuseaction=vids\.individual&VideoID=([_A-Za-z0-9-]+)/");
define("MYSP_TARGET", "<object type=\"application/x-shockwave-flash\" style=\"width:".MYSP_WIDTH."px; height:".MYSP_HEIGHT."px;\" 

data=\"http://lads.myspace.com/videos/vplayer.swf?m=###URL###&type=video\"><param name=\"movie\" value=\"http://lads.myspace.com/videos/vplayer.swf?

m=###URL###&type=video\" /></object>");

function mysp_plugin_callback($match)
{
        $output = MYSP_TARGET;
        $output = str_replace("###URL###", strip_tags($match[1]), $output);
        return ($output);
}

function mysp_plugin($content)
{
        return (preg_replace_callback(MYSP_REGEXP, 'mysp_plugin_callback', $content));
}

add_filter('the_content', 'mysp_plugin');
add_filter('comment_text', 'mysp_plugin');

 

You sure it's working? It should work imo but it's still not.

 

Link to comment
Share on other sites

Alright that works now, but now I'm stuck on what code I use to make imeem work :\

 

Original Link: http://www.imeem.com/shibuya7/video/Z1PR33um/ep_1_6_8_gokusen_ep_1_6_8_movies_video/

 

Only part I actually need is Z1PR33um.

 

Anyone got any idea's?

 

I need help with the regular expression it seems :|

 

// IMEEM Code

define("IMEEM_WIDTH", 540);
define("IMEEM_HEIGHT", 438);
define("IMEEM_REGEXP", "/http:\/\/www\.imeem\.com\/thischangesbasedonusername\/video\/([_A-Za-z0-9-]+)/");
define("IMEEM_TARGET", "<object type=\"application/x-shockwave-flash\" style=\"width:".IMEEM_WIDTH."px; height:".IMEEM_HEIGHT."px;\" 

data=\"http://media.imeem.com/v/###URL###/aus=false/pv=2\"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"movie\" 

value=\"http://media.imeem.com/v/###URL###/aus=false/pv=2\" /></object></p>");



function imeem_plugin_callback($match) {
$output = IMEEM_TARGET;
$output = str_replace("###URL###", substr($match[1], 0,10), $output);
return ($output);
}

function imeem_plugin($content) {
return preg_replace_callback(IMEEM_REGEXP, 'imeem_plugin_callback', $content);
}

add_filter('the_content', 'imeem_plugin');
add_filter('comment_text', 'imeem_plugin');

Link to comment
Share on other sites

Anyone? Also the thing I need to find is apparently the Regex for the username area in the url

 

define("IMEEM_REGEXP", "/http:\/\/www\.imeem\.com\/usernamevariable\/video\/([_A-Za-z0-9-]+)/");

 

Anyone know the regular expression used there?

Link to comment
Share on other sites

well i dont know what's the limit on characters is in their username, but I guess we could look for anything that's not whitespace

 

"/http:\/\/www\.imeem\.com\/\S+\/video\/([_A-Za-z0-9-]+)/"

 

if its just numbers and letters and possible a hyphen or underscore then we could do

 

"/http:\/\/www\.imeem\.com\/[A-Za-z0-9-_]+\/video\/([_A-Za-z0-9-]+)/"

Link to comment
Share on other sites

Alright that works now, but now I'm stuck on what code I use to make imeem work :\

 

Original Link: http://www.imeem.com/shibuya7/video/Z1PR33um/ep_1_6_8_gokusen_ep_1_6_8_movies_video/

 

Only part I actually need is Z1PR33um.

 

Anyone got any idea's?

 

I need help with the regular expression it seems :|

 

// IMEEM Code

define("IMEEM_WIDTH", 540);
define("IMEEM_HEIGHT", 438);
define("IMEEM_REGEXP", "/http:\/\/www\.imeem\.com\/thischangesbasedonusername\/video\/([_A-Za-z0-9-]+)/");
define("IMEEM_TARGET", "<object type=\"application/x-shockwave-flash\" style=\"width:".IMEEM_WIDTH."px; height:".IMEEM_HEIGHT."px;\" 

data=\"http://media.imeem.com/v/###URL###/aus=false/pv=2\"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"movie\" 

value=\"http://media.imeem.com/v/###URL###/aus=false/pv=2\" /></object></p>");



function imeem_plugin_callback($match) {
$output = IMEEM_TARGET;
$output = str_replace("###URL###", substr($match[1], 0,10), $output);
return ($output);
}

function imeem_plugin($content) {
return preg_replace_callback(IMEEM_REGEXP, 'imeem_plugin_callback', $content);
}

add_filter('the_content', 'imeem_plugin');
add_filter('comment_text', 'imeem_plugin');

try

<?php
$string = 'http://www.imeem.com/shibuya7/video/Z1PR33um/ep_1_6_8_gokusen_ep_1_6_8_movies_video/';
$string = preg_match('|(?<=/video/)[^/ ]+|i', $string, $match);
print_r($match[0]);
?>

 

Link to comment
Share on other sites

That's odd I just checked and the embed code is actually different from the url.

 

URL: http://www.imeem.com/shibuya7/video/Z1PR33um/ep_1_6_8_gokusen_ep_1_6_8_movies_video/

 

 

EMBED:

<object width="400" height="345"><param name="movie" value="http://media.imeem.com/v/hJBMI5f3yX/aus=false/pv=2"></param><param name="allowFullScreen" value="true"></param><embed src="http://media.imeem.com/v/hJBMI5f3yX/aus=false/pv=2" type="application/x-shockwave-flash" width="400" height="345" allowFullScreen="true"></embed></object>

 

Now I'm totally stuck as there is no hint of the embed code within the url anyone have any idea's on how to get that to replace the url with the embed and work? Thanks for any replies.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.