CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Help with shockwave-flash parser

 



woompy
New User

Nov 5, 2006, 4:12 AM

Post #1 of 1 (2964 views)
Help with shockwave-flash parser Can't Post

Iím no that good with regexp so I really need the help of someone who is.
Iím trying to write a parser to parse the shockwave-flash embedded video code from sites like Google video, Yahoo, Youtube, Bolt and others.
It needs to be parsed into a query string which is passed to a script which opens the players in a separate window. An example of how it will work with some pre parsed query strings can be found here - http://gigginonline.com/playvids.html
The receiving script also uses swfobject.js - the docs can be found here - http://blog.deconcept.com/swfobject/ which gets by the activex warnings.
The idea is that the parser can be added to the text parser of forums and blogs so users can add play lists.

This is what I have so far.

Code
#!/usr/bin/perl 

use CGI qw(:standard);
use Strict;

print header();

# src='http://www.bolt.com/video/flv_player_branded.swf?contentId=1952754&contentType=2' # src from bolt code

$text = qq([video](title)This is video 1 - BOLT CODE - (/title)<embed loop='false' quality='high' bgcolor='white' width='365' height='340' name='video_play_500' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /><br/><a href='http://www.bolt.com/'>Get video codes</a> at <a style='font-family:arial,sans-serif;font-size:12px;color:#0066CC' href='http://www.bolt.com'>Bolt</a>[/video]
[video](title)This is video 2 - YOUTUBE CODE - (/title)<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/topeBoB-ApQ"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/topeBoB-ApQ" type="application/x-shockwave-flash" wmode="transparent" height="350" width="425"></embed></object>[/video]
[video](title)This is video 3 - YAHOO CODE - (/title)<embed src='http://us.i1.yimg.com/cosmos.bcst.yahoo.com/player/media/swf/FLVVideoSolo.swf' flashvars='id=970784&emailUrl=http%3A%2F%2Fvideo.yahoo.com%2Futil%2Fmail%3Fei%3DUTF-8%26vid%3De2e02ad6d9d1646cfa12ec8f270ae1ad.970784%26cache%3D1&imUrl=http%25253A%25252F%25252Fvideo.yahoo.com%25252Fvideo%25252Fplay%25253F%252526ei%25253DUTF-8%252526vid%25253De2e02ad6d9d1646cfa12ec8f270ae1ad.970784%252526cache%25253D1&imTitle=Nobody%252527s%252BWatching%252BOK%252BGo&searchUrl=http://video.yahoo.com/video/search?p=&profileUrl=http://video.yahoo.com/video/profile?yid=&creatorValue=bm9ib2R5c3dhdGNoaW5ndHY%3D&vid=e2e02ad6d9d1646cfa12ec8f270ae1ad.970784' type='application/x-shockwave-flash' width='425' height='350'></embed>[/video]
[video](title)This is video 4 - AOL CODE - (/title)<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="415" height="347" id="browser" style="padding:0;margin:0"><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><param name="movie" value="http://uncutvideo.aol.com/v.06/uc_videoplayer.swf" /><param name="FlashVars" value="assetURL=http://pdl.stream.aol.com/aol/us/cvn/2006/9/7/38f518e743bb78738c25dd2c7ed1325c_dl.flv&duration=37&showExpandButton=false&expandFunctionID=expandVideo&assetID=38f518e743bb78738c25dd2c7ed1325c&wmurl=http://uncutvideo.aol.com/&pol=true&mvvis=true&mvurl=http://uncutvideo.aol.com/"/><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /><embed src="http://uncutvideo.aol.com/v.06/uc_videoplayer.swf" quality="high" bgcolor="#cccccc" wmode="transparent" FlashVars="assetURL=http://pdl.stream.aol.com/aol/us/cvn/2006/9/7/38f518e743bb78738c25dd2c7ed1325c_dl.flv&duration=37&showExpandButton=false&expandFunctionID=expandVideo&assetID=38f518e743bb78738c25dd2c7ed1325c&wmurl=http://uncutvideo.aol.com/&pol=true&mvvis=true&mvurl=http://uncutvideo.aol.com/" width="415" height="347" name="browser" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>[/video]);

#my ($fvars,$title,$video_data,$querystring,$width,$height,$src);

while ($text =~ s{\[video\](.+?)\[\/video\]} {

($src,$fvars,$type,$width,$height) = ();

$vdata = $1;
$vdata =~ m!\(title\)(.+?)\(\/title\)!is;
$title = $1;
$vdata =~ s!("|'|#)!!isg;
$vdata =~ m!\<embed (.+?)(\>|\/\>)!is;
$video_data = $1;

$video_data =~ s!("|'|#)!!isg; #clean it up

if ($video_data =~ m|type=application\/x\-shockwave\-flash|i) {
$type = "ok";
$video_data =~ s|type=application\/x\-shockwave\-flash||ig; # remove the Type
}

$video_data =~ m|width\s*=\s*([^ ]+)|i;
$width = "$1";

$video_data =~ m|height\s*=\s*([^ ]+)|i;
$height = "$1";

$video_data =~ m|src\s*=\s*([^ ]+)|i;
$src = "$1";

print "this is width of - $title $width\n";
print "this is height of - $title $height\n";
print "this is src of - $title $src \n";


if ($type&&$src&&$width&&$height) {

$video_data =~ s/^\s+//; #remove leading spaces
$video_data =~ s/\s+$//; #remove trailing spaces
$video_data =~ s/\s+/ /g; #remove excess white spaces

if ($video_data =~ m|flashvars\s*=\s*([^ ]+)|i) { #match and save
$fvars = "$1";
$video_data =~ s|flashvars\s*=\s*([^ ]+)||i; #delete flashvars from string
#print "this is flashvars $fvars\n";
}

@values = split(' ',$video_data);
$querystring = join('&', @values);

if ($fvars) {
$querystring .= "&" . $fvars;
}

#print "this is the query string - $querystring\n\n";
qq#<!--videocode-->QUERTSTRING,TITLE,WIDTH and HEIGHT - ($title) $querystring (width - $width) (height - $height)videocode-->#;
} else {
qq#<--videocode-->PROBLEM WITH VIDEO CODE TITLED - $title<--videocode-->#;
}

}
}eisg) {}

print "$text";


Iím having a few problems with this, the first is that my error checking doesn't work.
Iíve left the SRC out of the Bolt code to show you what its doing, or not doing.
Second thing is I need to clean up and combine some of the back referencing if possible.
Iím also having a problem with the Google code but I need to get what I have working before I can work on that.
Can someone please help.

Thanks
Bob

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives