Wednesday, February 6, 2008

I'll show you a broken pipe!

So after hours and hours of trying to get the embeded YouTube videos to make their tags change to a link I finally got it done. At first I tried some long regular expressions to see if it actually works by saying something like: ExtFilterDefine start-a1 mode=output intype=text/html cmd="/bin/sed s/<object width=\"425\" height=\"355\"><param name=\"movie\" value=\"/<a href=\"/g" but this didn't work out too well as I found out after some trial and error and some searching for the meaning of (32)Broken pipe: apr_file_write(child input), len 0
(32)Broken pipe: ef_unified_filter() failed I found out that Apache didn't like < as well as > as well as spaces so I escaped them and all was fine. So that got rid of the problem for a while, but then I would get more broken pipes. Turns out Apache doesn't like / as well...this is something that cannot be escaped apparently.


Somewhere between all that I decided to test it out using just sed from the command-line. I have to say that much of the frustration arose because a trimmed down regex I used worked in sed but not in the Apache config. At this time I matched the url to keep resulting in a new regex. So the next thing I did was take this into the Apache config I had. Besides it not liking the /, it also didn't like the \1 for the string that I matched to keep.

So then I split the regex eventually trying to do two output filters, then I realized that Apache does not do that, it only does one. So, I had to think of another way of doing things. This would lead to a nice little perl script that did all the magic I needed to be done...and this only took me five minutes to put together.

#!/usr/bin/perl

while () {
s#<object.*("http://www.youtube.com/.*").*type="app.*</object>#<a href=\1>Watch Video</a>#iog;
print;
}
exit 1;


The regex could use a little more work, but so far it looks like it works out, replacing an embeded YouTube video with a link directly to the video. I don't have the iTouch now so I don't know if the direct link to the video works at bringing up the YouTube application on the iTouch/iPhone because of the url difference http://www.youtube.com/v/* as opposed to http://youtube.com/watch?v=* however this can be changed in a few minutes.

The proxy server is set up at datel.no-ip.org, however only few places have access to the proxy, namely LAN and probably Keck (if I set it up correctly). A sample page with embeded YouTube is here.

No comments: