Skip to content

Commit 2627406

Browse files
committed
Add an option to disable opensubtitles in runners
1 parent 0c7f65e commit 2627406

File tree

3 files changed

+55
-36
lines changed

3 files changed

+55
-36
lines changed

src/entrypoint/controls.ts

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export interface RunnerOptions {
3131

3232
// the media you want to see sources from
3333
media: ScrapeMedia;
34+
35+
// it makes sense to have this in the builder
36+
// but I belive it's more useful in runner ops
37+
disableOpensubtitles?: boolean;
3438
}
3539

3640
export interface SourceRunnerOptions {
@@ -42,6 +46,10 @@ export interface SourceRunnerOptions {
4246

4347
// id of the source scraper you want to scrape from
4448
id: string;
49+
50+
// it makes sense to have this in the builder
51+
// but I belive it's more useful in runner ops
52+
disableOpensubtitles?: boolean;
4553
}
4654

4755
export interface EmbedRunnerOptions {
@@ -53,6 +61,10 @@ export interface EmbedRunnerOptions {
5361

5462
// id of the embed scraper you want to scrape from
5563
id: string;
64+
65+
// it makes sense to have this in the builder
66+
// but I belive it's more useful in runner ops
67+
disableOpensubtitles?: boolean;
5668
}
5769

5870
export interface ProviderControls {

src/runners/individualRunner.ts

+22-18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type IndividualSourceRunnerOptions = {
1818
id: string;
1919
events?: IndividualScraperEvents;
2020
proxyStreams?: boolean; // temporary
21+
disableOpensubtitles?: boolean;
2122
};
2223

2324
export async function scrapeInvidualSource(
@@ -74,12 +75,13 @@ export async function scrapeInvidualSource(
7475
});
7576

7677
// opensubtitles
77-
for (const embed of output.embeds)
78-
embed.url = `${embed.url}${btoa('MEDIA=')}${btoa(
79-
`${ops.media.imdbId}${
80-
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
81-
}`,
82-
)}`;
78+
if (!ops.disableOpensubtitles)
79+
for (const embed of output.embeds)
80+
embed.url = `${embed.url}${btoa('MEDIA=')}${btoa(
81+
`${ops.media.imdbId}${
82+
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
83+
}`,
84+
)}`;
8385

8486
if ((!output.stream || output.stream.length === 0) && output.embeds.length === 0)
8587
throw new NotFoundError('No streams found');
@@ -90,17 +92,18 @@ export async function scrapeInvidualSource(
9092
if (playableStreams.length === 0) throw new NotFoundError('No playable streams found');
9193

9294
// opensubtitles
93-
for (const playableStream of playableStreams) {
94-
playableStream.captions = await addOpenSubtitlesCaptions(
95-
playableStream.captions,
96-
ops,
97-
btoa(
98-
`${ops.media.imdbId}${
99-
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
100-
}`,
101-
),
102-
);
103-
}
95+
if (!ops.disableOpensubtitles)
96+
for (const playableStream of playableStreams) {
97+
playableStream.captions = await addOpenSubtitlesCaptions(
98+
playableStream.captions,
99+
ops,
100+
btoa(
101+
`${ops.media.imdbId}${
102+
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
103+
}`,
104+
),
105+
);
106+
}
104107
output.stream = playableStreams;
105108
}
106109
return output;
@@ -114,6 +117,7 @@ export type IndividualEmbedRunnerOptions = {
114117
id: string;
115118
events?: IndividualScraperEvents;
116119
proxyStreams?: boolean; // temporary
120+
disableOpensubtitles?: boolean;
117121
};
118122

119123
export async function scrapeIndividualEmbed(
@@ -152,7 +156,7 @@ export async function scrapeIndividualEmbed(
152156
const playableStreams = await validatePlayableStreams(output.stream, ops, embedScraper.id);
153157
if (playableStreams.length === 0) throw new NotFoundError('No playable streams found');
154158

155-
if (media)
159+
if (media && !ops.disableOpensubtitles)
156160
for (const playableStream of playableStreams)
157161
playableStream.captions = await addOpenSubtitlesCaptions(playableStream.captions, ops, media);
158162

src/runners/runner.ts

+21-18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type ProviderRunnerOptions = {
3838
events?: FullScraperEvents;
3939
media: ScrapeMedia;
4040
proxyStreams?: boolean; // temporary
41+
disableOpensubtitles?: boolean;
4142
};
4243

4344
export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOptions): Promise<RunOutput | null> {
@@ -115,15 +116,16 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
115116
if (!playableStream) throw new NotFoundError('No streams found');
116117

117118
// opensubtitles
118-
playableStream.captions = await addOpenSubtitlesCaptions(
119-
playableStream.captions,
120-
ops,
121-
btoa(
122-
`${ops.media.imdbId}${
123-
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
124-
}`,
125-
),
126-
);
119+
if (!ops.disableOpensubtitles)
120+
playableStream.captions = await addOpenSubtitlesCaptions(
121+
playableStream.captions,
122+
ops,
123+
btoa(
124+
`${ops.media.imdbId}${
125+
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
126+
}`,
127+
),
128+
);
127129

128130
return {
129131
sourceId: source.id,
@@ -177,15 +179,16 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
177179
if (!playableStream) throw new NotFoundError('No streams found');
178180

179181
// opensubtitles
180-
playableStream.captions = await addOpenSubtitlesCaptions(
181-
playableStream.captions,
182-
ops,
183-
btoa(
184-
`${ops.media.imdbId}${
185-
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
186-
}`,
187-
),
188-
);
182+
if (!ops.disableOpensubtitles)
183+
playableStream.captions = await addOpenSubtitlesCaptions(
184+
playableStream.captions,
185+
ops,
186+
btoa(
187+
`${ops.media.imdbId}${
188+
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
189+
}`,
190+
),
191+
);
189192
embedOutput.stream = [playableStream];
190193
} catch (error) {
191194
const updateParams: UpdateEvent = {

0 commit comments

Comments
 (0)