Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Perl-Sensitive Sunglasses
 
PerlMonks  

Resize video for mobile browser

by htmanning (Scribe)
on Aug 15, 2011 at 01:29 UTC ( #920270=perlquestion: print w/ replies, xml ) Need Help??
htmanning has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to resize the youtube iframe code so that it works in a mobile browser. For example:
<iframe width="560" height="349" src="http://www.youtube.com/embed/8lG +m40pxw" frameborder="0" allowfullscreen></iframe>
I need to set the width to 300 and adjust the height accordingly. Sometimes the width is 560, other times it might be 480, or 600. I was using the following but it no longer applies because Google changed their code around:
$video =~ s! (<iframe [ ]title="YouTube[ ]video[ ]player" [ ]width=")([0-9]+)(" [ ]height=")([0-9]+)(" ) ! $1 . "300" . $3 . ((300/$2)*$4) . $5 !xeg;
The above no longer works. I'm guessing because there is no longer a Title tag in the YouTube URL. Any help would be appreciated. I also need a way to take the iframe code and grab only the URL contained within it. I'm not sure how to accomplish that. Thanks.

Comment on Resize video for mobile browser
Select or Download Code
Re: Resize video for mobile browser
by Anonymous Monk on Aug 15, 2011 at 02:30 UTC

    Any help would be appreciated.

    The sooner you switch to pQuery, HTML::TreeBuilder::LibXML/HTML::TreeBuilder::XPath ... the better off you'll be

    #!/usr/bin/perl -- use strict; use warnings; my $fafafa = <<'__FAFAFA__'; <iframe width="560" height="349" src="http://www.youtube.com/embed/8lG +m40pxw" frameborder="0" allowfullscreen></iframe> __FAFAFA__ print $fafafa; $fafafa =~ s~<iframe([^>]+)>~'<iframe '.Fafafa("$1");~gie; print $fafafa; sub Fafafa { my %kava; my @bool; while( $_[0] =~ m{ \G (?: ( [^'"\s=]+ ) # $1, key \s* = \s* " ( [^"]+)" # $2, val ) | ( [^'"\s=]+ ) # single | \s }gxs ){ no warnings 'uninitialized'; print "1($1)2($2)3($3)\n"; if( $3 ){ push @bool, $3 } elsif( $1 ) { $kava{$1}=$2; } } use DDS; Dump(\%kava); return join ' ', @bool, map { qq'$_="$kava{$_}"' } keys %kava; } __END__
    <iframe width="560" height="349" src="http://www.youtube.com/embed/8lG +m40pxw" frameborder="0" allowfullscreen></iframe> 1()2()3() 1(width)2(560)3() 1()2()3() 1(height)2(349)3() 1()2()3() 1(src)2(http://www.youtube.com/embed/8lGm40pxw)3() 1()2()3() 1(frameborder)2(0)3() 1()2()3() 1()2()3(allowfullscreen) $HASH1 = { frameborder => 0, height => 349, src => 'http://www.youtube.com/embed/8lGm40pxw', width => 560 }; <iframe allowfullscreen width="560" frameborder="0" src="http://www.yo +utube.com/embed/8lGm40pxw" height="349"</iframe>
Re: Resize video for mobile browser
by kcott (Parson) on Aug 15, 2011 at 06:44 UTC

    I note you are matching against attribute="value" throughout and matching a single space between attribute/value pairs. The source HTML could easily contain additional whitespace such as attribute = "value".

    If you're going to do the matching yourself (rather than using one of the tools like those shown above), you need to take this into consideration.

    -- Ken

Re: Resize video for mobile browser
by Mr. Muskrat (Abbot) on Aug 15, 2011 at 17:29 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://920270]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2013-05-22 01:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (453 votes), past polls