39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
const util = require('util');
|
||
|
const config = require('config');
|
||
|
const fetch = require('node-fetch');
|
||
|
const fs = require('fs-extra');
|
||
|
|
||
|
function redditVideo(post) {
|
||
|
return fetch(`${post.permalink}.json`).then(res => res.json()).then(res => {
|
||
|
return res[0].data.children[0].data.media.reddit_video.fallback_url;
|
||
|
}).then(videoUrl => {
|
||
|
const audioUrl = videoUrl.split('/').slice(0, -1).join('/') + '/audio';
|
||
|
|
||
|
return fetch(audioUrl, {
|
||
|
method: 'HEAD'
|
||
|
}).then(res => {
|
||
|
const item = {
|
||
|
album: null,
|
||
|
items: [{
|
||
|
id: post.host.id || post.id,
|
||
|
url: videoUrl,
|
||
|
title: post.title,
|
||
|
datetime: post.datetime,
|
||
|
type: 'video/mp4',
|
||
|
original: post
|
||
|
}]
|
||
|
};
|
||
|
|
||
|
if(res.status === 200) {
|
||
|
item.items[0].mux = [audioUrl];
|
||
|
}
|
||
|
|
||
|
return item;
|
||
|
});
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports = redditVideo;
|