From 2e9d276d3d5133e65a3f23a44e7e915f175547c1 Mon Sep 17 00:00:00 2001 From: Lee Aylward Date: Sun, 15 Jan 2012 12:14:44 -0600 Subject: [PATCH] add autoplay option for youtube embeds --- lib/Noembed/Source/YouTube.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Noembed/Source/YouTube.pm b/lib/Noembed/Source/YouTube.pm index 2b5667b..bea5da0 100644 --- a/lib/Noembed/Source/YouTube.pm +++ b/lib/Noembed/Source/YouTube.pm @@ -34,7 +34,8 @@ sub serialize { my ($self, $body, $req) = @_; my $data = from_json $body; - my ($url) = $data->{html} =~ m{src="([^"]+)"}; + my ($src) = $data->{html} =~ m{src="([^"]+)"}; + my $uri = URI->new($src); # tack on start parameter if timecode was in original URL if (my @t = $req->url =~ /[#\?]a?t=(?:(\d+)m)?(\d+)s/) { @@ -42,10 +43,14 @@ sub serialize { if (@t) { $seconds += $t[0] * 60; } - $url .= "&start=$seconds"; + $uri->query_param(start => $seconds); } - $data->{html} = $self->render($data, $url); + if (my $autoplay = $req->param("autoplay")) { + $uri->query_param(autoplay => 1); + } + + $data->{html} = $self->render($data, $uri->as_string); return $data; }