This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:58 +02:00
parent 58a35fe998
commit bb06fe9763
2 changed files with 43 additions and 29 deletions

View File

@ -125,15 +125,21 @@ module.exports = function dissectLink(url) {
return hostMethod; return hostMethod;
} }
const { hostname } = new UrlPattern('http(s)\\://(www.):hostname(*)').match(url); const match = new UrlPattern('http(s)\\://(www.):hostname(*)').match(url);
if (hostname && fallbacks.has(hostname)) { if (match) {
return { const { hostname } = match;
url,
method: 'tube', if (hostname && fallbacks.has(hostname)) {
label: hostname, return {
}; url,
method: 'tube',
label: hostname,
};
}
} }
console.log(url);
return null; return null;
}; };

View File

@ -3,31 +3,39 @@
const youtubedl = require('youtube-dl'); const youtubedl = require('youtube-dl');
const dateFns = require('date-fns'); const dateFns = require('date-fns');
async function tube(host) { async function tube(host, post) {
const data = await new Promise((resolve, reject) => { try {
youtubedl.getInfo(host.url, null, (error, info) => { const data = await new Promise((resolve, reject) => {
if (error) { youtubedl.getInfo(host.url, null, (error, info) => {
reject(error); if (error) {
} reject(error);
}
resolve(info); resolve(info);
});
}); });
});
return { host.id = data.display_id;
album: null,
items: [ return {
{ album: null,
id: data.id, items: [
url: data.url, {
title: data.fulltitle || data.title, id: data.id,
description: data.description, url: data.url,
type: `video/${data.ext}`, title: data.fulltitle || data.title,
datetime: dateFns.format(data.upload_date, 'YYYYMMDD'), description: data.description,
original: data, type: `video/${data.ext}`,
}, datetime: dateFns.format(data.upload_date, 'YYYYMMDD'),
], original: data,
}; },
],
};
} catch (error) {
console.log('\x1b[33m%s\x1b[0m', `Ignoring possible profile page '${host.url}' (${post ? post.permalink : 'no post'})`);
return null;
}
} }
module.exports = tube; module.exports = tube;