I wrote a dataset downloader for e621.net: const axios = require('axios'); const fs =…
- User
I wrote a dataset downloader for e621.net: const axios = require('axios'); const fs = require('fs'); const path = require('path'); const readline = require('readline'); const ProgressBar = require('progress');
/**
-
Prompts the user for input.
-
@param {string} question - The question to display to the user.
-
@returns {Promise} - The user's input. */ function getUserInput(question) { const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
return new Promise(resolve => { rl.question(question, (input) => { rl.close(); resolve(input.trim()); }); }); }
/**
-
Retrieves the total number of posts matching the tags.
-
@param {string} tags - The tags to search for.
-
@param {string} username - e621 username.
-
@param {string} apiKey - e621 API key.
-
@returns {Promise} - Total number of posts. */ async function getPostCount(tags, username, apiKey) { try { const response = await axios.get('https://e621.net/posts.json', { params: { tags: tags, limit: 1 // Set limit to 1 to get minimal data }, auth: { username: username, password: apiKey }, headers: { 'User-Agent':
e621Downloader/1.0 (by ${username} on e621)} });codeconst totalPosts = parseInt(response.headers['x-total']); if (isNaN(totalPosts)) { throw new Error('Unable to retrieve total post count from response headers.'); } return totalPosts;} catch (error) { console.error('Error fetching post count:', error.response ? error.response.data : error.message); return null; } }
/**
-
Downloads the specified number of posts with the given tags.
-
@param {string} tags - Tags for searching posts.
-
@param {number} limit - Number of posts to download.
-
@param {string} destination - Destination folder path.
-
@param {string} username - e621 username.
-
@param {string} apiKey - e621 API key.
-
@param {boolean} describeEnabled - Whether to enable the describe function.
-
@param {boolean} replaceUnderscores - Whether to replace underscores with spaces in tags. */ async function downloadPosts(tags, limit, destination, username, apiKey, describeEnabled, replaceUnderscores) { let page = 1; let downloaded = 0;
-
- Assistant