Added single item album extraction with configurable display variable, as well as a host/source name variable.
This commit is contained in:
parent
21e70daa0a
commit
c3fc11d1ea
|
@ -32,6 +32,7 @@ Path patterns dictate where and how a file will be saved. Various variables and
|
||||||
* `$postUser`: The user that submitted the post, almost always equivalent to the `--user` command line argument
|
* `$postUser`: The user that submitted the post, almost always equivalent to the `--user` command line argument
|
||||||
* `$postDate`: The submission date of the reddit post, formatted by the `dateformat` configuration described below
|
* `$postDate`: The submission date of the reddit post, formatted by the `dateformat` configuration described below
|
||||||
* `$postIndex`: The index of the post according to the sort method
|
* `$postIndex`: The index of the post according to the sort method
|
||||||
|
* `$host`: Name of the source the content was hosted on
|
||||||
|
|
||||||
##### Album
|
##### Album
|
||||||
* `$albumId`: The ID of the media host album
|
* `$albumId`: The ID of the media host album
|
||||||
|
@ -45,6 +46,7 @@ Path patterns dictate where and how a file will be saved. Various variables and
|
||||||
* `$itemDescription`: The description of the individual image or video
|
* `$itemDescription`: The description of the individual image or video
|
||||||
* `$itemDate`: The submission date of the individual image or video, formatted by the `dateformat` configuration described below
|
* `$itemDate`: The submission date of the individual image or video, formatted by the `dateformat` configuration described below
|
||||||
* `$itemIndex`: The index of the individual image or video in an album, offset by the `indexOffset` configuration described below
|
* `$itemIndex`: The index of the individual image or video in an album, offset by the `indexOffset` configuration described below
|
||||||
|
* `$extracted`: When extracting single album items is enabled and the item has been extracted, this variable will display the value of `extractedLabel` as described below in case the item was the only item in an album
|
||||||
* `$ext`: The extension of the medium. Must typically be included, but may be omitted for self (text) posts on Unix systems
|
* `$ext`: The extension of the medium. Must typically be included, but may be omitted for self (text) posts on Unix systems
|
||||||
|
|
||||||
##### `dateFormat`
|
##### `dateFormat`
|
||||||
|
@ -58,3 +60,6 @@ Arrays start at 0, but as to not tire myself out debating the matter, you may of
|
||||||
|
|
||||||
##### `slashSubstitute`
|
##### `slashSubstitute`
|
||||||
The patterns represent Unix file paths, and a `/` therefore indicates a new directory. You may freely use directories in your paths, but titles or descriptions may contain a `/` that is not supposed to create a new directory. All instances of `/` in a variable value will be replaced with the configured slash substitute.
|
The patterns represent Unix file paths, and a `/` therefore indicates a new directory. You may freely use directories in your paths, but titles or descriptions may contain a `/` that is not supposed to create a new directory. All instances of `/` in a variable value will be replaced with the configured slash substitute.
|
||||||
|
|
||||||
|
##### `album.extractSingleItem` and `extractedLabel`
|
||||||
|
Some albums contain only one image or video. By setting `album.extractSingleItem` to `true` (default), the item will be saved in accordance to the individual item patterns rather than the album patterns. An extracted item will inherit the title and description of the album if it has none of its own. Extracted items can be marked with the `$extracted` boolean variable, of which the display value is set with `extractedLabel`.
|
||||||
|
|
|
@ -4,13 +4,15 @@ module.exports = {
|
||||||
video: 'output/$postUser/$postDate - $itemId - $postTitle$ext',
|
video: 'output/$postUser/$postDate - $itemId - $postTitle$ext',
|
||||||
text: 'output/$postUser/$postDate - $postId - $postTitle',
|
text: 'output/$postUser/$postDate - $postId - $postTitle',
|
||||||
album: {
|
album: {
|
||||||
|
extractSingleItem: true,
|
||||||
image: 'output/$postUser/$postDate - $albumId - $postTitle/$itemIndex - $itemId$ext',
|
image: 'output/$postUser/$postDate - $albumId - $postTitle/$itemIndex - $itemId$ext',
|
||||||
video: 'output/$postUser/$postDate - $albumId - $postTitle/$itemIndex - $itemId$ext'
|
video: 'output/$postUser/$postDate - $albumId - $postTitle/$itemIndex - $itemId$ext'
|
||||||
},
|
},
|
||||||
dateformat: 'YYYYMMDD',
|
dateFormat: 'YYYYMMDD',
|
||||||
titleLength: 200,
|
titleLength: 200,
|
||||||
indexOffset: 1,
|
indexOffset: 1,
|
||||||
slashSubstitute: '#'
|
slashSubstitute: '#',
|
||||||
|
extractedLabel: 'extracted-'
|
||||||
},
|
},
|
||||||
reddit: {
|
reddit: {
|
||||||
sort: 'top',
|
sort: 'top',
|
||||||
|
|
|
@ -4,21 +4,27 @@ const urlPattern = require('url-pattern');
|
||||||
|
|
||||||
const hosts = [{
|
const hosts = [{
|
||||||
method: 'self',
|
method: 'self',
|
||||||
|
label: 'self',
|
||||||
pattern: new urlPattern('http(s)\\://(www.)reddit.com/r/:subreddit/comments/:id/:uri/')
|
pattern: new urlPattern('http(s)\\://(www.)reddit.com/r/:subreddit/comments/:id/:uri/')
|
||||||
}, {
|
}, {
|
||||||
method: 'reddit',
|
method: 'reddit',
|
||||||
|
label: 'reddit',
|
||||||
pattern: new urlPattern('http(s)\\://i.redd.it/:id.:ext')
|
pattern: new urlPattern('http(s)\\://i.redd.it/:id.:ext')
|
||||||
}, {
|
}, {
|
||||||
method: 'imgurImage',
|
method: 'imgurImage',
|
||||||
|
label: 'imgur',
|
||||||
pattern: new urlPattern('http(s)\\://(i.)imgur.com/:id(.:ext)(?:num)')
|
pattern: new urlPattern('http(s)\\://(i.)imgur.com/:id(.:ext)(?:num)')
|
||||||
}, {
|
}, {
|
||||||
method: 'imgurAlbum',
|
method: 'imgurAlbum',
|
||||||
|
label: 'imgur',
|
||||||
pattern: new urlPattern('http(s)\\://(m.)imgur.com/:type/:id')
|
pattern: new urlPattern('http(s)\\://(m.)imgur.com/:type/:id')
|
||||||
}, {
|
}, {
|
||||||
method: 'gfycat',
|
method: 'gfycat',
|
||||||
|
label: 'gfycat',
|
||||||
pattern: new urlPattern('http(s)\\://(:server.)gfycat.com/:id(.:ext)')
|
pattern: new urlPattern('http(s)\\://(:server.)gfycat.com/:id(.:ext)')
|
||||||
}, {
|
}, {
|
||||||
method: 'eroshare',
|
method: 'eroshare',
|
||||||
|
label: 'eroshare',
|
||||||
pattern: new urlPattern('http(s)\\://eroshare.com/:id')
|
pattern: new urlPattern('http(s)\\://eroshare.com/:id')
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
@ -33,7 +39,8 @@ module.exports = function dissectLink(url) {
|
||||||
if(match) {
|
if(match) {
|
||||||
return Object.assign(match, {
|
return Object.assign(match, {
|
||||||
url: url,
|
url: url,
|
||||||
method: host.method
|
method: host.method,
|
||||||
|
label: host.label
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,15 @@ const extensions = {
|
||||||
};
|
};
|
||||||
|
|
||||||
function interpolate(path, post, item) {
|
function interpolate(path, post, item) {
|
||||||
const dateFormat = config.patterns.dateformat || 'YYYYMMDD';
|
const dateFormat = config.patterns.dateFormat || 'YYYYMMDD';
|
||||||
|
|
||||||
const vars = {
|
const vars = {
|
||||||
$postId: post.id,
|
$postId: post.id,
|
||||||
$postTitle: (post.title || '').slice(0, config.patterns.titleLength),
|
$postTitle: (post.title || '').slice(0, config.patterns.titleLength),
|
||||||
$postUser: post.user,
|
$postUser: post.user,
|
||||||
$postDate: dateFns.format(post.datetime, dateFormat),
|
$postDate: dateFns.format(post.datetime, dateFormat),
|
||||||
$postIndex: post.index + config.patterns.indexOffset
|
$postIndex: post.index + config.patterns.indexOffset,
|
||||||
|
$host: post.host.label
|
||||||
};
|
};
|
||||||
|
|
||||||
if(post.content.album) {
|
if(post.content.album) {
|
||||||
|
@ -37,6 +38,7 @@ function interpolate(path, post, item) {
|
||||||
$itemDescription: item.description,
|
$itemDescription: item.description,
|
||||||
$itemDate: dateFns.format(item.datetime, dateFormat),
|
$itemDate: dateFns.format(item.datetime, dateFormat),
|
||||||
$itemIndex: item.index + config.patterns.indexOffset,
|
$itemIndex: item.index + config.patterns.indexOffset,
|
||||||
|
$extracted: item.extracted ? config.patterns.extractedLabel : '',
|
||||||
$ext: extensions[item.type]
|
$ext: extensions[item.type]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,15 +13,17 @@ function eroshare(post) {
|
||||||
return Promise.reject(`Unable to recover Eroshare video '${post.host.id}' :(`);
|
return Promise.reject(`Unable to recover Eroshare video '${post.host.id}' :(`);
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
const data = JSON.parse(res.match(/var album = .*/)[0].slice(12, -1));
|
const data = JSON.parse(res.match(/var album = .*/)[0].slice(12, -1));
|
||||||
|
const extract = config.patterns.album.extractSingleItem && data.items.length === 1;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
album: {
|
album: extract ? null : {
|
||||||
id: data.slug,
|
id: data.slug,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
datetime: new Date(data.created_at)
|
datetime: new Date(data.created_at)
|
||||||
},
|
},
|
||||||
items: data.items.map(item => {
|
items: data.items.map(item => {
|
||||||
return {
|
return {
|
||||||
|
extracted: extract,
|
||||||
id: item.slug,
|
id: item.slug,
|
||||||
url: item.type === 'Image' ? item.url_full_protocol : item.url_mp4,
|
url: item.type === 'Image' ? item.url_full_protocol : item.url_mp4,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
|
|
|
@ -10,8 +10,10 @@ function imgurAlbum(post) {
|
||||||
'Authorization': `Client-ID ${config.methods.imgur.clientId}`
|
'Authorization': `Client-ID ${config.methods.imgur.clientId}`
|
||||||
}
|
}
|
||||||
}).then(res => res.json()).then(res => {
|
}).then(res => res.json()).then(res => {
|
||||||
|
const extract = config.patterns.album.extractSingleItem && res.data.images.length === 1;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
album: {
|
album: extract ? null : {
|
||||||
id: res.data.id,
|
id: res.data.id,
|
||||||
url: res.data.link,
|
url: res.data.link,
|
||||||
title: res.data.title,
|
title: res.data.title,
|
||||||
|
@ -20,10 +22,11 @@ function imgurAlbum(post) {
|
||||||
original: res.data
|
original: res.data
|
||||||
},
|
},
|
||||||
items: res.data.images.map(item => ({
|
items: res.data.images.map(item => ({
|
||||||
|
extracted: extract,
|
||||||
id: item.id,
|
id: item.id,
|
||||||
url: item.animated ? item.mp4 : item.link,
|
url: item.animated ? item.mp4 : item.link,
|
||||||
title: item.title,
|
title: item.title || (extract ? res.data.title : null),
|
||||||
description: item.description,
|
description: item.description || (extract ? res.data.description : null),
|
||||||
type: item.animated ? 'video/mp4' : item.type,
|
type: item.animated ? 'video/mp4' : item.type,
|
||||||
datetime: item.datetime * 1000,
|
datetime: item.datetime * 1000,
|
||||||
original: item
|
original: item
|
||||||
|
|
Loading…
Reference in New Issue