pspcrazy Posted June 13, 2008 Share Posted June 13, 2008 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'); Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted June 13, 2008 Share Posted June 13, 2008 what are you asking? I don't see a question. Quote Link to comment Share on other sites More sharing options...
pspcrazy Posted June 13, 2008 Author Share Posted June 13, 2008 Well the myspace part of the embed code doesn't work, and i've tried to debug it with no luck. I'm wondering if someone can notice something i haven't or potentially know a better way to do the replacement. Quote Link to comment Share on other sites More sharing options...
hansford Posted June 13, 2008 Share Posted June 13, 2008 I got this to work. the problem is with [[:print:]]+ it grabs everything after the video id including ></a>. $pattern = "/http:\/\/vids\.myspace\.com\/index\.cfm\?fuseaction=vids\.individual&VideoID=([_A-Za-z0-9-]+)/"; Quote Link to comment Share on other sites More sharing options...
pspcrazy Posted June 13, 2008 Author Share Posted June 13, 2008 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. Quote Link to comment Share on other sites More sharing options...
hansford Posted June 13, 2008 Share Posted June 13, 2008 I tested it. <? $str = "<a href='http://vids.myspace.com/index.cfm?fuseaction=vids.individual&VideoID=35839229'>video</a>"; $pattern = "/http:\/\/vids\.myspace\.com\/index\.cfm\?fuseaction=vids\.individual&VideoID=([_A-Za-z0-9?-]+)/"; $chk = preg_match($pattern, $str,$matches); if($chk){ echo $matches[0]; } ?> Quote Link to comment Share on other sites More sharing options...
pspcrazy Posted June 13, 2008 Author Share Posted June 13, 2008 It should work, that I know. It works fine with veoh, and all the others as well but oddly it still doesn't work lol. I wonder why... Quote Link to comment Share on other sites More sharing options...
pspcrazy Posted June 13, 2008 Author Share Posted June 13, 2008 I debugged it down to the &. When I use & instead it starts to work.. hopefully that fixes it.. Quote Link to comment Share on other sites More sharing options...
pspcrazy Posted June 13, 2008 Author Share Posted June 13, 2008 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'); Quote Link to comment Share on other sites More sharing options...
pspcrazy Posted June 13, 2008 Author Share Posted June 13, 2008 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? Quote Link to comment Share on other sites More sharing options...
pspcrazy Posted June 14, 2008 Author Share Posted June 14, 2008 Anyone? Quote Link to comment Share on other sites More sharing options...
hansford Posted June 14, 2008 Share Posted June 14, 2008 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-]+)/" Quote Link to comment Share on other sites More sharing options...
sasa Posted June 15, 2008 Share Posted June 15, 2008 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]); ?> Quote Link to comment Share on other sites More sharing options...
pspcrazy Posted June 15, 2008 Author Share Posted June 15, 2008 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. Quote Link to comment Share on other sites More sharing options...
pspcrazy Posted June 15, 2008 Author Share Posted June 15, 2008 Also sasa I don't want it to just convert 1 link, I want any imeem video link to convert to it's own embed code. I believe it required lookup's rather then regular expressions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.