@letsmoe/otter-sdk 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,11 +8,12 @@ export default {
8
8
  6,
9
9
  25,
10
10
  27,
11
- 34,
12
- 36,
13
- 38,
14
- 43,
15
- 44
11
+ 35,
12
+ 37,
13
+ 39,
14
+ 44,
15
+ 45,
16
+ 50
16
17
  ],
17
18
  "types": {
18
19
  "MediaType": {},
@@ -130,6 +131,15 @@ export default {
130
131
  ]
131
132
  }
132
133
  ],
134
+ "notifying": [
135
+ 6,
136
+ {
137
+ "profileId": [
138
+ 2,
139
+ "ID!"
140
+ ]
141
+ }
142
+ ],
133
143
  "__typename": [
134
144
  4
135
145
  ]
@@ -607,6 +617,12 @@ export default {
607
617
  "requireVpn": [
608
618
  6
609
619
  ],
620
+ "errorReporting": [
621
+ 6
622
+ ],
623
+ "castLogs": [
624
+ 6
625
+ ],
610
626
  "disabledPlugins": [
611
627
  4
612
628
  ],
@@ -627,6 +643,12 @@ export default {
627
643
  "requireVpn": [
628
644
  6
629
645
  ],
646
+ "errorReporting": [
647
+ 6
648
+ ],
649
+ "castLogs": [
650
+ 6
651
+ ],
630
652
  "__typename": [
631
653
  4
632
654
  ]
@@ -696,6 +718,26 @@ export default {
696
718
  "settings": [
697
719
  30
698
720
  ],
721
+ "account": [
722
+ 33
723
+ ],
724
+ "__typename": [
725
+ 4
726
+ ]
727
+ },
728
+ "PluginAccount": {
729
+ "signupUrl": [
730
+ 4
731
+ ],
732
+ "username": [
733
+ 4
734
+ ],
735
+ "loggedIn": [
736
+ 6
737
+ ],
738
+ "error": [
739
+ 4
740
+ ],
699
741
  "__typename": [
700
742
  4
701
743
  ]
@@ -704,9 +746,15 @@ export default {
704
746
  "tmdbConfigured": [
705
747
  6
706
748
  ],
749
+ "tmdbReachable": [
750
+ 6
751
+ ],
707
752
  "vpnConnected": [
708
753
  6
709
754
  ],
755
+ "vpnBypassed": [
756
+ 6
757
+ ],
710
758
  "requireVpn": [
711
759
  6
712
760
  ],
@@ -720,7 +768,7 @@ export default {
720
768
  2
721
769
  ],
722
770
  "kind": [
723
- 34
771
+ 35
724
772
  ],
725
773
  "heading": [
726
774
  4
@@ -750,7 +798,7 @@ export default {
750
798
  2
751
799
  ],
752
800
  "status": [
753
- 36
801
+ 37
754
802
  ],
755
803
  "progress": [
756
804
  5
@@ -803,13 +851,13 @@ export default {
803
851
  6
804
852
  ],
805
853
  "status": [
806
- 38
854
+ 39
807
855
  ],
808
856
  "self": [
809
- 39
857
+ 40
810
858
  ],
811
859
  "peers": [
812
- 39
860
+ 40
813
861
  ],
814
862
  "__typename": [
815
863
  4
@@ -817,7 +865,7 @@ export default {
817
865
  },
818
866
  "TogetherMessage": {
819
867
  "from": [
820
- 39
868
+ 40
821
869
  ],
822
870
  "payload": [
823
871
  4
@@ -828,10 +876,10 @@ export default {
828
876
  },
829
877
  "TogetherUpdate": {
830
878
  "room": [
831
- 40
879
+ 41
832
880
  ],
833
881
  "message": [
834
- 41
882
+ 42
835
883
  ],
836
884
  "__typename": [
837
885
  4
@@ -971,7 +1019,7 @@ export default {
971
1019
  "MediaType!"
972
1020
  ],
973
1021
  "sort": [
974
- 43
1022
+ 44
975
1023
  ]
976
1024
  }
977
1025
  ],
@@ -983,13 +1031,13 @@ export default {
983
1031
  "MediaType!"
984
1032
  ],
985
1033
  "theme": [
986
- 44,
1034
+ 45,
987
1035
  "CatalogTheme!"
988
1036
  ]
989
1037
  }
990
1038
  ],
991
1039
  "catalogRows": [
992
- 45,
1040
+ 46,
993
1041
  {
994
1042
  "mediaType": [
995
1043
  0,
@@ -1086,7 +1134,7 @@ export default {
1086
1134
  }
1087
1135
  ],
1088
1136
  "notifications": [
1089
- 35,
1137
+ 36,
1090
1138
  {
1091
1139
  "profileId": [
1092
1140
  2,
@@ -1107,7 +1155,7 @@ export default {
1107
1155
  }
1108
1156
  ],
1109
1157
  "downloads": [
1110
- 37,
1158
+ 38,
1111
1159
  {
1112
1160
  "profileId": [
1113
1161
  2,
@@ -1119,7 +1167,7 @@ export default {
1119
1167
  4
1120
1168
  ],
1121
1169
  "togetherRoom": [
1122
- 40
1170
+ 41
1123
1171
  ],
1124
1172
  "subtitles": [
1125
1173
  24,
@@ -1152,13 +1200,104 @@ export default {
1152
1200
  32
1153
1201
  ],
1154
1202
  "status": [
1155
- 33
1203
+ 34
1204
+ ],
1205
+ "neoworksAccount": [
1206
+ 48
1207
+ ],
1208
+ "__typename": [
1209
+ 4
1210
+ ]
1211
+ },
1212
+ "NeoworksAccount": {
1213
+ "signedIn": [
1214
+ 6
1215
+ ],
1216
+ "email": [
1217
+ 4
1218
+ ],
1219
+ "name": [
1220
+ 4
1221
+ ],
1222
+ "lastSync": [
1223
+ 49
1224
+ ],
1225
+ "__typename": [
1226
+ 4
1227
+ ]
1228
+ },
1229
+ "NeoworksSync": {
1230
+ "at": [
1231
+ 4
1232
+ ],
1233
+ "received": [
1234
+ 3
1235
+ ],
1236
+ "sent": [
1237
+ 3
1238
+ ],
1239
+ "failure": [
1240
+ 4
1241
+ ],
1242
+ "__typename": [
1243
+ 4
1244
+ ]
1245
+ },
1246
+ "ChallengeKind": {},
1247
+ "Challenge": {
1248
+ "id": [
1249
+ 2
1250
+ ],
1251
+ "kind": [
1252
+ 50
1253
+ ],
1254
+ "url": [
1255
+ 4
1256
+ ],
1257
+ "domain": [
1258
+ 4
1259
+ ],
1260
+ "interactive": [
1261
+ 6
1156
1262
  ],
1157
1263
  "__typename": [
1158
1264
  4
1159
1265
  ]
1160
1266
  },
1161
1267
  "Mutation": {
1268
+ "completeChallenge": [
1269
+ 6,
1270
+ {
1271
+ "id": [
1272
+ 2,
1273
+ "ID!"
1274
+ ],
1275
+ "cookies": [
1276
+ 4,
1277
+ "String!"
1278
+ ],
1279
+ "userAgent": [
1280
+ 4,
1281
+ "String!"
1282
+ ],
1283
+ "finalUrl": [
1284
+ 4
1285
+ ]
1286
+ }
1287
+ ],
1288
+ "failChallenge": [
1289
+ 6,
1290
+ {
1291
+ "id": [
1292
+ 2,
1293
+ "ID!"
1294
+ ],
1295
+ "reason": [
1296
+ 4,
1297
+ "String!"
1298
+ ]
1299
+ }
1300
+ ],
1162
1301
  "findStreams": [
1163
1302
  6,
1164
1303
  {
@@ -1263,6 +1402,23 @@ export default {
1263
1402
  ]
1264
1403
  }
1265
1404
  ],
1405
+ "setNotifying": [
1406
+ 6,
1407
+ {
1408
+ "profileId": [
1409
+ 2,
1410
+ "ID!"
1411
+ ],
1412
+ "mediaId": [
1413
+ 2,
1414
+ "ID!"
1415
+ ],
1416
+ "notifying": [
1417
+ 6,
1418
+ "Boolean!"
1419
+ ]
1420
+ }
1421
+ ],
1266
1422
  "markNotificationsRead": [
1267
1423
  6,
1268
1424
  {
@@ -1272,8 +1428,11 @@ export default {
1272
1428
  ]
1273
1429
  }
1274
1430
  ],
1431
+ "checkNotifications": [
1432
+ 6
1433
+ ],
1275
1434
  "startDownload": [
1276
- 37,
1435
+ 38,
1277
1436
  {
1278
1437
  "profileId": [
1279
1438
  2,
@@ -1301,7 +1460,7 @@ export default {
1301
1460
  6
1302
1461
  ],
1303
1462
  "hostTogether": [
1304
- 40,
1463
+ 41,
1305
1464
  {
1306
1465
  "profileId": [
1307
1466
  2,
@@ -1310,7 +1469,7 @@ export default {
1310
1469
  }
1311
1470
  ],
1312
1471
  "joinTogether": [
1313
- 40,
1472
+ 41,
1314
1473
  {
1315
1474
  "profileId": [
1316
1475
  2,
@@ -1444,6 +1603,9 @@ export default {
1444
1603
  ]
1445
1604
  }
1446
1605
  ],
1606
+ "checkTmdbConnection": [
1607
+ 6
1608
+ ],
1447
1609
  "setPluginEnabled": [
1448
1610
  32,
1449
1611
  {
@@ -1470,6 +1632,90 @@ export default {
1470
1632
  ]
1471
1633
  }
1472
1634
  ],
1635
+ "loginPlugin": [
1636
+ 32,
1637
+ {
1638
+ "name": [
1639
+ 4,
1640
+ "String!"
1641
+ ],
1642
+ "username": [
1643
+ 4,
1644
+ "String!"
1645
+ ],
1646
+ "password": [
1647
+ 4,
1648
+ "String!"
1649
+ ]
1650
+ }
1651
+ ],
1652
+ "logoutPlugin": [
1653
+ 32,
1654
+ {
1655
+ "name": [
1656
+ 4,
1657
+ "String!"
1658
+ ]
1659
+ }
1660
+ ],
1661
+ "updatePlugins": [
1662
+ 54
1663
+ ],
1664
+ "startNeoworksSignIn": [
1665
+ 4,
1666
+ {
1667
+ "returnTo": [
1668
+ 4
1669
+ ]
1670
+ }
1671
+ ],
1672
+ "completeNeoworksSignIn": [
1673
+ 48,
1674
+ {
1675
+ "code": [
1676
+ 4,
1677
+ "String!"
1678
+ ],
1679
+ "state": [
1680
+ 4,
1681
+ "String!"
1682
+ ]
1683
+ }
1684
+ ],
1685
+ "signOutOfNeoworks": [
1686
+ 48
1687
+ ],
1688
+ "syncNeoworks": [
1689
+ 48
1690
+ ],
1691
+ "syncNeoworksSoon": [
1692
+ 6
1693
+ ],
1694
+ "__typename": [
1695
+ 4
1696
+ ]
1697
+ },
1698
+ "PluginUpdate": {
1699
+ "name": [
1700
+ 4
1701
+ ],
1702
+ "fromVersion": [
1703
+ 4
1704
+ ],
1705
+ "toVersion": [
1706
+ 4
1707
+ ],
1708
+ "__typename": [
1709
+ 4
1710
+ ]
1711
+ },
1712
+ "PluginUpdateReport": {
1713
+ "updated": [
1714
+ 53
1715
+ ],
1716
+ "failed": [
1717
+ 4
1718
+ ],
1473
1719
  "__typename": [
1474
1720
  4
1475
1721
  ]
@@ -1485,7 +1731,10 @@ export default {
1485
1731
  }
1486
1732
  ],
1487
1733
  "together": [
1488
- 42
1734
+ 43
1735
+ ],
1736
+ "challenges": [
1737
+ 51
1489
1738
  ],
1490
1739
  "__typename": [
1491
1740
  4
@@ -1,4 +1,4 @@
1
- import { PluginSourceError } from "../errors.ts";
1
+ import { PluginBlockedError, PluginSourceError } from "../errors.ts";
2
2
  import type { PluginContext } from "../definition.ts";
3
3
  import type { SourceInput } from "../model.ts";
4
4
  import {
@@ -70,13 +70,26 @@ async function extractSource(page: PlayerPage, ctx: PluginContext): Promise<Sour
70
70
  );
71
71
  }
72
72
 
73
+ // What every VOE player page carries in some form: the encoded payload, its older variables, or the plain HLS link.
74
+ const PLAYER_PAYLOAD = /<script[^>]+type=["']application\/json["']|\b(?:mkgma|a168c)\b|["']hls["']\s*:|\.m3u8/i;
75
+
73
76
  async function retrieveVoe(url: string, ctx: PluginContext): Promise<SourceInput> {
74
77
  const page = await loadPlayerPage(url, ctx);
75
78
  const source = await extractSource(page, ctx);
76
- if (!source) {
77
- throw new PluginSourceError("extraction_failed", `VOE: no stream found on ${page.url}`);
79
+ if (source) {
80
+ return { ...source, headers: { Referer: originOf(page.url) + "/" } };
81
+ }
82
+ // A page without any player payload is a challenge (VOE domains sit behind DDoS-Guard) or an interstitial, not a changed player.
83
+ if (!PLAYER_PAYLOAD.test(page.html)) {
84
+ throw new PluginBlockedError(`VOE: ${page.url} served "${pageTitleOf(page.html)}" instead of the player`);
78
85
  }
79
- return { ...source, headers: { Referer: originOf(page.url) + "/" } };
86
+ throw new PluginSourceError("extraction_failed", `VOE: no stream found on ${page.url}`);
87
+ }
88
+
89
+ function pageTitleOf(html: string): string {
90
+ const title = html.match(/<title[^>]*>([^<]*)<\/title>/i);
91
+ if (!title) return "a page without a title";
92
+ return title[1].trim();
80
93
  }
81
94
 
82
95
  export const voe = defineHoster({ name: "VOE", domains: VOE_DOMAINS, retrieve: retrieveVoe });
package/src/index.ts CHANGED
@@ -6,4 +6,5 @@ export * from "./errors.ts";
6
6
  export { match, type Matcher } from "./match.ts";
7
7
  export { extract, type Extractor, type ExtractedMedia } from "./extract.ts";
8
8
  export type { HttpClient, HttpResponse, PostOptions, RequestOptions } from "./http-client.ts";
9
+ export type { Browser } from "./browser.ts";
9
10
  export { defineHoster, hosters, HosterRegistry, type HosterDefinition } from "./hosters/index.ts";
package/src/run.ts CHANGED
@@ -2,7 +2,16 @@ import { writeSync } from "fs";
2
2
  import type { PluginDefinition } from "./definition.ts";
3
3
  import { OtterError } from "./errors.ts";
4
4
  import { handlersOf, isPluginDefinition, type PluginHandlers } from "./runtime.ts";
5
- import type { PluginMeta, ResolveResult, StreamsArgs, StreamsResult, SubtitlesArgs, SubtitlesResult } from "./types.ts";
5
+ import type {
6
+ LoginArgs,
7
+ LoginResult,
8
+ PluginMeta,
9
+ ResolveResult,
10
+ StreamsArgs,
11
+ StreamsResult,
12
+ SubtitlesArgs,
13
+ SubtitlesResult,
14
+ } from "./types.ts";
6
15
 
7
16
  export type { PluginHandlers };
8
17
 
@@ -51,6 +60,11 @@ async function dispatch(handlers: PluginHandlers, input: Invocation): Promise<ne
51
60
  respond<ResolveResult>(await handlers.resolve(String(url)));
52
61
  }
53
62
 
63
+ if (input.capability === "login") {
64
+ if (!handlers.login) fail("login not implemented");
65
+ respond<LoginResult>(await handlers.login(input.args as unknown as LoginArgs));
66
+ }
67
+
54
68
  fail(`unsupported capability: ${input.capability}`);
55
69
  }
56
70
 
package/src/runtime.ts CHANGED
@@ -24,6 +24,8 @@ import { resolveWithTiming } from "./timing.ts";
24
24
  import type {
25
25
  Capability,
26
26
  Download,
27
+ LoginArgs,
28
+ LoginResult,
27
29
  PluginMeta,
28
30
  ResolveResult,
29
31
  StreamsArgs,
@@ -41,6 +43,8 @@ export interface PluginHandlers {
41
43
  resolve?: (url: string) => Promise<ResolveResult>;
42
44
  /** Lists caption files for a TMDB-known movie or episode. */
43
45
  subtitles?: (args: SubtitlesArgs) => Promise<SubtitlesResult>;
46
+ /** Logs in to the site and returns a session. */
47
+ login?: (credentials: LoginArgs) => Promise<LoginResult>;
44
48
  }
45
49
 
46
50
  export function isPluginDefinition(plugin: PluginHandlers | PluginDefinition): plugin is PluginDefinition {
@@ -54,9 +58,15 @@ function capabilitiesOf(definition: PluginDefinition): Capability[] {
54
58
  if (definition.streams) capabilities.push("streams");
55
59
  if (definition.sources) capabilities.push("resolve");
56
60
  if (definition.subtitles) capabilities.push("subtitles");
61
+ if (definition.account) capabilities.push("login");
57
62
  return capabilities;
58
63
  }
59
64
 
65
+ function accountRequirementOf(definition: PluginDefinition): PluginMeta["account"] {
66
+ if (!definition.account) return undefined;
67
+ return { signup_url: definition.account.signup_url };
68
+ }
69
+
60
70
  function domainsOf(definition: PluginDefinition): string[] | undefined {
61
71
  if (!definition.sources) return undefined;
62
72
  const domains = [...definition.sources.domains];
@@ -78,6 +88,7 @@ export function metaOf(definition: PluginDefinition): PluginMeta {
78
88
  base_url: definition.base_url,
79
89
  languages: definition.languages,
80
90
  media: definition.media,
91
+ account: accountRequirementOf(definition),
81
92
  };
82
93
  }
83
94
 
@@ -229,6 +240,12 @@ export class PluginRuntime {
229
240
  if (!capability) throw new Error("resolve not implemented");
230
241
  return completeSource(await capability.retrieve(params, this.ctx));
231
242
  }
243
+
244
+ async login(credentials: LoginArgs): Promise<LoginResult> {
245
+ const capability = this.definition.account;
246
+ if (!capability) throw new Error("login not implemented");
247
+ return capability.login(credentials, this.ctx);
248
+ }
232
249
  }
233
250
 
234
251
  /** The v1 handlers of a v2 definition, so one dispatcher serves both kinds of plugin. */
@@ -250,5 +267,8 @@ export function handlersOf(definition: PluginDefinition, options: ContextOptions
250
267
  if (definition.sources) {
251
268
  handlers.resolve = (url) => resolveWithTiming(async () => toResolveResult(await runtime.retrieveSource({ url })));
252
269
  }
270
+ if (definition.account) {
271
+ handlers.login = (credentials) => runtime.login(credentials);
272
+ }
253
273
  return handlers;
254
274
  }
package/src/testing.ts CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import { join } from "node:path";
6
+ import type { Browser } from "./browser.ts";
6
7
  import type { PluginContext, PluginDefinition } from "./definition.ts";
7
8
  import type {
8
9
  EpisodeRef,
@@ -23,6 +24,8 @@ export interface TestPluginOptions {
23
24
  fetch?: typeof fetch;
24
25
  /** The plugin's env: settings values and OTTER_BASE_URL. Empty by default. */
25
26
  env?: Record<string, string | undefined>;
27
+ /** Replaces the Otter app's WebView behind ctx.browser. */
28
+ browser?: Browser;
26
29
  }
27
30
 
28
31
  export interface TestPlugin {
@@ -34,7 +37,7 @@ export interface TestPlugin {
34
37
 
35
38
  /** Calls the plugin's handlers the way the backend would, and returns the completed objects. */
36
39
  export function testPlugin(definition: PluginDefinition, options: TestPluginOptions = {}): TestPlugin {
37
- const runtime = new PluginRuntime(definition, { fetch: options.fetch, env: options.env || {} });
40
+ const runtime = new PluginRuntime(definition, { fetch: options.fetch, env: options.env || {}, browser: options.browser });
38
41
  return {
39
42
  ctx: runtime.ctx,
40
43
  streams: { list: (params) => runtime.listStreams(params) },
package/src/types.ts CHANGED
@@ -3,9 +3,33 @@
3
3
  //
4
4
  // Otter plugins do three things: find stream links for a title TMDB already
5
5
  // identified ("streams"), turn a hoster link into a playable media URL
6
- // ("resolve"), and find subtitle files for a title ("subtitles").
6
+ // ("resolve"), and find subtitle files for a title ("subtitles"). Plugins
7
+ // whose site needs an account also log in ("login").
7
8
 
8
- export type Capability = "meta" | "streams" | "resolve" | "subtitles";
9
+ export type Capability = "meta" | "streams" | "resolve" | "subtitles" | "login";
10
+
11
+ /** The site needs the user's account. */
12
+ export interface AccountRequirement {
13
+ /** Where users without an account can make one. */
14
+ signup_url?: string;
15
+ }
16
+
17
+ /** Passed to the login capability: the user's credentials for the site. */
18
+ export interface LoginArgs {
19
+ username: string;
20
+ password: string;
21
+ }
22
+
23
+ /** An opaque session (e.g. the site's cookies) the plugin gets back with every later call. */
24
+ export interface LoginResult {
25
+ session: string;
26
+ /** RFC 3339; omitted when unknown. */
27
+ expires_at?: string;
28
+ }
29
+
30
+ /** Env vars through which a plugin with an account receives it on every call. */
31
+ export const ACCOUNT_USERNAME_ENV_KEY = "OTTER_ACCOUNT_USERNAME";
32
+ export const ACCOUNT_SESSION_ENV_KEY = "OTTER_ACCOUNT_SESSION";
9
33
 
10
34
  export type MediaType = "movie" | "series" | "episode";
11
35
 
@@ -35,6 +59,8 @@ export interface PluginMeta {
35
59
  base_url?: string;
36
60
  languages?: string[];
37
61
  media?: Array<"movie" | "episode">;
62
+ /** Set when the site only works with the user's login. */
63
+ account?: AccountRequirement;
38
64
  }
39
65
 
40
66
  /** One playable source: usually a hoster page that still needs resolving. */