Skip to content

Commit e2d59dc

Browse files
committed
torrent timeout
1 parent 19009d2 commit e2d59dc

7 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ services:
239239
- TORRENT_USER=<your-username-here>
240240
- TORRENT_PASSWORD=<your-password-here>
241241
- TORRENT_CLIENT=qbittorrent
242+
#- TORRENT_CLIENT_TIMEOUT=10
242243
#- TORRENT_CATEGORY_FORCE=false
243244
#- TORRENT_CATEGORY=onepacerr
244245
#- TORRENT_CATEGORY_ONCE_COMPLETED=completed
@@ -425,10 +426,11 @@ If you set `LIBRARY_MEDIA_SERVER=false`, you can instead generate those files re
425426
| ⭐ `TORRENT_URL` | `http://localhost:8080` | Your torrent API URL. |
426427
| ⭐ `TORRENT_USER` | _None_ | Your torrent API username. |
427428
| ⭐ `TORRENT_PASSWORD` | _None_ | Your torrent API password. |
429+
| `TORRENT_CLIENT_TIMEOUT` | 10 | Seconds to wait for torrent client to respond to requests, increase if you have a LOT of torrents. |
428430
| `TORRENT_CATEGORY_FORCE` | `false` | If `true`, when trying to add a torrent also forces a category update if torrent already exists with a different category. |
429431
| `TORRENT_CATEGORY` | `onepacerr` | Creates downloads with this category, also filters completed torrents using this. |
430432
| `TORRENT_CATEGORY_ONCE_COMPLETED` | `completed` | After processing completed downloads, changes the torrent category to this one. |
431-
| `TORRENT_CHECK_INTERVAL` | `60` | Seconds between checking for completed downloads. |
433+
| `TORRENT_CHECK_INTERVAL` | 60 | Seconds between checking for completed downloads. |
432434

433435
---
434436

@@ -450,7 +452,7 @@ If you set `LIBRARY_MEDIA_SERVER=false`, you can instead generate those files re
450452
| `METADATA_URL` | `https://raw.githubusercontent.com/ladyisatis/one-pace-metadata/refs/heads/v2/metadata/data.json` | Metadata url (untested with different ones). |
451453
| `METADATA_LANGUAGE` | `en` | Currently only language supported. |
452454
| `METADATA_POSTER_SET` | `default` | Currently `default` equals `piratezekk`. There are also `official` and `mizzoufan523` available. If a set is missing a poster it uses `default`. |
453-
| `METADATA_CHECK_INTERVAL` | `3600` | Seconds between checking for new metadata. |
455+
| `METADATA_CHECK_INTERVAL` | 3600 | Seconds between checking for new metadata. |
454456

455457
---
456458

‎sample.env‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ TORRENT_PASSWORD=<your-password-here>
125125

126126
# Your torrent client. Will be used in the future to use different clients rather tnax qBittorrent.
127127
TORRENT_CLIENT=qbittorrent
128+
# Seconds to wait for torrent client to respond to requests, increase if you have a LOT of torrents.
129+
TORRENT_CLIENT_TIMEOUT=10
128130

129131
# If `true`, when trying to add a torrent also forces a category update if torrent already exists with a different category.
130132
TORRENT_CATEGORY_FORCE=false

‎src/environment.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export default {
103103
TORRENT_PASSWORD: process.env.TORRENT_PASSWORD || `password`,
104104

105105
TORRENT_CLIENT: process.env.TORRENT_CLIENT || `qbittorrent`,
106+
TORRENT_CLIENT_TIMEOUT:
107+
Number.parseInt(process.env.TORRENT_CLIENT_TIMEOUT || '10') * 1000,
106108

107109
TORRENT_CATEGORY_FORCE: /true/i.test(
108110
process.env.TORRENT_CATEGORY_FORCE || 'false',

‎src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const startApp = async () => {
6868
e instanceof LabelsDisabledInDelugeError ||
6969
e instanceof TorrentConnectionError
7070
) {
71-
Logger.debug(`Error handled, no need tO crash...`)
71+
Logger.debug(`Error handled, no need to crash...`)
7272
} else {
7373
Logger.error('APPLICATION CRASHED UNEXPECTEDLY...')
7474
Logger.error(e)

‎src/metadata/metadata.controller.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818

1919
export class MetadataController {
2020
private metadata: Metadata
21+
private reprocess: boolean
2122

2223
private TVShowNFO
2324
private seasonNFOs = {}
@@ -37,12 +38,25 @@ export class MetadataController {
3738
Logger.info(`Newer Metadata found!`)
3839
this.metadata = metadata
3940
newMetadata = true
41+
} else if (this.reprocess) {
42+
Logger.info(`Reprocessing Metadata due to previous errors!`)
43+
this.reprocess = false
44+
newMetadata = true
4045
}
4146
} catch (e) {
4247
Logger.error(`Error refreshing Metadata, will retry...`)
4348
Logger.error(e)
4449
}
4550

51+
try {
52+
if (newMetadata) await this.processMetadataEpisodes()
53+
} catch (e) {
54+
//TODO refactor checkMetadataDownloaded and create a queue of failedToProcess to only retry those
55+
Logger.error(
56+
`Unexpected error encountered when processing metadata, we will attempt to reprocess it again next cycle...`,
57+
)
58+
this.reprocess = true
59+
}
4660
if (newMetadata) await this.processMetadataEpisodes()
4761

4862
setTimeout(async () => {

‎src/torrent/clients/deluge.controller.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export class DelugeController implements ITorrentController {
1818
username: string
1919
password: string
2020
}) {
21-
this.client = new Deluge(options)
21+
this.client = new Deluge({
22+
...options,
23+
timeout: environment.TORRENT_CLIENT_TIMEOUT,
24+
})
2225
}
2326

2427
public async addTorrent(

‎src/torrent/clients/qbittorrent.controller.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export class qBittorrentController implements ITorrentController {
2222
username: string
2323
password: string
2424
}) {
25-
this.client = new QBittorrent(options)
25+
this.client = new QBittorrent({
26+
...options,
27+
timeout: environment.TORRENT_CLIENT_TIMEOUT,
28+
})
2629
}
2730

2831
public async addTorrent(

0 commit comments

Comments
 (0)