add gfycat.com support (fixes #15)

This commit is contained in:
teddit 2021-02-19 20:29:39 +01:00
parent 420df6bd45
commit 12a4de42cf
4 changed files with 19 additions and 20 deletions

View File

@ -38,7 +38,7 @@ const config = {
searches: 600,
sidebar: 60 * 60 * 24 * 7, // 7 days
shorts: 60 * 60 * 24 * 31,
wikis: 60* 60 * 24 * 7,
wikis: 60 * 60 * 24 * 7,
subreddits_explore: {
front: 60 * 60 * 24 * 1,
new_page: 60
@ -51,6 +51,7 @@ const config = {
reddit: true, // old.reddit.com and reddit.com --> instance domain (config.domain)
},
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', '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

@ -35,7 +35,8 @@ module.exports = function(tools) {
if (file_prefix === 'flair_') {
// Flair emojis end in the name without a file extension
file_ext = 'png'
} else if(!pathname.includes('.')) { /**
} else if(!pathname.includes('.')) {
/**
* Sometimes reddit API returns video without extension, like
* "DASH_480" and not "DASH_480.mp4".
*/
@ -57,6 +58,9 @@ module.exports = function(tools) {
resolve('')
} else {
let filename = `${temp_url.pathname.substr(1).split('/')[0]}.${file_ext}`
if(temp_url.hostname === 'thumbs.gfycat.com')
filename = `${temp_url.pathname.substr(1).split('/')[0]}`
let path = `./static/vids/${dir}${filename}`
let temp_path = `./static/vids/${dir}temp_${filename}`
if(!fs.existsSync(path)) {

View File

@ -39,12 +39,17 @@ module.exports = function(fetch) {
user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(post) : '')
}
let validEmbedDomains = ['gfycat.com', 'youtube.com']
let valid_embed_video_domains = ['gfycat.com']
let has_gif = false
let gif_to_mp4 = null
let reddit_video = null
let embed_video = false
if(post.media)
if(valid_embed_video_domains.includes(post.media.type))
embed_video = true
if(post.preview) {
if(post.preview && !embed_video) {
if(post.preview.reddit_video_preview) {
if(post.preview.reddit_video_preview.is_gif) {
has_gif = true

View File

@ -3,28 +3,17 @@ module.exports = function() {
this.processPostMedia = (obj, post, post_media, has_gif, reddit_video, gif_to_mp4) => {
return new Promise(resolve => {
(async () => {
let valid_embed_domains = ['gfycat.com', 'youtube.com']
if(post_media || has_gif) {
if(!has_gif) {
if(valid_embed_domains.includes(post_media.type)) {
if(config.valid_embed_video_domains.includes(post_media.type)) {
if(post_media.type === 'gfycat.com') {
obj.has_media = true
let video_url = post_media.oembed.thumbnail_url
video_url = video_url.replace('size_restricted.gif', 'mobile.mp4')
obj.media = {
source: await downloadAndSave(post_media.oembed.thumbnail_url),
source: await downloadAndSave(video_url),
height: post_media.oembed.thumbnail_height,
width: post_media.oembed.thumbnail_width,
duration: null,
is_gif: null,
not_hosted_in_reddit: true,
embed_src: null
}
try {
let str = post_media.oembed.html
let r = /iframe.*?src=\"(.*?)\"/;
let src = r.exec(str)[1]
obj.media.embed_src = cleanUrl(src)
} catch(error) {
console.error(`Error while trying to get src link from embed html.`, error)
width: post_media.oembed.thumbnail_width
}
}
if(post_media.type === 'youtube.com') {