Skip to content

Conversation

@nekoshippo
Copy link

@nekoshippo nekoshippo commented Oct 5, 2020

When
<a href="//youtu.be/WJ88GhJJI3Q?start=4394" data-lity>Link</a>
is fired, var matches in lity.js is filled as

matches[0]: youtu.be/WJ88GhJJI3Q?start=4394
matches[1]: youtu.be
matches[2]: undefined
matches[3]: undefined
matches[4]: WJ88GhJJI3Q
matches[5]: ?start=4394

and then, lity builds a url below which includes %3F as an urlencoded result of ? in matches[5] so that YouTube does not start the movie at 4394.
https://www.youtube.com/embed/WJ88GhJJI3Q?autoplay=1&%3Fstart=4394

So,
var _youtubeRegex = /(youtube(-nocookie)?\.com|youtu\.be)\/(watch\?v=|v\/|u\/|embed\/?)?([\w-]{11})(.*)?/i;
should be
var _youtubeRegex = /(youtube(-nocookie)?\.com|youtu\.be)\/(watch\?v=|v\/|u\/|embed\/?)?([\w-]{11})\?(.*)?/i;
for the expected behavior.

When 
`<a href="//youtu.be/WJ88GhJJI3Q?start=4394" data-lity>Link</a>`
is fired, var matches in lity.js is filled as
```
matche[0]: youtu.be/WJ88GhJJI3Q?start=4394
matche[1]: youtu.be
matche[2]: undefined
matche[3]: undefined
matche[4]: WJ88GhJJI3Q
matche[5]: ?start=4394
```
and then, lity builds a url below which includes `%3F` as an urlencoded result of `?` in `matche[5]` so that YouTube does not start the movie at 4394.
`https://www.youtube.com/embed/WJ88GhJJI3Q?autoplay=1&%3Fstart=4394`

So, 
`var _youtubeRegex = /(youtube(-nocookie)?\.com|youtu\.be)\/(watch\?v=|v\/|u\/|embed\/?)?([\w-]{11})(.*)?/i;`
should be
`var _youtubeRegex = /(youtube(-nocookie)?\.com|youtu\.be)\/(watch\?v=|v\/|u\/|embed\/?)?([\w-]{11})\?(.*)?/i;`
for the expected behavior.
@nekoshippo nekoshippo changed the title Update youtube.js Fix RegEx pattern for YouTube Oct 6, 2020
@naton
Copy link

naton commented Feb 18, 2022

Hi @nekoshippo, I'm interested in merging this into my "vanilla js" fork at https://github.com/naton/lity but unsure how to proceed. Any suggestions? Rebase this to my master there maybe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants