File size: 7,091 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import { Addon, Option, UserData, Resource, Stream, ParsedStream } from '../db';
import { Preset, baseOptions } from './preset';
import { Env, SERVICE_DETAILS } from '../utils';
import { constants, ServiceId } from '../utils';
import { FileParser, StreamParser } from '../parser';

class NuvioStreamsStreamParser extends StreamParser {
  parse(stream: Stream): ParsedStream {
    let parsedStream: ParsedStream = {
      id: this.getRandomId(),
      addon: this.addon,
      type: 'http',
      url: this.applyUrlModifications(stream.url ?? undefined),
      externalUrl: stream.externalUrl ?? undefined,
      ytId: stream.ytId ?? undefined,
      requestHeaders: stream.behaviorHints?.proxyHeaders?.request,
      responseHeaders: stream.behaviorHints?.proxyHeaders?.response,
      notWebReady: stream.behaviorHints?.notWebReady ?? undefined,
      videoHash: stream.behaviorHints?.videoHash ?? undefined,
      originalName: stream.name ?? undefined,
      originalDescription: (stream.description || stream.title) ?? undefined,
    };

    stream.description = stream.description || stream.title;

    parsedStream.type = 'http';

    parsedStream.parsedFile = FileParser.parse(
      `${stream.name}\n${stream.description}`
    );
    parsedStream.filename = stream.description?.split('\n')[0];
    parsedStream.folderName = undefined;

    parsedStream.size = this.getSize(stream, parsedStream);

    parsedStream.message = stream.name
      ?.replace(/\d+p?/gi, '')
      ?.trim()
      ?.replace(/-$/, '')
      ?.trim();

    if (stream.description?.split('\n')?.[-1]?.includes('⚠️')) {
      parsedStream.message += `\n${stream.description?.split('\n')?.[-1]}`;
    }

    return parsedStream;
  }
}

export class NuvioStreamsPreset extends Preset {
  static override getParser(): typeof StreamParser {
    return NuvioStreamsStreamParser;
  }

  static override get METADATA() {
    const supportedResources = [constants.STREAM_RESOURCE];
    const regions = [
      {
        value: 'USA7',
        label: 'USA East',
      },
      {
        value: 'USA6',
        label: 'USA West',
      },
      {
        value: 'USA5',
        label: 'USA Middle',
      },
      {
        value: 'UK3',
        label: 'United Kingdom',
      },
      {
        value: 'CA1',
        label: 'Canada',
      },
      {
        value: 'FR1',
        label: 'France',
      },
      {
        value: 'DE2',
        label: 'Germany',
      },
      {
        value: 'HK1',
        label: 'Hong Kong',
      },
      {
        value: 'IN1',
        label: 'India',
      },
      {
        value: 'AU1',
        label: 'Australia',
      },
      {
        value: 'SZ',
        label: 'China',
      },
    ];
    const providers = [
      {
        value: 'showbox',
        label: 'Showbox',
      },
      {
        value: 'xprime',
        label: 'XPrime',
      },
      {
        value: 'hollymoviehd',
        label: 'HollyMovieHD',
      },
      {
        value: 'cuevana',
        label: 'Cuevana',
      },
      {
        value: 'soapertv',
        label: 'Soapertv',
      },
      {
        value: 'vidzee',
        label: 'Vidzee',
      },
      {
        value: 'hianime',
        label: 'HiAnime',
      },
      {
        value: 'vidsrc',
        label: 'Vidsrc',
      },
    ];

    const options: Option[] = [
      ...baseOptions(
        'Nuvio Streams',
        supportedResources,
        Env.DEFAULT_NUVIOSTREAMS_TIMEOUT
      ),
      {
        id: 'scraperApiKey',
        name: 'Scraper API Key',
        description:
          'Optionally provide a [ScraperAPI](https://www.scraperapi.com/) API Key from',
        type: 'password',
        required: false,
        default: '',
      },
      {
        id: 'showBoxCookie',
        name: 'ShowBox Cookie',
        description:
          'The cookie for the ShowBox provider. Highly recommended to get streams greater than 9GB. Log in at [Febbox](https://www.febbox.com/) > DevTools > Storage > Cookied > Copy the value of the `ui` cookie. ',
        type: 'password',
        required: false,
        default: '',
      },
      {
        id: 'showBoxRegion',
        name: 'ShowBox Region',
        description: 'The region to use for the ShowBox provider',
        type: 'select',
        required: false,
        options: regions,
        default: regions[0].value,
      },
      {
        id: 'providers',
        name: 'Providers',
        description: 'The providers to use',
        type: 'multi-select',
        required: true,
        options: providers,
        default: providers.map((provider) => provider.value),
      },
      {
        id: 'socials',
        name: '',
        description: '',
        type: 'socials',
        socials: [
          { id: 'github', url: 'https://github.com/tapframe/NuvioStreaming' },
          { id: 'ko-fi', url: 'https://ko-fi.com/tapframe' },
        ],
      },
    ];

    return {
      ID: 'nuvio-streams',
      NAME: 'Nuvio Streams',
      LOGO: 'https://raw.githubusercontent.com/tapframe/NuvioStreaming/main/assets/titlelogo.png',
      URL: Env.NUVIOSTREAMS_URL,
      TIMEOUT: Env.DEFAULT_NUVIOSTREAMS_TIMEOUT || Env.DEFAULT_TIMEOUT,
      USER_AGENT: Env.DEFAULT_NUVIOSTREAMS_USER_AGENT || Env.DEFAULT_USER_AGENT,
      SUPPORTED_SERVICES: [],
      DESCRIPTION: 'Free high quality streaming using multiple providers. ',
      OPTIONS: options,
      SUPPORTED_STREAM_TYPES: [constants.HTTP_STREAM_TYPE],
      SUPPORTED_RESOURCES: supportedResources,
    };
  }

  static async generateAddons(
    userData: UserData,
    options: Record<string, any>
  ): Promise<Addon[]> {
    return [this.generateAddon(userData, options)];
  }

  private static generateAddon(
    userData: UserData,
    options: Record<string, any>
  ): Addon {
    return {
      name: options.name || this.METADATA.NAME,
      manifestUrl: this.generateManifestUrl(userData, options),
      enabled: true,
      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,
      },
    };
  }

  private static generateManifestUrl(
    userData: UserData,
    options: Record<string, any>
  ) {
    let url = options.url || this.METADATA.URL;
    if (url.endsWith('/manifest.json')) {
      return url;
    }
    url = url.replace(/\/$/, '');
    const cookie = options.showBoxCookie;
    const providers = options.providers;
    const scraperApiKey = options.scraperApiKey;
    let config = [];
    if (cookie) {
      config.push(['cookie', cookie]);
    }
    if (options.showBoxRegion) {
      config.push(['region', options.showBoxRegion]);
    }
    if (providers) {
      config.push(['providers', providers.join(',')]);
    }
    if (scraperApiKey) {
      config.push(['scraper_api_key', scraperApiKey]);
    }

    const configString = this.urlEncodeKeyValuePairs(config, '/', false);

    return `${url}${configString ? '/' + configString : ''}/manifest.json`;
  }
}