Rewrite i.imgur.com gifv to mp4

* Configurable env var VALID_MEDIA_DOMAINS
This commit is contained in:
3nprob 2021-10-07 16:59:52 +09:00
parent 660e5681be
commit 56a2f6b266
2 changed files with 8 additions and 3 deletions

View File

@ -70,7 +70,9 @@ const config = {
initial_limit: 100, // This is the amount of page loads one IP address can make in one minute without getting limited.
limit_after_limited: 30 // When an IP is limited, this is the amount of page loads the IP can make in one minute.
},
valid_media_domains: ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'emoji.redditmedia.com', 'styles.redditmedia.com', 'www.redditstatic.com', 'thumbs.gfycat.com', 'i.ytimg.com'],
valid_media_domains: process.env.VALID_MEDIA_DOMAINS
? JSON.parse(process.env.VALID_MEDIA_DOMAINS)
: ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'emoji.redditmedia.com', 'styles.redditmedia.com', 'www.redditstatic.com', 'thumbs.gfycat.com', 'i.ytimg.com'],
valid_embed_video_domains: ['gfycat.com', 'youtube.com'],
reddit_api_error_text: `Seems like your instance is either blocked (e.g. due to API rate limiting), reddit is currently down, or your API key is expired and not renewd properly. This can also happen for other reasons.`
};

View File

@ -93,9 +93,12 @@ module.exports = function() {
if(!gif_to_mp4) {
if(post.preview) {
if(post.preview.reddit_video_preview) {
if(post.preview.reddit_video_preview.fallback_url) {
const url = post.domain === 'i.imgur.com'
? replaceDomains(post.url_overridden_by_dest.replace(/\.gifv$/, '.mp4'))
: post.preview.reddit_video_preview.fallback_url;
if(url) {
obj.media = {
source: await downloadAndSave(post.preview.reddit_video_preview.fallback_url),
source: await downloadAndSave(url),
height: post.preview.reddit_video_preview.height,
width: post.preview.reddit_video_preview.width,
duration: post.preview.reddit_video_preview.duration,