reduce blocking domain to 1 hour
This commit is contained in:
@ -15,7 +15,7 @@ export const getYoutubePlaylistId = (url: string) => {
|
||||
return u.searchParams.get('list')
|
||||
}
|
||||
|
||||
const getEmbedData = (url: string) => {
|
||||
export const getEmbedData = (url: string) => {
|
||||
const BaseUrl = 'https://www.youtube.com'
|
||||
const embedBaseUrl = 'https://www.youtube.com/embed'
|
||||
|
||||
@ -25,17 +25,17 @@ const getEmbedData = (url: string) => {
|
||||
throw new Error(`Invalid youtube url: ${url}`)
|
||||
}
|
||||
|
||||
const type = match[4]
|
||||
const id = match[5]
|
||||
|
||||
if (type === '/playlist?list=') {
|
||||
const playlistId = getYoutubePlaylistId(url) || id
|
||||
|
||||
const playlistId = getYoutubePlaylistId(url)
|
||||
if (playlistId) {
|
||||
return {
|
||||
src: `${embedBaseUrl}/videoseries?list=${playlistId}`,
|
||||
url: `${BaseUrl}/playlist?list=${playlistId}`,
|
||||
}
|
||||
} else if (type === '/shorts/') {
|
||||
}
|
||||
|
||||
const type = match[4]
|
||||
const id = match[5]
|
||||
if (type === '/shorts/') {
|
||||
return {
|
||||
src: `${embedBaseUrl}/${id}`,
|
||||
url: `${BaseUrl}/shorts/${id}`,
|
||||
@ -43,7 +43,6 @@ const getEmbedData = (url: string) => {
|
||||
}
|
||||
|
||||
const videoId = getYoutubeVideoId(url) || id
|
||||
|
||||
return {
|
||||
src: `${embedBaseUrl}/${videoId}`,
|
||||
url: `${BaseUrl}/watch?v=${videoId}`,
|
||||
|
||||
@ -1,6 +1,21 @@
|
||||
import { expect } from "chai";
|
||||
import "mocha";
|
||||
import { escapeTitle, getYoutubePlaylistId, getYoutubeVideoId } from "../src/websites/youtube-handler";
|
||||
import {
|
||||
escapeTitle,
|
||||
getEmbedData,
|
||||
getYoutubePlaylistId,
|
||||
getYoutubeVideoId,
|
||||
} from '../src/websites/youtube-handler'
|
||||
|
||||
describe('getEmbedData', () => {
|
||||
expect('https://www.youtube.com/embed/vFD2gu007dc').to.eq(
|
||||
getEmbedData('https://youtu.be/vFD2gu007dc').src
|
||||
)
|
||||
|
||||
expect('https://www.youtube.com/embed/cg9b4RC87LI').to.eq(
|
||||
getEmbedData('https://youtu.be/cg9b4RC87LI?t=116').src
|
||||
)
|
||||
})
|
||||
|
||||
describe('getYoutubeVideoId', () => {
|
||||
it('should parse video id out of a URL', async () => {
|
||||
@ -12,15 +27,9 @@ describe('getYoutubeVideoId', () => {
|
||||
'https://www.youtube.com/watch?v=vFD2gu007dc&list=RDvFD2gu007dc&start_radio=1'
|
||||
)
|
||||
)
|
||||
expect('vFD2gu007dc').to.eq(
|
||||
getYoutubeVideoId('https://youtu.be/vFD2gu007dc')
|
||||
)
|
||||
expect('BMFVCnbRaV4').to.eq(
|
||||
getYoutubeVideoId('https://youtube.com/watch?v=BMFVCnbRaV4&feature=share')
|
||||
)
|
||||
expect('cg9b4RC87LI').to.eq(
|
||||
getYoutubeVideoId('https://youtu.be/cg9b4RC87LI?t=116')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user