Skip to content

Commit

Permalink
Improve logging for videos that exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Nov 1, 2024
1 parent 075249c commit 88c7197
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "floatplane-plex-downloader",
"version": "5.16.1",
"version": "5.16.2",
"private": true,
"type": "module",
"scripts": {
Expand Down
23 changes: 14 additions & 9 deletions src/lib/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,26 @@ export class Video extends Attachment {
}

public async download() {
promQueued.inc();
await Video.DownloadSemaphore.obtain();
try {
// Make sure the folder for the video exists
await fs.mkdir(this.folderPath, { recursive: true }).catch((err) => this.onError(err, true));
if (settings.extras.saveNfo) {
this.logger.log("Saving .nfo");
await this.saveNfo().catch(withContext(`Saving .nfo file!`)).catch(this.onError);
await this.saveNfo().catch(withContext(`Saving .nfo file`)).catch(this.onError);
}
if (settings.extras.downloadArtwork) {
this.logger.log("Saving artwork");
await this.downloadArtwork().catch(withContext(`Saving artwork!`)).catch(this.onError);
await this.downloadArtwork().catch(withContext(`Saving artwork`)).catch(this.onError);
}
if ((await this.getState()) === Video.State.Muxed) {
this.logger.done(chalk`{green Exists! Skipping}`);
return;
}
if ((await this.getState()) === Video.State.Muxed) return;
promQueued.inc();
for (let retries = 0; retries < Video.MaxRetries; retries++) {
try {
switch (await this.getState()) {
case Video.State.Missing: {
await this.onMissing().catch(withContext(`Downloading missing video!`));
await this.onMissing().catch(withContext(`Downloading missing video`));
}
// eslint-disable-next-line no-fallthrough
case Video.State.Partial: {
Expand All @@ -131,7 +132,7 @@ export class Video extends Attachment {
}
}
}
this.logger.done(chalk`{cyan Download & Muxing complete!}`);
this.logger.done(chalk`{cyan Downloaded!}`);
promDownloadedTotal.inc();
break;
} catch (err) {
Expand All @@ -141,8 +142,8 @@ export class Video extends Attachment {
}
} finally {
await Video.DownloadSemaphore.release();
promQueued.dec();
}
promQueued.dec();
}

private onError(err: unknown, throwAfterLog = false) {
Expand Down Expand Up @@ -213,6 +214,7 @@ export class Video extends Attachment {

public async saveNfo() {
if (await fileExists(this.nfoPath)) return;
this.logger.log("Saving .nfo");

let season = "";
let episode = "";
Expand Down Expand Up @@ -248,12 +250,14 @@ export class Video extends Attachment {
.end({ prettyPrint: true });
await fs.writeFile(this.nfoPath, nfo, "utf8");
await fs.utimes(this.nfoPath, new Date(), this.releaseDate);
this.logger.log("Saved .nfo");
}

public async downloadArtwork() {
if (!this.artworkUrl) return;
// If the file already exists
if (await this.artworkFileExtension()) return;
this.logger.log("Saving artwork");

// Fetch the thumbnail and get its content type
const response = await fApi.got(this.artworkUrl, { responseType: "buffer" });
Expand All @@ -268,6 +272,7 @@ export class Video extends Attachment {
// Save the thumbnail with the correct file extension
await fs.writeFile(artworkPathWithExtension, Uint8Array.from(response.body));
await fs.utimes(artworkPathWithExtension, new Date(), this.releaseDate);
this.logger.log("Saved artwork");
}

// The number of available slots for making delivery requests,
Expand Down

0 comments on commit 88c7197

Please sign in to comment.