New provider: yt playlists
This commit is contained in:
parent
b5482fe3c3
commit
73447243a3
|
@ -5,7 +5,7 @@ require('dotenv').config()
|
|||
let config = {
|
||||
domain: process.env.DOMAIN || "localhost:3000",
|
||||
https: (process.env.SSL === 'true') || false,
|
||||
recognizeProviders: true,
|
||||
recognizeProviders: (process.env.RECOGNIZE_PROVIDERS === 'true') || true,
|
||||
getBaseUrl() {
|
||||
if (config.https) {
|
||||
return `https://${config.domain}`;
|
||||
|
@ -35,6 +35,10 @@ fastify.get('/a/:id', async (req, res) => {
|
|||
fastify.get('/yt/:id', async (req, res) => {
|
||||
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
|
||||
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
|
||||
*/
|
||||
function checkKnownProviders(target) {
|
||||
if(/^(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$/.test(target)){
|
||||
const shortcode = `yt/${target.match(/(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/)[1]}`
|
||||
const youtubeVideoID = target.match(/(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/)
|
||||
if (youtubeVideoID) {
|
||||
const shortcode = `yt/${youtubeVideoID[1]}`
|
||||
return {
|
||||
url: `${config.getBaseUrl()}/${shortcode}`,
|
||||
shortcode,
|
||||
target
|
||||
}
|
||||
}
|
||||
const amazonID = target.match(/https?:\/\/(www|smile|)\.?(amazon|smile)\.(com|de)(?:(?:\/.*\/|\/)(?:dp|gp))(\/product\/|\/)([A-Z0-9]+)/)[5];
|
||||
console.log(amazonID)
|
||||
const youtubePlaylistID = target.match(/(?:youtube(?:-nocookie)?\.com\/)playlist\?(?:.*)list=([a-zA-Z0-9_-]*)(?:&.*|)/)
|
||||
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) {
|
||||
const shortcode = `a/${amazonID}`
|
||||
const shortcode = `a/${amazonID[5]}`
|
||||
return {
|
||||
url: `${config.getBaseUrl()}/${shortcode}`,
|
||||
shortcode,
|
||||
|
|
Loading…
Reference in New Issue