Skip to content

Commit

Permalink
Fix Video.onError not binding & fs.mkdir not called early enough
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Nov 1, 2024
1 parent e6c8ab2 commit 075249c
Show file tree
Hide file tree
Showing 2 changed files with 5 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.0",
"version": "5.16.1",
"private": true,
"type": "module",
"scripts": {
Expand Down
13 changes: 4 additions & 9 deletions src/lib/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ export class Video extends Attachment {

this.description = videoInfo.description;
this.artworkUrl = videoInfo.artworkUrl;
// Ensure onError is bound to this instance
this.onError = this.onError.bind(this);
}

public async download() {
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);
Expand Down Expand Up @@ -210,9 +214,6 @@ export class Video extends Attachment {
public async saveNfo() {
if (await fileExists(this.nfoPath)) return;

// Make sure the folder for the video exists
await fs.mkdir(this.folderPath, { recursive: true });

let season = "";
let episode = "";
const match = /S(\d+)E(\d+)/i.exec(this.nfoPath);
Expand Down Expand Up @@ -254,9 +255,6 @@ export class Video extends Attachment {
// If the file already exists
if (await this.artworkFileExtension()) return;

// Make sure the folder for the video exists
await fs.mkdir(this.folderPath, { recursive: true });

// Fetch the thumbnail and get its content type
const response = await fApi.got(this.artworkUrl, { responseType: "buffer" });
const contentType = response.headers["content-type"];
Expand Down Expand Up @@ -292,9 +290,6 @@ export class Video extends Attachment {
protected async getVideoStream(quality: string): Promise<ReturnType<typeof fApi.got.stream>> {
if ((await this.getState()) === VideoState.Muxed) throw new Error(`Attempting to download "${this.videoTitle}" video already downloaded!`);

// Make sure the folder for the video exists
await fs.mkdir(this.folderPath, { recursive: true });

const delivery = await this.getDelivery();
if (delivery?.origins === undefined) throw new Error("Video has no origins to download from!");

Expand Down

0 comments on commit 075249c

Please sign in to comment.