mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Fix parsing video IDs from youtube URLs
This commit is contained in:
parent
bd2c4724ae
commit
31eb1a0f61
1 changed files with 11 additions and 8 deletions
|
|
@ -9,13 +9,7 @@ const axios = require('axios');
|
|||
const YOUTUBE_URL_MATCH =
|
||||
/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/
|
||||
|
||||
exports.youtubeHandler = {
|
||||
|
||||
shouldPrehandle: (url, env) => {
|
||||
return YOUTUBE_URL_MATCH.test(url.toString())
|
||||
},
|
||||
|
||||
getVideoId: (url) => {
|
||||
function getYoutubeVideoId(url) {
|
||||
const u = new URL(url);
|
||||
const videoId = u.searchParams['v']
|
||||
if (!videoId) {
|
||||
|
|
@ -26,10 +20,19 @@ exports.youtubeHandler = {
|
|||
return match[5]
|
||||
}
|
||||
return videoId
|
||||
}
|
||||
exports.getYoutubeVideoId = getYoutubeVideoId
|
||||
|
||||
exports.youtubeHandler = {
|
||||
|
||||
shouldPrehandle: (url, env) => {
|
||||
return YOUTUBE_URL_MATCH.test(url.toString())
|
||||
},
|
||||
|
||||
|
||||
|
||||
prehandle: async (url, env) => {
|
||||
const videoId = getVideoId(url)
|
||||
const videoId = getYoutubeVideoId(url)
|
||||
if (!videoId) {
|
||||
return {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue