feat: support TMDB IDs

This commit is contained in:
WebStreamr 2025-08-22 14:46:51 +00:00
parent eecd3255f0
commit c7c2ebf353
No known key found for this signature in database
3 changed files with 18 additions and 8 deletions

View file

@ -3,7 +3,7 @@ import { Request, Response, Router } from 'express';
import { ContentType } from 'stremio-addon-sdk';
import winston from 'winston';
import { Source } from '../source';
import { contextFromRequestAndResponse, envIsProd, ImdbId, StreamResolver } from '../utils';
import { contextFromRequestAndResponse, envIsProd, Id, ImdbId, StreamResolver, TmdbId } from '../utils';
const locks = new Map<string, Mutex>();
@ -27,22 +27,31 @@ export class StreamController {
private async getStream(req: Request, res: Response) {
const type: ContentType = (req.params['type'] || '') as ContentType;
const id: string = req.params['id'] || '';
const rawId: string = req.params['id'] || '';
let id: Id;
if (rawId.startsWith('tmdb:')) {
id = TmdbId.fromString(rawId.replace('tmdb:', ''));
} else if (rawId.startsWith('tt')) {
id = ImdbId.fromString(rawId);
} else {
throw new Error(`Unsupported ID: ${rawId}`);
}
const ctx = contextFromRequestAndResponse(req, res);
this.logger.info(`Search stream for type "${type}" and id "${id}" for ip ${ctx.ip}`, ctx);
this.logger.info(`Search stream for type "${type}" and id "${rawId}" for ip ${ctx.ip}`, ctx);
const sources = this.sources.filter(source => source.countryCodes.filter(countryCode => countryCode in ctx.config).length);
let mutex = locks.get(id);
let mutex = locks.get(rawId);
if (!mutex) {
mutex = new Mutex();
locks.set(id, mutex);
locks.set(rawId, mutex);
}
await mutex.runExclusive(async () => {
const { streams, ttl } = await this.streamResolver.resolve(ctx, sources, type, ImdbId.fromString(id));
const { streams, ttl } = await this.streamResolver.resolve(ctx, sources, type, id);
if (ttl && envIsProd()) {
res.setHeader('Cache-Control', `max-age=${ttl / 1000}, public`);
@ -53,7 +62,7 @@ export class StreamController {
});
if (!mutex.isLocked()) {
locks.delete(id);
locks.delete(rawId);
}
};
}

View file

@ -70,6 +70,7 @@ exports[`buildManifest default manifest 1`] = `
"description": "Provides HTTP URLs from streaming websites. Configure add-on for additional languages. Add MediaFlow proxy for more URLs. Supported languages: German, English, Castilian Spanish, French, Italian, Latin American Spanish",
"id": "webstreamr",
"idPrefixes": [
"tmdb:",
"tt",
],
"name": "WebStreamr",

View file

@ -21,7 +21,7 @@ export const buildManifest = (sources: Source[], extractors: Extractor[], config
'series',
],
catalogs: [],
idPrefixes: ['tt'],
idPrefixes: ['tmdb:', 'tt'],
behaviorHints: {
p2p: false,
configurable: true,