Spaces:
Build error
Build error
File size: 4,724 Bytes
0bfe2e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
import {
Addon,
Option,
ParsedFile,
ParsedStream,
Stream,
UserData,
} from '../db';
import { Preset, baseOptions } from './preset';
import { constants, createLogger, Env } from '../utils';
import { debridioSocialOption } from './debridio';
import { FileParser, StreamParser } from '../parser';
const logger = createLogger('DebridioTvPreset');
class DebridioTvStreamParser extends StreamParser {
protected override getParsedFile(
stream: Stream,
parsedStream: ParsedStream
): ParsedFile | undefined {
const parsed = stream.name ? FileParser.parse(stream.name) : undefined;
if (!parsed) {
return undefined;
}
logger.debug(`resolution: ${parsed}`);
return {
...parsed,
title: undefined,
};
}
protected override getFilename(
stream: Stream,
currentParsedStream: ParsedStream
): string | undefined {
logger.debug('returning undefined for filename');
return undefined;
}
protected override getMessage(
stream: Stream,
currentParsedStream: ParsedStream
): string | undefined {
return `${stream.name} - ${stream.description}`;
}
}
export class DebridioTvPreset extends Preset {
static override getParser(): typeof StreamParser {
return DebridioTvStreamParser;
}
static override get METADATA() {
const supportedResources = [
constants.CATALOG_RESOURCE,
constants.META_RESOURCE,
constants.STREAM_RESOURCE,
];
const channels = [
{
label: 'USA',
value: 'usa',
},
{
label: 'Mexico',
value: 'mx',
},
{
label: 'UK',
value: 'uk',
},
{
label: 'France',
value: 'fr',
},
{
label: 'Chile',
value: 'cl',
},
{
label: 'Italy',
value: 'it',
},
{
label: 'Estonia',
value: 'ee',
},
];
const options: Option[] = [
...baseOptions(
'Debridio TV',
supportedResources,
Env.DEFAULT_DEBRIDIO_TV_TIMEOUT
),
{
id: 'debridioApiKey',
name: 'Debridio API Key',
description:
'Your Debridio API Key, located at your [account settings](https://debridio.com/account)',
type: 'password',
required: true,
},
{
id: 'channels',
name: 'Channels',
description: 'The channels to display',
type: 'multi-select',
required: true,
options: channels,
default: channels.map((channel) => channel.value),
},
debridioSocialOption,
];
return {
ID: 'debridio-tv',
NAME: 'Debridio TV',
LOGO: 'https://res.cloudinary.com/adobotec/image/upload/w_120,h_120/v1735925306/debridio/logo.png.png',
URL: Env.DEBRIDIO_TV_URL,
TIMEOUT: Env.DEFAULT_DEBRIDIO_TV_TIMEOUT || Env.DEFAULT_TIMEOUT,
USER_AGENT: Env.DEFAULT_DEBRIDIO_TV_USER_AGENT || Env.DEFAULT_USER_AGENT,
SUPPORTED_SERVICES: [],
DESCRIPTION: 'Live streaming of a wide variety of channels.',
OPTIONS: options,
SUPPORTED_STREAM_TYPES: [constants.LIVE_STREAM_TYPE],
SUPPORTED_RESOURCES: supportedResources,
};
}
static async generateAddons(
userData: UserData,
options: Record<string, any>
): Promise<Addon[]> {
if (!options.url && !options.debridioApiKey) {
throw new Error(
'To access the Debridio addons, you must provide your Debridio API Key'
);
}
return [this.generateAddon(userData, options)];
}
private static generateAddon(
userData: UserData,
options: Record<string, any>
): Addon {
let url = this.METADATA.URL;
if (options.url?.endsWith('/manifest.json')) {
url = options.url;
} else {
let baseUrl = this.METADATA.URL;
if (options.url) {
baseUrl = new URL(options.url).origin;
}
// remove trailing slash
baseUrl = baseUrl.replace(/\/$/, '');
if (!options.debridioApiKey) {
throw new Error(
'To access the Debridio addons, you must provide your Debridio API Key'
);
}
const config = this.base64EncodeJSON({
api_key: options.debridioApiKey,
channels: options.channels,
});
url = `${baseUrl}/${config}/manifest.json`;
}
return {
name: options.name || this.METADATA.NAME,
manifestUrl: url,
enabled: true,
library: false,
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
timeout: options.timeout || this.METADATA.TIMEOUT,
presetType: this.METADATA.ID,
presetInstanceId: '',
headers: {
'User-Agent': this.METADATA.USER_AGENT,
},
};
}
}
|