New provider: yt playlists
This commit is contained in:
parent
b5482fe3c3
commit
73447243a3
@ -5,7 +5,7 @@ require('dotenv').config()
|
|||||||
let config = {
|
let config = {
|
||||||
domain: process.env.DOMAIN || "localhost:3000",
|
domain: process.env.DOMAIN || "localhost:3000",
|
||||||
https: (process.env.SSL === 'true') || false,
|
https: (process.env.SSL === 'true') || false,
|
||||||
recognizeProviders: true,
|
recognizeProviders: (process.env.RECOGNIZE_PROVIDERS === 'true') || true,
|
||||||
getBaseUrl() {
|
getBaseUrl() {
|
||||||
if (config.https) {
|
if (config.https) {
|
||||||
return `https://${config.domain}`;
|
return `https://${config.domain}`;
|
||||||
@ -35,6 +35,10 @@ fastify.get('/a/:id', async (req, res) => {
|
|||||||
fastify.get('/yt/:id', async (req, res) => {
|
fastify.get('/yt/:id', async (req, res) => {
|
||||||
res.redirect(302, `https://youtu.be/${req.params.id}`)
|
res.redirect(302, `https://youtu.be/${req.params.id}`)
|
||||||
})
|
})
|
||||||
|
//Automagic Youtube redirects on /ytpl/
|
||||||
|
fastify.get('/ytpl/:id', async (req, res) => {
|
||||||
|
res.redirect(302, `https://youtube.com/playlist?list=${req.params.id}`)
|
||||||
|
})
|
||||||
|
|
||||||
//Normal shorturls
|
//Normal shorturls
|
||||||
fastify.get('/:shortcode', async (req, res) => {
|
fastify.get('/:shortcode', async (req, res) => {
|
||||||
@ -134,18 +138,27 @@ fastify.post('/new', { newUrlSchema }, async (req, res) => {
|
|||||||
* @returns Standard shortening response if provider recognized or null
|
* @returns Standard shortening response if provider recognized or null
|
||||||
*/
|
*/
|
||||||
function checkKnownProviders(target) {
|
function checkKnownProviders(target) {
|
||||||
if(/^(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$/.test(target)){
|
const youtubeVideoID = target.match(/(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/)
|
||||||
const shortcode = `yt/${target.match(/(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/)[1]}`
|
if (youtubeVideoID) {
|
||||||
|
const shortcode = `yt/${youtubeVideoID[1]}`
|
||||||
return {
|
return {
|
||||||
url: `${config.getBaseUrl()}/${shortcode}`,
|
url: `${config.getBaseUrl()}/${shortcode}`,
|
||||||
shortcode,
|
shortcode,
|
||||||
target
|
target
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const amazonID = target.match(/https?:\/\/(www|smile|)\.?(amazon|smile)\.(com|de)(?:(?:\/.*\/|\/)(?:dp|gp))(\/product\/|\/)([A-Z0-9]+)/)[5];
|
const youtubePlaylistID = target.match(/(?:youtube(?:-nocookie)?\.com\/)playlist\?(?:.*)list=([a-zA-Z0-9_-]*)(?:&.*|)/)
|
||||||
console.log(amazonID)
|
if (youtubePlaylistID) {
|
||||||
|
const shortcode = `ytpl/${youtubePlaylistID[1]}`
|
||||||
|
return {
|
||||||
|
url: `${config.getBaseUrl()}/${shortcode}`,
|
||||||
|
shortcode,
|
||||||
|
target
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const amazonID = target.match(/https?:\/\/(www|smile|)\.?(amazon|smile)\.(de)(?:(?:\/.*\/|\/)(?:dp|gp))(\/product\/|\/)([A-Z0-9]+)/);
|
||||||
if (amazonID) {
|
if (amazonID) {
|
||||||
const shortcode = `a/${amazonID}`
|
const shortcode = `a/${amazonID[5]}`
|
||||||
return {
|
return {
|
||||||
url: `${config.getBaseUrl()}/${shortcode}`,
|
url: `${config.getBaseUrl()}/${shortcode}`,
|
||||||
shortcode,
|
shortcode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user