Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/lib/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Video extends Attachment {
private static readonly MaxRetries = 1;
private static readonly DownloadThreads = 8;

Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DownloadSemaphore is initialized at class load time using a static field, which means settings.downloadWaitTime is only read once when the class is first loaded. If the setting is changed at runtime (which appears to be supported by the @inrixia/db library with updateOnExternalChanges: true), the semaphore won't be reconfigured.

Consider either: (1) making this check dynamic rather than static initialization, or (2) documenting that changes to downloadWaitTime require a restart to take effect.

Suggested change
// NOTE: DownloadSemaphore is intentionally initialized at class load time.
// Changes to `settings.downloadWaitTime` at runtime (for example via
// @inrixia/db with `updateOnExternalChanges: true`) will NOT reconfigure
// this semaphore. A process restart is required for updates to take effect.

Copilot uses AI. Check for mistakes.
private static readonly DownloadSemaphore = new Semaphore(this.DownloadThreads);
private static readonly DownloadSemaphore = new Semaphore(settings.downloadWaitTime > 0 ? 1 : this.DownloadThreads);

private static readonly ThrottleOptions: ThrottleOptions = { rate: settings.maxDownloadSpeed * byteToMbits };
private static readonly ThrottleGroup = settings.maxDownloadSpeed > -1 ? new ThrottleGroup(Video.ThrottleOptions) : undefined;
Expand Down Expand Up @@ -155,6 +155,10 @@ export class Video extends Attachment {
} finally {
release();
promQueued.dec();
// Wait between downloads if downloadWaitTime is set
if (settings.downloadWaitTime > 0) {
await sleep(settings.downloadWaitTime * 1000);
}
Comment on lines 156 to +161
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sleep is called after the semaphore is released, which creates a race condition. When the semaphore is released at line 156, another download can immediately acquire it and start downloading before the current download completes its sleep. This defeats the purpose of the wait time.

The sleep should be moved before the release() call to ensure the wait time is enforced between downloads. Move lines 158-161 to before line 156.

Suggested change
release();
promQueued.dec();
// Wait between downloads if downloadWaitTime is set
if (settings.downloadWaitTime > 0) {
await sleep(settings.downloadWaitTime * 1000);
}
// Wait between downloads if downloadWaitTime is set
if (settings.downloadWaitTime > 0) {
await sleep(settings.downloadWaitTime * 1000);
}
release();
promQueued.dec();

Copilot uses AI. Check for mistakes.
}
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const defaultSettings: Settings = {
waitForNewVideos: true,
seekAndDestroy: [],
},
downloadWaitTime: 0,
maxDownloadSpeed: -1,
plex: {
sectionsToUpdate: [],
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type Settings = {
waitForNewVideos: boolean;
seekAndDestroy: string[];
};
downloadWaitTime: number;
maxDownloadSpeed: number;
filePathFormatting: string;
plex: PlexSettings;
Expand Down
11 changes: 11 additions & 0 deletions wiki/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ Added for Kodi support as Kodi looks for artwork in the format `VideoName-thumb.

<br>

**downloadWaitTime**:
Wait time (in seconds) between downloads. Default is 0 (disabled).
When set to a value greater than 0, downloads will be performed sequentially with the specified wait time between each download.
This helps prevent overloading the Floatplane servers with concurrent requests and reduces the risk of being rate-limited.

```json
"downloadWaitTime": 0
```

<br>

**maxDownloadSpeed**:
The maximum speed to download at in mbps.

Expand Down
Loading