1
Fork 0

tidy for loops

This commit is contained in:
Conduitry 2022-06-11 08:23:08 -04:00
parent de2febf6d9
commit 635ad1b3b6
2 changed files with 4 additions and 11 deletions

View File

@ -5,17 +5,13 @@ import { dl } from './_dl.js';
await dl({
from: import.meta.url,
async *get_posts(query, get) {
for (let page = null; ;) {
const { posts } = await (await get('https://e621.net/posts.json', { limit: 320, page, tags: query })).json();
for (let page = null, posts; !posts || posts.length === 320; page = `b${posts[319]?.id}`) {
posts = (await (await get('https://e621.net/posts.json', { limit: 320, page, tags: query })).json()).posts;
yield posts.map(post => ({
url: `https://static1.e621.net/data/${post.file.md5.slice(0, 2)}/${post.file.md5.slice(2, 4)}/${post.file.md5}.${post.file.ext}`,
dest: `${query}/${post.id}-${post.file.md5}.${post.file.ext}`,
date: post.created_at,
}));
if (posts.length < 320) {
return;
}
page = `b${posts[319].id}`;
}
},
});

View File

@ -5,17 +5,14 @@ import { dl } from './_dl.js';
await dl({
from: import.meta.url,
async *get_posts(query, get) {
for (let pid = 0; ; pid++) {
const 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) || [];
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 = `${query}/${post.match(/\bid="(.*?)"/)[1]}-${post.match(/\bmd5="(.*?)"/)[1]}.${url.match(/[^.]*$/)[0]}`;
const date = post.match(/\bcreated_at="(.*?)"/)[1];
return { url, dest, date };
});
if (posts.length < 100) {
return;
}
}
},
});