Skip to content

Commit 925c966

Browse files
committed
refactor(graphql-api): Only download supported subs
This helps to prevent the ratelimit from open subtitles
1 parent 17f4a14 commit 925c966

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

apps/graphql-api/src/shared/subtitles/subtitles.service.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export class SubtitlesService {
1818

1919
private readonly enabled: boolean = true
2020

21+
/**
22+
* TODO:: Get from ENV
23+
*/
24+
private readonly supportedLanguages = [
25+
'en',
26+
'nl'
27+
]
28+
2129
constructor(
2230
private readonly httpService: HttpService,
2331
private readonly configService: ConfigService
@@ -83,7 +91,7 @@ export class SubtitlesService {
8391
limit: 'best'
8492
})
8593

86-
const subtitleLanguages = Object.keys(subtitles)
94+
const subtitleLanguages = Object.keys(subtitles).filter(lang => this.supportedLanguages.includes(lang))
8795

8896
if (subtitleLanguages.length > 0) {
8997
const formattedSubs = []
@@ -92,9 +100,9 @@ export class SubtitlesService {
92100

93101
await Promise.all(
94102
subtitleLanguages.map(async (language) => {
95-
try {
96-
const subtitle: SubtitleInterface = subtitles[language]
103+
const subtitle: SubtitleInterface = subtitles[language]
97104

105+
try {
98106
const subLocation = await this.downloadSubtitle(download, subtitle, location)
99107

100108
formattedSubs.push({
@@ -104,7 +112,7 @@ export class SubtitlesService {
104112
score: subtitle.score
105113
})
106114
} catch (err) {
107-
this.logger.error(`[${download._id}]: Could not download subtitle "${language}"`, err)
115+
this.logger.error(`[${download._id}]: Could not download subtitle "${language}" (${subtitle.url})`, err)
108116
}
109117
})
110118
)

apps/graphql-api/src/shared/torrent/torrent.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ export class TorrentService {
561561
/**
562562
* Cleans up a download
563563
*/
564-
public cleanUpDownload(download: Model<Download>, deleteDownload = false) {
564+
public cleanUpDownload(download: Model<Download>, deleteDownload = false): Promise<void> {
565565
return new Promise(async (resolve) => {
566566
if (deleteDownload) {
567567
// Delete the download

0 commit comments

Comments
 (0)