Added dynamic dividers to patterns. Fixed PornHub module. Updated README.
This commit is contained in:
@@ -50,7 +50,7 @@ async function getCompletePosts() {
|
||||
}
|
||||
|
||||
if (!usernames.length && !postIds.length) {
|
||||
throw new Error('Could not retrieve any posts. Did you supply --users, --posts, --file-users or --file-posts?');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (usernames.length) {
|
||||
@@ -105,12 +105,14 @@ async function initApp() {
|
||||
|
||||
if (args.fetch || args.fileDirect) {
|
||||
await getCompleteContents(ep);
|
||||
return;
|
||||
}
|
||||
|
||||
const userPosts = await getCompletePosts();
|
||||
|
||||
await fetchSavePosts(userPosts, ep);
|
||||
if (userPosts) {
|
||||
await fetchSavePosts(userPosts, ep);
|
||||
}
|
||||
|
||||
await ep.close();
|
||||
|
||||
if (args.watch) {
|
||||
|
||||
@@ -34,6 +34,14 @@ function getArgs() {
|
||||
type: 'string',
|
||||
alias: 'file-fetch',
|
||||
})
|
||||
.option('label', {
|
||||
describe: 'Arbitrary variable made available in path patterns. Useful to organize files from a URL lists in directory.',
|
||||
type: 'string',
|
||||
})
|
||||
.option('base', {
|
||||
describe: 'Alternative base path, overriding both the default posts and direct base paths.',
|
||||
type: 'string',
|
||||
})
|
||||
.option('limit', {
|
||||
describe: 'Maximum amount of posts to fetch per supplied user (!), after filtering out ignored, cross- and reposts',
|
||||
type: 'number',
|
||||
|
||||
@@ -7,6 +7,8 @@ const dateFns = require('date-fns');
|
||||
const mime = require('mime-types');
|
||||
const format = require('template-format');
|
||||
|
||||
const args = require('./cli')();
|
||||
|
||||
function interpolate(pattern, item = null, content = null, host = null, post = null, user = null, strip = true, dateFormat = config.library.dateFormat) {
|
||||
const data = {
|
||||
tags: {},
|
||||
@@ -104,7 +106,7 @@ function interpolate(pattern, item = null, content = null, host = null, post = n
|
||||
if (typeof value === 'string') {
|
||||
return {
|
||||
...acc,
|
||||
[key]: value && value.toString().replace(/\//g, config.library.slashSubstitute),
|
||||
[key]: value ? value.toString().replace(/\//g, config.library.slashSubstitute) : '',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -112,20 +114,45 @@ function interpolate(pattern, item = null, content = null, host = null, post = n
|
||||
...acc,
|
||||
[key]: Object.entries(value).reduce((subacc, [subkey, subvalue]) => ({
|
||||
...subacc,
|
||||
[subkey]: subvalue && subvalue.toString().replace(/\//g, config.library.slashSubstitute),
|
||||
[subkey]: subvalue ? subvalue.toString().replace(/\//g, config.library.slashSubstitute) : '',
|
||||
}), {}),
|
||||
};
|
||||
}, {})
|
||||
: data;
|
||||
|
||||
const base = {
|
||||
posts: format(config.library.base.posts, strippedData),
|
||||
direct: format(config.library.base.direct, strippedData),
|
||||
};
|
||||
const dividers = Object.entries(data).reduce((acc, [key, value]) => {
|
||||
if (typeof value === 'string') {
|
||||
return {
|
||||
...acc,
|
||||
[key]: value ? config.library.divider : '',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...acc,
|
||||
[key]: Object.entries(value).reduce((subacc, [subkey, subvalue]) => ({
|
||||
...subacc,
|
||||
[subkey]: subvalue ? config.library.divider : '',
|
||||
}), {}),
|
||||
};
|
||||
}, {});
|
||||
|
||||
if (args.label) {
|
||||
Object.assign(strippedData, {
|
||||
label: format(args.label, strippedData),
|
||||
});
|
||||
}
|
||||
|
||||
const interpolated = format(pattern, {
|
||||
base,
|
||||
...strippedData,
|
||||
base: {
|
||||
posts: format(args.base || config.library.base.posts, strippedData),
|
||||
direct: format(args.base || config.library.base.direct, strippedData),
|
||||
},
|
||||
dividers,
|
||||
divider: config.library.divider,
|
||||
divs: dividers,
|
||||
div: config.library.divider,
|
||||
});
|
||||
|
||||
return interpolated;
|
||||
|
||||
@@ -1,38 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const fetch = require('node-fetch');
|
||||
const youtubedl = require('youtube-dl');
|
||||
const dateFns = require('date-fns');
|
||||
|
||||
async function pornhub(host, post) {
|
||||
const res = await fetch(`https://www.pornhub.com/view_video.php?viewkey=${host.id}`);
|
||||
async function pornhub(host) {
|
||||
const data = await new Promise((resolve, reject) => {
|
||||
youtubedl.getInfo(`https://www.pornhub.com/view_video.php?viewkey=${host.id}`, null, (error, info) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
if (res.status !== 200) {
|
||||
throw new Error(`Could not fetch info PornHub video '${host.id}': '${res.error}'`);
|
||||
}
|
||||
|
||||
const html = await res.text();
|
||||
const dataString = html.replace(/\s+/g, ' ').match(/var flashvars_.* = (.*); var player_mp4_seek/)[1];
|
||||
const data = JSON.parse(dataString);
|
||||
const url = data.mediaDefinitions.sort((sourceA, sourceB) => {
|
||||
if (sourceA.quality < sourceB.quality) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sourceA.quality > sourceB.quality) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
})[0].videoUrl;
|
||||
resolve(info);
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
album: null,
|
||||
items: [{
|
||||
id: host.id,
|
||||
url,
|
||||
title: post ? post.title : null,
|
||||
type: 'video/mp4',
|
||||
datetime: post ? post.datetime : null,
|
||||
}],
|
||||
items: [
|
||||
{
|
||||
id: data.id,
|
||||
url: data.url,
|
||||
title: data.fulltitle || data.title,
|
||||
type: `video/${data.ext}`,
|
||||
datetime: dateFns.format(data.upload_date, 'YYYYMMDD'),
|
||||
original: data,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user