* 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 {}
|
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) {
|
export function parseEmbedUrl (href) {
|
||||||
if (!href) return null
|
if (!href) return null
|
||||||
|
|
||||||
@ -132,7 +143,7 @@ export function parseEmbedUrl (href) {
|
|||||||
id: searchParams.get('v'),
|
id: searchParams.get('v'),
|
||||||
meta: {
|
meta: {
|
||||||
href,
|
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
|
id: pathname.slice(1), // remove leading slash
|
||||||
meta: {
|
meta: {
|
||||||
href,
|
href,
|
||||||
start: searchParams.get('t')
|
start: parseYoutubeStart(searchParams.get('t'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user