Moved source into dedicated directory.
This commit is contained in:
44
src/methods/eroshare.js
Normal file
44
src/methods/eroshare.js
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const config = require('config');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
function eroshare(post) {
|
||||
return fetch(`https://web.archive.org/web/20170630040157im_/https://eroshare.com/${post.host.id}`).then(res => {
|
||||
if(res.ok) {
|
||||
return res.text()
|
||||
}
|
||||
|
||||
return Promise.reject(`Unable to recover Eroshare video '${post.host.id}' :(`);
|
||||
}).then(res => {
|
||||
const data = JSON.parse(res.match(/var album = .*/)[0].slice(12, -1));
|
||||
const extract = config.patterns.album.extractSingleItem && data.items.length === 1;
|
||||
|
||||
return {
|
||||
album: extract ? null : {
|
||||
id: data.slug,
|
||||
title: data.title,
|
||||
datetime: new Date(data.created_at)
|
||||
},
|
||||
items: data.items.map(item => {
|
||||
return {
|
||||
extracted: extract,
|
||||
id: item.slug,
|
||||
url: item.type === 'Image' ? item.url_full_protocol : item.url_mp4,
|
||||
title: data.title,
|
||||
description: item.description,
|
||||
type: item.type === 'Image' ? 'image/jpeg' : 'video/mp4',
|
||||
datetime: new Date(data.created_at),
|
||||
width: data.width,
|
||||
height: data.height,
|
||||
original: item
|
||||
};
|
||||
})
|
||||
};
|
||||
}).catch(error => {
|
||||
console.log('\x1b[33m%s\x1b[0m', error);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = eroshare;
|
||||
26
src/methods/gfycat.js
Normal file
26
src/methods/gfycat.js
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const config = require('config');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
function gfycat(post) {
|
||||
return fetch(`https://gfycat.com/cajax/get/${post.host.id}`).then(res => res.json()).then(res => {
|
||||
return {
|
||||
album: null,
|
||||
items: [{
|
||||
id: res.gfyItem.gfyName,
|
||||
url: res.gfyItem.webmUrl,
|
||||
title: res.gfyItem.title,
|
||||
description: res.gfyItem.description,
|
||||
type: 'video/webm',
|
||||
datetime: new Date(res.gfyItem.createDate * 1000),
|
||||
original: res.gfyItem
|
||||
}]
|
||||
};
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = gfycat;
|
||||
44
src/methods/imgurAlbum.js
Normal file
44
src/methods/imgurAlbum.js
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const config = require('config');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
function imgurAlbum(post) {
|
||||
return fetch(`https://api.imgur.com/3/album/${post.host.id}`, {
|
||||
headers: {
|
||||
'Authorization': `Client-ID ${config.methods.imgur.clientId}`
|
||||
}
|
||||
}).then(res => res.json()).then(res => {
|
||||
const extract = config.library.album.extractSingleItem && res.data.images.length === 1;
|
||||
|
||||
if(extract) {
|
||||
console.log('\x1b[36m%s\x1b[0m', `Extracting single item from album '${post.title}' - ${res.data.link}`);
|
||||
}
|
||||
|
||||
return {
|
||||
album: extract ? null : {
|
||||
id: res.data.id,
|
||||
url: res.data.link,
|
||||
title: res.data.title,
|
||||
description: res.data.description,
|
||||
datetime: new Date(res.data.datetime * 1000),
|
||||
original: res.data
|
||||
},
|
||||
items: res.data.images.map(item => ({
|
||||
extracted: extract,
|
||||
id: item.id,
|
||||
url: item.animated ? item.mp4 : item.link,
|
||||
title: item.title || (extract ? res.data.title : null),
|
||||
description: item.description || (extract ? res.data.description : null),
|
||||
type: item.animated ? 'video/mp4' : item.type,
|
||||
datetime: item.datetime * 1000,
|
||||
original: item
|
||||
}))
|
||||
};
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = imgurAlbum;
|
||||
30
src/methods/imgurImage.js
Normal file
30
src/methods/imgurImage.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const config = require('config');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
function imgurImage(post) {
|
||||
return fetch(`https://api.imgur.com/3/image/${post.host.id}`, {
|
||||
headers: {
|
||||
'Authorization': `Client-ID ${config.methods.imgur.clientId}`
|
||||
}
|
||||
}).then(res => res.json()).then(res => {
|
||||
return {
|
||||
album: null,
|
||||
items: [{
|
||||
id: res.data.id,
|
||||
url: res.data.animated ? res.data.mp4 : res.data.link,
|
||||
title: res.data.title,
|
||||
description: res.data.description,
|
||||
type: res.data.animated ? 'video/mp4' : res.data.type,
|
||||
datetime: new Date(res.data.datetime * 1000),
|
||||
original: res.data
|
||||
}]
|
||||
};
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = imgurImage;
|
||||
17
src/methods/methods.js
Normal file
17
src/methods/methods.js
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const self = require('./self.js');
|
||||
const reddit = require('./reddit.js');
|
||||
const imgurImage = require('./imgurImage.js');
|
||||
const imgurAlbum = require('./imgurAlbum.js');
|
||||
const gfycat = require('./gfycat.js');
|
||||
const eroshare = require('./eroshare.js');
|
||||
|
||||
module.exports = {
|
||||
self: self,
|
||||
reddit: reddit,
|
||||
imgurImage: imgurImage,
|
||||
imgurAlbum: imgurAlbum,
|
||||
gfycat: gfycat,
|
||||
eroshare: eroshare
|
||||
};
|
||||
21
src/methods/reddit.js
Normal file
21
src/methods/reddit.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const config = require('config');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
function reddit(post) {
|
||||
return Promise.resolve({
|
||||
album: null,
|
||||
items: [{
|
||||
id: post.host.id || post.id,
|
||||
url: post.url,
|
||||
title: post.title,
|
||||
datetime: post.datetime,
|
||||
type: 'image/jpeg',
|
||||
original: post
|
||||
}]
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = reddit;
|
||||
23
src/methods/self.js
Normal file
23
src/methods/self.js
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const config = require('config');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
function self(post) {
|
||||
return Promise.resolve({
|
||||
album: null,
|
||||
items: [{
|
||||
id: post.id,
|
||||
url: post.url,
|
||||
title: post.title,
|
||||
text: post.text,
|
||||
datetime: post.datetime,
|
||||
type: 'text/plain',
|
||||
self: true,
|
||||
original: post
|
||||
}]
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = self;
|
||||
Reference in New Issue
Block a user