mirror of
https://codeberg.org/teddit/teddit.git
synced 2026-04-18 21:45:06 -04:00
add gfycat.com support (fixes #15)
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
|
||||
+5
-16
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user