Skip to content

Commit

Permalink
add autoplay option for youtube embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
leedo committed Jan 15, 2012
1 parent 5aabebe commit 2e9d276
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Noembed/Source/YouTube.pm
Expand Up @@ -34,18 +34,23 @@ 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/) {
my $seconds = pop @t;
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;
}

Expand Down

0 comments on commit 2e9d276

Please sign in to comment.