Better support for go to url
This commit is contained in:
parent
8d3a31676f
commit
cb2359f8b5
|
@ -53,18 +53,37 @@ const actions = {
|
||||||
return state.colorClasses[randomInt]
|
return state.colorClasses[randomInt]
|
||||||
},
|
},
|
||||||
|
|
||||||
getVideoIdFromUrl ({ state }, url) {
|
getVideoIdFromUrl (_, url) {
|
||||||
console.log('checking for id')
|
/** @type {URL} */
|
||||||
console.log(url)
|
let urlObject
|
||||||
const rx = /^.*(?:(?:(you|hook)tu\.?be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|&v(?:i)?=))([^#&?]*).*/
|
try {
|
||||||
|
urlObject = new URL(url)
|
||||||
const match = url.match(rx)
|
} catch (e) {
|
||||||
|
|
||||||
if (match) {
|
|
||||||
return match[2]
|
|
||||||
} else {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const extractors = [
|
||||||
|
// anything with /watch?v=
|
||||||
|
function() {
|
||||||
|
if (urlObject.pathname === "/watch" && urlObject.searchParams.has("v")) {
|
||||||
|
return urlObject.searchParams.get("v")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// youtu.be
|
||||||
|
function() {
|
||||||
|
if (urlObject.host === "youtu.be" && urlObject.pathname.match(/^\/[A-Za-z0-9_-]+$/)) {
|
||||||
|
return urlObject.pathname.slice(1)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// cloudtube
|
||||||
|
function() {
|
||||||
|
if (urlObject.host.match(/^cadence\.(gq|moe)$/) && urlObject.pathname.match(/^\/cloudtube\/video\/[A-Za-z0-9_-]+$/)) {
|
||||||
|
return urlObject.pathname.slice("/cloudtube/video/".length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return extractors.reduce((a, c) => a || c(), null) || false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue