-
Notifications
You must be signed in to change notification settings - Fork 0
/
stremio.ts
536 lines (520 loc) · 14.2 KB
/
stremio.ts
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/**
* Adaptation of the index.d.ts file provided by @types/stremio-addon-sdk for exporting interfaces and types (for reuse)
*/
// Type definitions for stremio-addon-sdk 1.6
// Project: https://github.com/Stremio/stremio-addon-sdk#readme
// Definitions by: Sleeyax <https://github.com/sleeyax>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.4
export {};
export type ShortManifestResource = 'catalog' | 'meta' | 'stream' | 'subtitles' | 'addon_catalog';
export type Extra = 'search' | 'genre' | 'skip';
export type ContentType = 'movie' | 'series' | 'channel' | 'tv';
export interface Args {
type: ContentType;
id: string;
extra?: { search: string; genre: string; skip: number };
}
/**
* The addonInterface, as returned from builder.getInterface()
*/
export interface AddonInterface {
manifest: Manifest;
get: (args: { resource: ShortManifestResource } & Args) => Promise<any>;
}
/**
* A resolving object can also include the following cache related properties
*/
export interface Cache {
/**
* (in seconds) sets the Cache-Control header to max-age=$cacheMaxAge
* and overwrites the global cache time set in serveHTTP options.
*/
cacheMaxAge?: number;
/**
* (in seconds) sets the Cache-Control header to stale-while-revalidate=$staleRevalidate.
*/
staleRevalidate?: number;
/**
* (in seconds) sets the Cache-Control header to stale-if-error=$staleError.
*/
staleError?: number;
}
/**
* Summarized collection of meta items.
*
* Catalogs are displayed on the Stremio's Board, Discover and Search.
*/
export interface MetaPreview {
/**
* Universal identifier.
* You may use a prefix unique to your addon.
*
* Example: 'yt_id:UCrDkAvwZum-UTjHmzDI2iIw'
*/
id: string;
/**
* Type of the content.
*/
type: ContentType;
/**
* Name of the content.
*/
name: string;
/**
* URL to PNG of poster.
*
* Accepted aspect ratios: 1:0.675 (IMDb poster type) or 1:1 (square).
*
* You can use any resolution, as long as the file size is below 100kb.
* Below 50kb is recommended
*/
poster?: string;
/**
* Poster can be square (1:1 aspect) or regular (1:0.675) or landscape (1:1.77).
*
* Defaults to 'regular'.
*/
posterShape?: 'square' | 'regular' | 'landscape';
/**
* The background shown on the stremio detail page.
*
* Heavily encouraged if you want your content to look good.
*
* URL to PNG, max file size 500kb.
*/
background?: string;
/**
* The logo shown on the stremio detail page.
*
* Encouraged if you want your content to look good.
*
* URL to PNG.
*/
logo?: string;
/**
* A few sentences describing your content.
*/
description?: string;
}
/**
* Detailed description of a meta item.
*
* This description is displayed when the user selects an item form the catalog.
*/
export interface MetaDetail extends MetaPreview {
/**
* genre/categories of the content.
*
* e.g. ["Thriller", "Horror"]
*
* **WARNING: this will soon be deprecated, use 'links' instead**
*/
genres?: string[];
releaseInfo?: string;
/**
* Array of directors.
*
* Deprecated: use 'links' instead
*
* @deprecated
*/
director?: string[];
/**
* Array of members of the cast.
*
* use 'links' instead
*
* @deprecated
*/
cast?: string[];
/**
* IMDb rating, which should be a number from 0.0 to 10.0.
*/
imdbRating?: string;
/**
* ISO 8601, initial release date.
*
* For movies, this is the cinema debut.
*
* e.g. "2010-12-06T05:00:00.000Z"
*/
released?: string;
/**
* Can be used to link to internal pages of Stremio.
*
* example: array of actor / genre / director links.
*/
links?: MetaLink[];
/**
* Used for channel and series.
*
* If you do not provide this (e.g. for movie), Stremio assumes this meta item has one video, and it's ID is equal to the meta item id.
*/
videos?: MetaVideo[];
/**
* Human-readable expected runtime.
*
* e.g. "120m"
*/
runtime?: string;
/**
* Spoken language.
*/
language?: string;
/**
* Official country of origin.
*/
country?: string;
/**
* Human-readable that describes all the significant awards.
*/
awards?: string;
/**
* URL to official website.
*/
website?: string;
behaviourHints?: {
/**
* Set to a Video Object id in order to open the Detail page directly to that video's streams.
*/
defaultVideo?: boolean | string;
};
}
export interface MetaLink {
/**
* Human readable name for the link.
*/
name: string;
/**
* Any unique category name, links are grouped based on their category.
*
* Some recommended categories are: actor, director, writer,
* while the following categories are reserved and should not be used: imdb, share, similar.
*/
category: string;
/**
* An external URL or Meta Link.
*/
url: string;
}
export interface MetaVideo {
/**
* ID of the video.
*/
id: string;
/**
* Title of the video.
*/
title: string;
/**
* ISO 8601, publish date of the video.
*
* for episodes, this should be the initial air date.
*
* e.g. "2010-12-06T05:00:00.000Z"
*/
released: string;
/**
* URL to png of the video thumbnail, in the video's aspect ratio.
*
* max file size 5kb.
*/
thumbnail?: string;
/**
* In case you can return links to streams while forming meta response,
* you can pass and array of Stream Objects to point the video to a HTTP URL, BitTorrent,
* YouTube or any other stremio-supported transport protocol.
*
* Note that this is exclusive: passing video.streams means that Stremio will not request any streams
* from other addons for that video.
* If you return streams that way, it is still recommended to implement the streams resource.
*/
streams?: Stream[];
/**
* Set to true to explicitly state that this video is available for streaming, from your addon.
*
* No need to use this if you've passed stream.
*/
available?: boolean;
/**
* Episode number, if applicable.
*/
episode?: number;
/**
* Season number, if applicable.
*/
season?: number;
/**
* YouTube ID of the trailer video; use if this is an episode for a series.
*/
trailer?: string;
/**
* Video overview/summary
*/
overview?: string;
}
/**
* Tells Stremio how to obtain the media content.
*
* It may be torrent info hash, HTTP URL, etc.
*/
export interface Stream {
/**
* Direct URL to a video stream - http, https, rtmp protocols are supported.
*/
url?: string;
/**
* Youtube video ID, plays using the built-in YouTube player.
*/
ytId?: string;
/**
* Info hash of a torrent file, and fileIdx is the index of the video file within the torrent.
*
* If fileIdx is not specified, the largest file in the torrent will be selected.
*/
infoHash?: string;
/**
* The index of the video file within the torrent (from infoHash).
*
* If fileIdx is not specified, the largest file in the torrent will be selected.
*/
fileIdx?: number;
/**
* Meta Link or an external URL to the video, which should be opened in a browser (webpage).
*
* e.g. a link to Netflix.
*/
externalUrl?: string;
/**
* Title of the stream
*
* Usually used for stream quality.
*/
title?: string;
/**
* Name of the stream
*
* Usually a short name to identify the addon that provided the stream
*/
name?: string;
/**
* Array of Subtitle objects representing subtitles for this stream.
*/
subtitles?: Subtitle[];
behaviorHints?: {
/**
* Hints it's restricted to particular countries.
*
* Array of ISO 3166-1 alpha-3 country codes in lowercase in which the stream is accessible.
*/
countryWhitelist?: string[];
/**
* Applies if the protocol of the url is http(s).
*
* Needs to be set to true if the URL does not support https or is not an MP4 file.
*/
notWebReady?: boolean;
/**
* If defined, addons with the same behaviorHints.group will be chosen automatically for binge watching.
*
* This should be something that identifies the stream's nature within your addon.
* For example, if your addon is called "gobsAddon", and the stream is 720p, the group should be "gobsAddon-720p".
* If the next episode has a stream with the same group, stremio should select that stream implicitly.
*/
group?: string;
/**
* **Not implemented yet!**
*
* HTTP headers to use when trying to playback url.
* Only applies to urls.
*
* @ignore
*/
headers?: any;
};
}
/**
* Subtitles resource for the chosen media.
*/
export interface Subtitle {
/**
* Url to the subtitle file.
*/
url: string;
/**
* Language code for the subtitle, if a valid ISO 639-2 code is not sent, the text of this value will be used instead.
*/
lang: string;
}
/**
* The addon description and capabilities.
*
* The first thing to define for your addon is the manifest, which describes it's name, purpose and some technical details.
*/
export interface Manifest {
/**
* Identifier, dot-separated, e.g. "com.stremio.filmon"
*/
id: string;
/**
* Human readable name
*/
name: string;
/**
* Human readable description
*/
description: string;
/**
* Semantic version of the addon
*/
version: string;
/**
* Supported resources, defined as an array of objects (long version) or strings (short version).
*
* Example #1: [{"name": "stream", "types": ["movie"], "idPrefixes": ["tt"]}]
*
* Example #2: ["catalog", "meta", "stream", "subtitles", "addon_catalog"]
*/
resources: ShortManifestResource[] | FullManifestResource[];
/**
* Supported types.
*/
types: ContentType[];
/**
* Use this if you want your addon to be called only for specific content IDs.
*
* For example, if you set this to ["yt_id:", "tt"], your addon will only be called for id values that start with 'yt_id:' or 'tt'.
*/
idPrefixes?: string[];
/**
* A list of the content catalogs your addon provides.
*
* Leave this an empty array ([]) if your addon does not provide the catalog resource.
*/
catalogs: ManifestCatalog[];
/**
* Array of Catalog objects, a list of other addon manifests.
*
* This can be used for an addon to act just as a catalog of other addons.
*/
addonCatalogs?: ManifestCatalog[];
/**
* Background image for the addon.
*
* URL to png/jpg, at least 1024x786 resolution.
*/
background?: string;
/**
* Logo icon, URL to png, monochrome, 256x256.
*/
logo?: string;
/**
* Contact email for addon issues.
* Used for the Report button in the app.
* Also, the Stremio team may reach you on this email for anything relating your addon.
*/
contactEmail?: string;
behaviorHints?: {
/**
* If the addon includes adult content.
*
* Defaults to false.
*/
adult?: boolean;
/**
* If the addon includes P2P content, such as BitTorrent, which may reveal the user's IP to other streaming parties.
*
* Used to provide an adequate warning to the user.
*/
p2p?: boolean;
};
}
/**
* Used as a response for defineResourceHandler.
*/
export interface AddonCatalog {
/**
* only http is currently officially supported.
*/
transportName: string;
/**
* The URL of the addon's manifest.json file.
*/
transportUrl: string;
/**
* Object representing the addon's Manifest Object.
*/
manifest: Manifest;
}
export interface FullManifestResource {
/**
* Resource name.
*/
name: ShortManifestResource;
/**
* Supported types.
*/
types: ContentType[];
/**
* Use this if you want your addon to be called only for specific content IDs
*
* For example, if you set this to ["yt_id:", "tt"], your addon will only be called for id values that start with 'yt_id:' or 'tt'.
*/
idPrefixes?: string[];
}
export interface ManifestCatalog {
/**
* This is the content type of the catalog.
*/
type: ContentType;
/**
* The id of the catalog, can be any unique string describing the catalog (unique per addon, as an addon can have many catalogs).
*
* For example: if the catalog name is "Favourite Youtube Videos", the id can be "fav_youtube_videos".
*/
id: string;
/**
* Human readable name of the catalog.
*/
name: string;
/**
* Use the 'options' property of 'extra' instead.
* @deprecated
*/
genres?: string[];
/**
* All extra properties related to this catalog.
*/
extra?: ManifestExtra[];
}
export interface ManifestExtra {
/**
* The name of the property
*
* This name will be used in the extraProps argument itself.
*/
name: Extra;
/**
* Set to true if this property must always be passed.
*/
isRequired?: boolean;
/**
* Possible values for this property.
* This is useful for things like genres, where you need the user to select from a pre-set list of options.
*
* e.g. { name: "genre", options: ["Action", "Comedy", "Drama"] }
*
*
* It's also useful if we want to specify a limited number of pages (for the skip parameter).
*
* e.g. { name: "skip", options: ["0", "100", "200"] }
*/
options?: string[];
/**
* The limit of values a user may select from the pre-set options list
*
* By default this is set to 1.
*/
optionsLimit?: number;
}