Skip to content

Commit

Permalink
properly display media count
Browse files Browse the repository at this point in the history
  • Loading branch information
snebl committed Nov 5, 2023
1 parent 7bbc535 commit 62a005a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ async function downloadAllFolders(save) {
console.log('\nDownloading: ' + save.table[index].tags);

let currentCompleted = 0;
let completeOffset = 0;
// function is recursive so it can call itself (with timeout) when we need to fetch and download more than 320 files (e621's max limit)
async function downloadFolder() {
// fetch new URLs for each folder listed in the selected data json file
Expand All @@ -396,12 +397,6 @@ async function downloadAllFolders(save) {
return;
}

// remember modified folder [moved]
// if (tempIndex != index) {
// foldersModified.push((Object.keys(data['posts']).length == config.batch ? '>' : '+') + Object.keys(data['posts']).length + ' ][ ' + tags);
// tempIndex = index;
// }

// TODO: look into ways to make this faster
for (const post of data['posts']) {
// not recursive (except for retries)
Expand All @@ -414,6 +409,11 @@ async function downloadAllFolders(save) {
// track how long it takes to download
const dlTime = Date.now();

// needed to properly display the media count
if (completeOffset == 0 && Object.keys(data['posts']).length != config.batch) {
completeOffset = currentCompleted;
}

// reconstruct URL if its null for some reason
let url = post['file']['url'];
let wasDecoded = false;
Expand Down Expand Up @@ -442,7 +442,11 @@ async function downloadAllFolders(save) {
fileStream.on('finish', () => {
fileStream.close();
currentCompleted++;
console.log(' ├─Download Completed [ ' + currentCompleted + (Object.keys(data['posts']).length == config.batch ? '' : ('/' + Object.keys(data['posts']).length)) + ' ]' + infoString + (Date.now() - dlTime) + ' ms');
console.log(
' ├─Download Completed [ ' + currentCompleted +
(Object.keys(data['posts']).length == config.batch ? '' : (' / ' + (completeOffset + Object.keys(data['posts']).length))) +
' ]' + infoString + (Date.now() - dlTime) + ' ms'
);
if (wasDecoded) console.log(' │ └─[ URL Decoded ]');
total.total++;
total.bytes += post['file']['size'];
Expand Down

0 comments on commit 62a005a

Please sign in to comment.