Skip to content

Commit

Permalink
feat(api): Made supported subs configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Oct 12, 2020
1 parent c32ccfb commit f3ffc19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 6 additions & 1 deletion apps/api/src/shared/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class ConfigService {
public static readonly DOWNLOAD_LOCATION: string = 'DOWNLOAD_LOCATION'
public static readonly OPENSUBTITLES_USERNAME: string = 'OPENSUBTITLES_USERNAME'
public static readonly OPENSUBTITLES_PASSWORD: string = 'OPENSUBTITLES_PASSWORD'
public static readonly SUBTITLES_LANGUAGES: string = 'SUBTITLES_LANGUAGES'
public static readonly MAX_CONCURRENT_DOWNLOADS: string = 'MAX_CONCURRENT_DOWNLOADS'
public static readonly TRAKT_KEY: string = 'TRAKT_KEY'

Expand Down Expand Up @@ -103,7 +104,11 @@ export class ConfigService {

[ConfigService.OPENSUBTITLES_USERNAME]: Joi.string(),

[ConfigService.OPENSUBTITLES_PASSWORD]: Joi.string()
[ConfigService.OPENSUBTITLES_PASSWORD]: Joi.string(),

[ConfigService.SUBTITLES_LANGUAGES]: Joi.string()
.default('en'),

[ConfigService.MAX_CONCURRENT_DOWNLOADS]: Joi.number()
.default(1),
})
Expand Down
11 changes: 3 additions & 8 deletions apps/api/src/shared/subtitles/subtitles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ export class SubtitlesService {

private readonly enabled: boolean = true

/**
* TODO:: Get from ENV
*/
private readonly supportedLanguages = [
'en',
'nl'
]
private readonly supportedLanguages

constructor(
private readonly httpService: HttpService,
private readonly configService: ConfigService
) {
const username = this.configService.get(ConfigService.OPENSUBTITLES_USERNAME)
const password = this.configService.get(ConfigService.OPENSUBTITLES_PASSWORD)
this.supportedLanguages = this.configService.get(ConfigService.SUBTITLES_LANGUAGES)

if (username && password) {
this.client = new OpenSubtitles({
Expand All @@ -52,7 +47,7 @@ export class SubtitlesService {
* @param {TorrentFile} torrent - The torrent to search subtitles for.
* @param {boolean} retry - Are we allowed to retry or not.
*/
public async searchForSubtitles(download: Model<Download>, torrent: TorrentFile, retry = true) {
public async searchForSubtitles(download: Model<Download>, torrent: TorrentFile, retry = true): Promise<void> {
// Only search for subtitles when it's enabled
if (!this.enabled) {
return
Expand Down

0 comments on commit f3ffc19

Please sign in to comment.