factor out shared booru code
This commit is contained in:
parent
95983cbffe
commit
a1cfa60e51
|
@ -0,0 +1,15 @@
|
|||
import { dl, get } from './_shared.js';
|
||||
|
||||
export const booru = (host, limit) => dl(
|
||||
async function*(query) {
|
||||
for (let pid = 0, posts; !posts || posts.length === limit; pid++) {
|
||||
posts = (await (await get(`https://${host}/index.php`, { page: 'dapi', s: 'post', q: 'index', limit, pid, tags: query })).text()).match(/<post\b.*?\/>/gs) || [];
|
||||
yield posts.map(post => {
|
||||
const url = post.match(/\bfile_url="(.*?)"/)[1];
|
||||
const dest = `${post.match(/\bid="(.*?)"/)[1]}-${post.match(/\bmd5="(.*?)"/)[1]}.${url.match(/[^.]*$/)[0]}`;
|
||||
const date = post.match(/\bcreated_at="(.*?)"/)[1];
|
||||
return { url, dest, date };
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
|
@ -1,17 +1,5 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import { dl, get } from './_shared.js';
|
||||
import { booru } from './_booru.js';
|
||||
|
||||
await dl(
|
||||
async function*(query) {
|
||||
for (let pid = 0, posts; !posts || posts.length === 100; pid++) {
|
||||
posts = (await (await get('https://furry.booru.org/index.php', { page: 'dapi', s: 'post', q: 'index', limit: 100, pid, tags: query })).text()).match(/<post\b.*?\/>/gs) || [];
|
||||
yield posts.map(post => {
|
||||
const url = post.match(/\bfile_url="(.*?)"/)[1];
|
||||
const dest = `${post.match(/\bid="(.*?)"/)[1]}-${post.match(/\bmd5="(.*?)"/)[1]}.${url.match(/[^.]*$/)[0]}`;
|
||||
const date = post.match(/\bcreated_at="(.*?)"/)[1];
|
||||
return { url, dest, date };
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
await booru('furry.booru.org', 100);
|
||||
|
|
Loading…
Reference in New Issue