'use strict'; const fetch = require('node-fetch'); async function redditVideo(host, post) { const res = await fetch(`${post.permalink}.json`); const [{ data }] = await res.json(); const videoUrl = data.children[0].data.media.reddit_video.fallback_url; const audioUrl = `${videoUrl.split('/').slice(0, -1).join('/')}/audio`; const audioRes = await fetch(audioUrl, { method: 'HEAD', }); 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 (audioRes.status === 200) { item.items[0].mux = [audioUrl]; } return item; } module.exports = redditVideo;