ripunzel/src/methods/tube.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-07-07 23:08:20 +00:00
'use strict';
const youtubedl = require('youtube-dl');
const dateFns = require('date-fns');
2018-07-07 23:08:20 +00:00
const logger = require('../logger')(__filename);
2019-12-22 02:20:24 +00:00
async function tube(host, post) {
try {
const data = await new Promise((resolve, reject) => {
youtubedl.getInfo(host.url, null, (error, info) => {
if (error) {
reject(error);
}
2018-07-07 23:08:20 +00:00
2019-12-22 02:20:24 +00:00
resolve(info);
});
});
2018-07-07 23:08:20 +00:00
host.id = data.display_id; // eslint-disable-line no-param-reassign
2019-12-22 02:20:24 +00:00
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) {
logger.warn(`Ignoring possible image or profile page '${host.url}' (${post ? post.permalink : 'no post'})`);
2019-12-22 02:20:24 +00:00
return null;
}
2018-07-07 23:08:20 +00:00
}
module.exports = tube;