Added support for Vidble (image) albums. Replaced extensions.json and reverseLookup with mime-types lib.
This commit is contained in:
parent
af068df639
commit
89ab431a2f
|
@ -26,7 +26,8 @@ module.exports = {
|
||||||
comment: '$itemDescription'
|
comment: '$itemDescription'
|
||||||
},
|
},
|
||||||
dateFormat: 'YYYYMMDD',
|
dateFormat: 'YYYYMMDD',
|
||||||
titleLength: 200,
|
filenameLimit: 250,
|
||||||
|
truncator: '...',
|
||||||
indexOffset: 1,
|
indexOffset: 1,
|
||||||
slashSubstitute: '#',
|
slashSubstitute: '#',
|
||||||
},
|
},
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
"dist-exiftool": "^10.53.0",
|
"dist-exiftool": "^10.53.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"fs-extra": "^5.0.0",
|
"fs-extra": "^5.0.0",
|
||||||
|
"mime-types": "^2.1.18",
|
||||||
"node-exiftool": "^2.3.0",
|
"node-exiftool": "^2.3.0",
|
||||||
"node-fetch": "^2.1.2",
|
"node-fetch": "^2.1.2",
|
||||||
"promise.prototype.finally": "^3.1.0",
|
"promise.prototype.finally": "^3.1.0",
|
||||||
|
|
|
@ -26,6 +26,14 @@ const hosts = [{
|
||||||
method: 'imgurAlbum',
|
method: 'imgurAlbum',
|
||||||
label: 'imgur',
|
label: 'imgur',
|
||||||
pattern: new urlPattern('http(s)\\://(:subdomain.)imgur.com/:type/:id')
|
pattern: new urlPattern('http(s)\\://(:subdomain.)imgur.com/:type/:id')
|
||||||
|
}, {
|
||||||
|
method: 'vidbleImage',
|
||||||
|
label: 'vidble',
|
||||||
|
pattern: new urlPattern('http(s)\\://(www.)vidble.com/(show/):id(.:ext)')
|
||||||
|
}, {
|
||||||
|
method: 'vidbleAlbum',
|
||||||
|
label: 'vidble',
|
||||||
|
pattern: new urlPattern('http(s)\\://(www.)vidble.com/album/:id')
|
||||||
}, {
|
}, {
|
||||||
method: 'gfycat',
|
method: 'gfycat',
|
||||||
label: 'gfycat',
|
label: 'gfycat',
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"image/jpeg": ".jpg",
|
|
||||||
"image/png": ".png",
|
|
||||||
"image/gif": ".gif",
|
|
||||||
"video/mp4": ".mp4",
|
|
||||||
"video/webm": ".webm"
|
|
||||||
}
|
|
|
@ -4,8 +4,7 @@ const config = require('config');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const dateFns = require('date-fns');
|
const dateFns = require('date-fns');
|
||||||
|
const mime = require('mime-types');
|
||||||
const extensions = require('./extensions.json');
|
|
||||||
|
|
||||||
function interpolate(pattern, user, post, item) {
|
function interpolate(pattern, user, post, item) {
|
||||||
const dateFormat = config.library.dateFormat || 'YYYYMMDD';
|
const dateFormat = config.library.dateFormat || 'YYYYMMDD';
|
||||||
|
@ -65,7 +64,7 @@ function interpolate(pattern, user, post, item) {
|
||||||
$itemIndex: item.index + config.library.indexOffset,
|
$itemIndex: item.index + config.library.indexOffset,
|
||||||
$extracted: item.extracted ? config.library.booleans.extracted : '',
|
$extracted: item.extracted ? config.library.booleans.extracted : '',
|
||||||
$preview: item.preview ? config.library.booleans.preview : '',
|
$preview: item.preview ? config.library.booleans.preview : '',
|
||||||
$ext: item.extension || (item.type ? extensions[item.type] : path.extname(url.parse(item.url).pathname))
|
$ext: `.${mime.extension(item.type).replace('jpeg', 'jpg') || path.extname(url.parse(item.url).pathname)}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ const redditVideo = require('./redditVideo.js');
|
||||||
const redditPreview = require('./redditPreview.js');
|
const redditPreview = require('./redditPreview.js');
|
||||||
const imgurImage = require('./imgurImage.js');
|
const imgurImage = require('./imgurImage.js');
|
||||||
const imgurAlbum = require('./imgurAlbum.js');
|
const imgurAlbum = require('./imgurAlbum.js');
|
||||||
|
const vidbleImage = require('./vidbleImage.js');
|
||||||
|
const vidbleAlbum = require('./vidbleAlbum.js');
|
||||||
const gfycat = require('./gfycat.js');
|
const gfycat = require('./gfycat.js');
|
||||||
const eroshare = require('./eroshare.js');
|
const eroshare = require('./eroshare.js');
|
||||||
|
|
||||||
|
@ -16,6 +18,8 @@ module.exports = {
|
||||||
redditPreview,
|
redditPreview,
|
||||||
imgurImage,
|
imgurImage,
|
||||||
imgurAlbum,
|
imgurAlbum,
|
||||||
|
vidbleImage,
|
||||||
|
vidbleAlbum,
|
||||||
gfycat,
|
gfycat,
|
||||||
eroshare
|
eroshare
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const path = require('path');
|
const mime = require('mime-types');
|
||||||
const fetch = require('node-fetch');
|
|
||||||
|
|
||||||
const extensions = require('../extensions.json');
|
|
||||||
|
|
||||||
function reverseLookup(extension) {
|
|
||||||
return Object.keys(extensions).find(mime => extensions[mime] === extension);
|
|
||||||
};
|
|
||||||
|
|
||||||
function redditImage(post) {
|
function redditImage(post) {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
|
@ -19,7 +12,7 @@ function redditImage(post) {
|
||||||
url: post.url,
|
url: post.url,
|
||||||
title: post.title,
|
title: post.title,
|
||||||
datetime: post.datetime,
|
datetime: post.datetime,
|
||||||
type: reverseLookup(path.extname(post.url)),
|
type: mime.lookup(post.url),
|
||||||
original: post
|
original: post
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,14 +4,9 @@ const util = require('util');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
const mime = require('mime-types');
|
||||||
const urlPattern = require('url-pattern');
|
const urlPattern = require('url-pattern');
|
||||||
|
|
||||||
const extensions = require('../extensions.json');
|
|
||||||
|
|
||||||
function reverseLookup(extension) {
|
|
||||||
return Object.keys(extensions).find(mime => extensions[mime] === extension);
|
|
||||||
};
|
|
||||||
|
|
||||||
function redditPreview(post) {
|
function redditPreview(post) {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
album: post.preview.length > 1 ? {
|
album: post.preview.length > 1 ? {
|
||||||
|
@ -22,14 +17,14 @@ function redditPreview(post) {
|
||||||
original: post
|
original: post
|
||||||
} : null,
|
} : null,
|
||||||
items: post.preview.map(image => {
|
items: post.preview.map(image => {
|
||||||
const urlComponents = new urlPattern('http(s)\\://i.redditmedia.com/:id(.:ext)(?*)').match(image.url);
|
console.log(mime.lookup(image.url));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: post.host.id || post.id,
|
id: post.host.id || post.id,
|
||||||
url: image.url,
|
url: image.url,
|
||||||
title: post.title,
|
title: post.title,
|
||||||
datetime: post.datetime,
|
datetime: post.datetime,
|
||||||
type: reverseLookup(`.${urlComponents.ext}`),
|
type: mime.lookup(image.url),
|
||||||
preview: true,
|
preview: true,
|
||||||
original: post
|
original: post
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const util = require('util');
|
||||||
|
const config = require('config');
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
const urlPattern = require('url-pattern');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const mime = require('mime-types');
|
||||||
|
|
||||||
|
const pattern = new urlPattern('https\\://(www.)vidble.com/:id(_med)(.:ext)');
|
||||||
|
|
||||||
|
function vidbleAlbum(post) {
|
||||||
|
return fetch(`https://www.vidble.com/album/${post.host.id}`).then(res => {
|
||||||
|
if(res.status !== 200) {
|
||||||
|
throw new Error(`Could not fetch info for vidble album '${post.host.id}': '${res.error}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.text();
|
||||||
|
}).then(res => {
|
||||||
|
const $ = cheerio.load(res);
|
||||||
|
|
||||||
|
const title = $('h2').text();
|
||||||
|
const imgUrls = $('img.img2').toArray().map(img => `https://vidble.com${img.attribs.src || img.attribs['data-original']}`);
|
||||||
|
|
||||||
|
const extract = config.library.album.extractSingleItem && imgUrls.length === 1;
|
||||||
|
|
||||||
|
if(extract) {
|
||||||
|
console.log('\x1b[36m%s\x1b[0m', `Extracting single item from album '${post.title}' - ${res.link}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
album: extract ? null : {
|
||||||
|
id: post.host.id,
|
||||||
|
url: post.url,
|
||||||
|
title: post.title,
|
||||||
|
datetime: post.datetime
|
||||||
|
},
|
||||||
|
items: imgUrls.map(url => {
|
||||||
|
const components = pattern.match(url);
|
||||||
|
const id = components.id.replace('_med', '');
|
||||||
|
const mimetype = mime.lookup(components.ext);
|
||||||
|
|
||||||
|
return {
|
||||||
|
extracted: extract,
|
||||||
|
id: id,
|
||||||
|
url: `https://vidble.com/${id}.${components.ext}`,
|
||||||
|
type: mimetype,
|
||||||
|
datetime: post.datetime
|
||||||
|
};
|
||||||
|
})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = vidbleAlbum;
|
|
@ -0,0 +1,26 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const util = require('util');
|
||||||
|
const config = require('config');
|
||||||
|
const path = require('path');
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
const $ = require('cheerio');
|
||||||
|
|
||||||
|
function vidbleImage(post) {
|
||||||
|
return fetch(`https://vidble.com/${post.host.id}`).then(res => res.text()).then(res => {
|
||||||
|
console.log(res, $('img'));
|
||||||
|
|
||||||
|
if(res.status !== 200) {
|
||||||
|
throw new Error(`Could not fetch info for vidble album '${post.host.id}': '${res.data.error}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
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}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = vidbleImage;
|
Loading…
Reference in New Issue