Ah gotcha. I was thinking about the mismatch possibly causing issues in
case, e.g., there are two src strings, and the if matches one, and the
parsing of the video ID matches the other.

As an aside, we don't need this now, but if things get tricky, we should
probably use the URI module (see cgi-bin/DW/Hooks/EmbedWhitelist.pm for an
example)


On Tue, Apr 23, 2013 at 12:28 PM, Deborah Kaplan
<notifications@github.com>wrote:

> In cgi-bin/LJ/EmbedModule.pm:
>
> > @@ -257,6 +267,101 @@ sub _extract_num_unit {
> >      return ( $num, "%" );
> >  }
> >
> > +# extract src info if useful
> > +# returns a hash of link text, url
> > +# currently handles: YouTube, Vimeo
> > +sub extract_src_info {
> > +    my ($class, $content) = @_;
> > +    my ($url, $site, $href, $linktext);
> > +
> > +    if ( $content =~ /src="http:\/\/.*youtube\.com/ ) {
> > +        # YouTube
> > +
> > +        my $host = "https://www.youtube.com/";
> > +        my $prefix = "watch?v=";
> > +
> > +        # get the video ID
> > +        $content =~ /.*src="[^"]*embed\/([^"]*)".*/;
>
> So this was a little handwavy, because the url styles can change at any
> time. But the idea was if it's a youtube embed, your regexp has already
> selected for that, so now we're just selecting for the video string in the
> attribute of the style src="http://www.youtube.com/embed/MfstYSUscBc"
>
> I could put it there, too -- would make the regexp slightly more
> efficient. My thought proces was that if YT changed the embed address (say,
> to embed.youtu.be, for example) that would leave us fewer places to
> change the string. I'm not married to either way.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/dreamwidth/dw-free/pull/338/files#r3909550>
> .
>