* fix #2443: add parseYoutubeStart() to convert start times * handle null parameter * add spaces for lint * switch to regex, handles more cases, simply don't touch unexpected input * force braces for lint
This commit is contained in:
parent
cbcb8cb96c
commit
acd5b69087
15
lib/url.js
15
lib/url.js
@ -78,6 +78,17 @@ export function parseInternalLinks (href) {
|
||||
return {}
|
||||
}
|
||||
|
||||
export function parseYoutubeStart (t) {
|
||||
// https://stackoverflow.com/questions/17379268/youtube-dropped-t-start-time-support-in-direct-url-and-embed-videos
|
||||
// https://developers.google.com/youtube/player_parameters#start
|
||||
if (!t || !t.match(/^([0-9]+[smh])+$/g)) return t
|
||||
let r = 0
|
||||
for (const m of t.matchAll(/([0-9]+)([smh])/g)) {
|
||||
r += parseInt(m[1]) * Math.pow(60, 'smh'.indexOf(m[2]))
|
||||
}
|
||||
return r.toString()
|
||||
}
|
||||
|
||||
export function parseEmbedUrl (href) {
|
||||
if (!href) return null
|
||||
|
||||
@ -132,7 +143,7 @@ export function parseEmbedUrl (href) {
|
||||
id: searchParams.get('v'),
|
||||
meta: {
|
||||
href,
|
||||
start: searchParams.get('t')
|
||||
start: parseYoutubeStart(searchParams.get('t'))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -152,7 +163,7 @@ export function parseEmbedUrl (href) {
|
||||
id: pathname.slice(1), // remove leading slash
|
||||
meta: {
|
||||
href,
|
||||
start: searchParams.get('t')
|
||||
start: parseYoutubeStart(searchParams.get('t'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user