From bb06fe97633f443fb8f572e54410ada0ee94c6f9 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:58 +0200 Subject: [PATCH] Cleanup --- src/dissectLink.js | 20 +++++++++++------ src/methods/tube.js | 52 ++++++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/dissectLink.js b/src/dissectLink.js index ea46619..80fab2f 100644 --- a/src/dissectLink.js +++ b/src/dissectLink.js @@ -125,15 +125,21 @@ module.exports = function dissectLink(url) { 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)) { - return { - url, - method: 'tube', - label: hostname, - }; + if (match) { + const { hostname } = match; + + if (hostname && fallbacks.has(hostname)) { + return { + url, + method: 'tube', + label: hostname, + }; + } } + console.log(url); + return null; }; diff --git a/src/methods/tube.js b/src/methods/tube.js index 16b3e42..f93f846 100644 --- a/src/methods/tube.js +++ b/src/methods/tube.js @@ -3,31 +3,39 @@ const youtubedl = require('youtube-dl'); const dateFns = require('date-fns'); -async function tube(host) { - const data = await new Promise((resolve, reject) => { - youtubedl.getInfo(host.url, null, (error, info) => { - if (error) { - reject(error); - } +async function tube(host, post) { + try { + const data = await new Promise((resolve, reject) => { + youtubedl.getInfo(host.url, null, (error, info) => { + if (error) { + reject(error); + } - resolve(info); + resolve(info); + }); }); - }); - return { - album: null, - items: [ - { - id: data.id, - url: data.url, - title: data.fulltitle || data.title, - description: data.description, - type: `video/${data.ext}`, - datetime: dateFns.format(data.upload_date, 'YYYYMMDD'), - original: data, - }, - ], - }; + host.id = data.display_id; + + return { + album: null, + items: [ + { + id: data.id, + url: data.url, + title: data.fulltitle || data.title, + description: data.description, + 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;