42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const youtubedl = require('youtube-dl');
|
|
const dateFns = require('date-fns');
|
|
|
|
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);
|
|
});
|
|
});
|
|
|
|
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;
|