1
Fork 0

factor out shared booru code

This commit is contained in:
Conduitry 2022-06-19 22:39:10 -04:00
parent 95983cbffe
commit a1cfa60e51
2 changed files with 17 additions and 14 deletions

15
_booru.js Normal file
View File

@ -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 };
});
}
},
);

View File

@ -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);