@serifpersia/dango 3.6.7 → 3.6.9

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.
Files changed (156) hide show
  1. package/README.md +1 -1
  2. package/client/dist/assets/{AnimeCard-C3P9zWi9.js → AnimeCard-DKDJK8Mp.js} +1 -1
  3. package/client/dist/assets/{AnimeInfo-Et6687Tl.js → AnimeInfo-CTcvfjva.js} +1 -1
  4. package/client/dist/assets/{AnimeInfoPage-DX4eNnlH.js → AnimeInfoPage-B_UiacIN.js} +2 -2
  5. package/client/dist/assets/{Asmr-CCdEWrFi.js → Asmr-DMSN2vxl.js} +2 -2
  6. package/client/dist/assets/{AsmrResetProgressModal-DgEWBJOw.js → AsmrResetProgressModal-CRwfOatX.js} +1 -1
  7. package/client/dist/assets/{AvSyncCalibrator-CQ2fjf2E.js → AvSyncCalibrator-CRJsi-vz.js} +1 -1
  8. package/client/dist/assets/{Home-DUkUTTTy.js → Home-pwmK9_Eh.js} +1 -1
  9. package/client/dist/assets/{Insights-QCh4xW12.js → Insights-m7kFzg2A.js} +1 -1
  10. package/client/dist/assets/{LibraryListPage-BoTxRqHz.js → LibraryListPage-C1wpPvu6.js} +1 -1
  11. package/client/dist/assets/ListeningList-OzfEI1Ga.js +1 -0
  12. package/client/dist/assets/{Manga-HydR-L7o.js → Manga-ChRCExhK.js} +1 -1
  13. package/client/dist/assets/{MangaInfoPage-CBakEI9a.js → MangaInfoPage-DSHJPo2A.js} +1 -1
  14. package/client/dist/assets/{MangaReadPage-DwAR3iPy.js → MangaReadPage-CzOVY1wA.js} +1 -1
  15. package/client/dist/assets/{MangaResetProgressModal-DGzl8vsO.js → MangaResetProgressModal-CJfzdUBb.js} +1 -1
  16. package/client/dist/assets/{Mature-Pi0TxKuF.js → Mature-CifQMfhs.js} +1 -1
  17. package/client/dist/assets/{MediaCard--cuFxOCS.js → MediaCard-CM10yB9V.js} +1 -1
  18. package/client/dist/assets/{OptionListMenu-B3D39dGS.js → OptionListMenu-6Kovbsqw.js} +1 -1
  19. package/client/dist/assets/{Player-CsH4x_I_.js → Player-CK0hT-u4.js} +2 -2
  20. package/client/dist/assets/{PlayerSettings-DGxBsi3F.js → PlayerSettings-Bb66uqT9.js} +1 -1
  21. package/client/dist/assets/{QueueOptionsButton-Djq4Cpex.js → QueueOptionsButton-C_nTj8_q.js} +1 -1
  22. package/client/dist/assets/{QueueRail-DOrYgNVX.js → QueueRail-DUK7URAE.js} +1 -1
  23. package/client/dist/assets/{ReadingList-DwYoBrNk.js → ReadingList-Ck9LJThU.js} +1 -1
  24. package/client/dist/assets/{ResetProgressModal-CMF86mX6.js → ResetProgressModal-BUphIv0k.js} +1 -1
  25. package/client/dist/assets/{Search-DFkhuk-x.js → Search-zJyP15h6.js} +1 -1
  26. package/client/dist/assets/{Settings-DBB2r0VQ.js → Settings-BYdoSEUh.js} +1 -1
  27. package/client/dist/assets/{SkeletonGrid-DJelJgAv.js → SkeletonGrid-CqgbOhjX.js} +1 -1
  28. package/client/dist/assets/{Trackers-DGYXFhYZ.js → Trackers-BVjyv6CM.js} +1 -1
  29. package/client/dist/assets/{Tv-C5MDGD2Z.js → Tv-L13ylswR.js} +1 -1
  30. package/client/dist/assets/{TvInfo-DrKuK13u.js → TvInfo-Cvcm5U2D.js} +1 -1
  31. package/client/dist/assets/{TvPopup-DtHilRDT.js → TvPopup-DhxfKvYm.js} +1 -1
  32. package/client/dist/assets/{TvSearch-CzNxdu_w.js → TvSearch-P8bFE6_X.js} +1 -1
  33. package/client/dist/assets/{TvWatchlist-D7p4br6S.js → TvWatchlist-D5gVPjtb.js} +1 -1
  34. package/client/dist/assets/{Watchlist-DrOzswl2.js → Watchlist-Cjq8l3rU.js} +1 -1
  35. package/client/dist/assets/{hls-BGCX7mJy.js → hls-BkzuANAg.js} +1 -1
  36. package/client/dist/assets/{index-CnfZwsds.js → index-CLVgzKLk.js} +19 -19
  37. package/client/dist/assets/{useAnimeInfoData-DYXWBPF-.js → useAnimeInfoData-DZJZu-so.js} +1 -1
  38. package/client/dist/assets/{useAsmr-BbhQ59bk.js → useAsmr-CvrMGHuo.js} +1 -1
  39. package/client/dist/assets/useAsmrPopup-Bimy8Ouw.js +1 -0
  40. package/client/dist/assets/{useMangaLibrary-DuesWQaE.js → useMangaLibrary--MiN11uR.js} +1 -1
  41. package/client/dist/assets/{useMangaPopup-D57OVGUr.js → useMangaPopup-CR5XhKKS.js} +1 -1
  42. package/client/dist/assets/{useProviders-mpQb_dix.js → useProviders-DqdT4fA5.js} +1 -1
  43. package/client/dist/assets/{useTv-DGflCsSI.js → useTv-BL0HMDyP.js} +1 -1
  44. package/client/dist/assets/{useTvLibrary-BqeSmyc4.js → useTvLibrary-D4U4iqN8.js} +1 -1
  45. package/client/dist/index.html +1 -1
  46. package/package.json +3 -5
  47. package/server/dist/config.js +1 -174
  48. package/server/dist/server.js +1068 -289
  49. package/server/dist/shipped-defaults.js +1 -6
  50. package/server/package.json +4 -5
  51. package/client/dist/assets/Asmr.module-CdWlioTY.js +0 -1
  52. package/client/dist/assets/ListeningList-DguKjI_t.js +0 -1
  53. package/client/dist/assets/Music-BGH_0voi.css +0 -1
  54. package/client/dist/assets/Music-CQpyXTLH.js +0 -1
  55. package/client/dist/assets/Radio-CCHNFN7R.css +0 -1
  56. package/client/dist/assets/Radio-DF6g6odd.js +0 -1
  57. package/client/dist/assets/Radio.module-DGSZLpKM.js +0 -1
  58. package/client/dist/assets/useAsmrPopup-SymV1J-b.js +0 -1
  59. package/server/dist/app-auth.js +0 -157
  60. package/server/dist/app-hono.js +0 -598
  61. package/server/dist/db/drizzle.js +0 -16
  62. package/server/dist/db/schema-anime.js +0 -61
  63. package/server/dist/db/schema-asmr.js +0 -13
  64. package/server/dist/db/schema-manga.js +0 -31
  65. package/server/dist/db/schema-tv.js +0 -18
  66. package/server/dist/db.js +0 -217
  67. package/server/dist/discord-gateway.js +0 -385
  68. package/server/dist/discord-rpc.js +0 -413
  69. package/server/dist/github-sync.js +0 -508
  70. package/server/dist/google.js +0 -741
  71. package/server/dist/hono/asmr.js +0 -10
  72. package/server/dist/hono/auth.js +0 -49
  73. package/server/dist/hono/music.js +0 -209
  74. package/server/dist/hono/proxy.js +0 -827
  75. package/server/dist/hono/tv.js +0 -200
  76. package/server/dist/hono/watchlist.js +0 -341
  77. package/server/dist/lib/anilist.js +0 -1583
  78. package/server/dist/lib/anischedule.js +0 -191
  79. package/server/dist/lib/insights.js +0 -185
  80. package/server/dist/lib/ipc.js +0 -23
  81. package/server/dist/lib/kitsu.js +0 -517
  82. package/server/dist/lib/mal-import.js +0 -291
  83. package/server/dist/lib/mal.js +0 -957
  84. package/server/dist/lib/migration.js +0 -310
  85. package/server/dist/lib/offline-db.js +0 -395
  86. package/server/dist/lib/potoken.js +0 -135
  87. package/server/dist/lib/recommendations.service.js +0 -216
  88. package/server/dist/lib/temp-ids.js +0 -3
  89. package/server/dist/lib/tmdb.js +0 -72
  90. package/server/dist/lib/tracker/anilist-tracker.js +0 -308
  91. package/server/dist/lib/tracker/manga-sync.service.js +0 -773
  92. package/server/dist/lib/tracker/sync-state.js +0 -21
  93. package/server/dist/lib/tracker/sync.service.js +0 -476
  94. package/server/dist/lib/translate.js +0 -79
  95. package/server/dist/lib/ump.js +0 -106
  96. package/server/dist/lib/ytmusic.js +0 -162
  97. package/server/dist/logger.js +0 -16
  98. package/server/dist/providers/manga/manga.types.js +0 -1
  99. package/server/dist/providers/provider.interface.js +0 -1
  100. package/server/dist/providers/remote-loader.js +0 -614
  101. package/server/dist/providers/remote-types.js +0 -159
  102. package/server/dist/providers/title-matching.js +0 -226
  103. package/server/dist/providers/tv.types.js +0 -1
  104. package/server/dist/rclone.js +0 -120
  105. package/server/dist/repositories/asmr.repository.js +0 -77
  106. package/server/dist/repositories/insights.repository.js +0 -106
  107. package/server/dist/repositories/library.repository.js +0 -94
  108. package/server/dist/repositories/mal-cache.repository.js +0 -52
  109. package/server/dist/repositories/manga.repository.js +0 -95
  110. package/server/dist/repositories/notifications.repository.js +0 -60
  111. package/server/dist/repositories/queue.repository.js +0 -72
  112. package/server/dist/repositories/settings.repository.js +0 -30
  113. package/server/dist/repositories/shows-meta.repository.js +0 -58
  114. package/server/dist/repositories/temp-show-ids.repository.js +0 -63
  115. package/server/dist/repositories/tv.repository.js +0 -93
  116. package/server/dist/repositories/watched-episodes.repository.js +0 -82
  117. package/server/dist/repositories/watchlist.repository.js +0 -60
  118. package/server/dist/scripts/backfill-episode-duration.js +0 -42
  119. package/server/dist/sync-payload.js +0 -91
  120. package/server/dist/sync.js +0 -657
  121. package/server/dist/trpc/context.js +0 -7
  122. package/server/dist/trpc/errors.js +0 -15
  123. package/server/dist/trpc/index.js +0 -18
  124. package/server/dist/trpc/router.js +0 -49
  125. package/server/dist/trpc/routers/asmr-library.js +0 -112
  126. package/server/dist/trpc/routers/asmr-progress.js +0 -121
  127. package/server/dist/trpc/routers/asmr.js +0 -87
  128. package/server/dist/trpc/routers/auth.js +0 -194
  129. package/server/dist/trpc/routers/continue-watching.js +0 -81
  130. package/server/dist/trpc/routers/data.js +0 -1026
  131. package/server/dist/trpc/routers/discord.js +0 -285
  132. package/server/dist/trpc/routers/discovery.js +0 -11
  133. package/server/dist/trpc/routers/insights.js +0 -14
  134. package/server/dist/trpc/routers/manga-library.js +0 -263
  135. package/server/dist/trpc/routers/manga-progress.js +0 -169
  136. package/server/dist/trpc/routers/manga.js +0 -201
  137. package/server/dist/trpc/routers/music.js +0 -655
  138. package/server/dist/trpc/routers/notifications.js +0 -80
  139. package/server/dist/trpc/routers/progress.js +0 -109
  140. package/server/dist/trpc/routers/queue.js +0 -93
  141. package/server/dist/trpc/routers/radio.js +0 -145
  142. package/server/dist/trpc/routers/settings.js +0 -96
  143. package/server/dist/trpc/routers/tracker.js +0 -213
  144. package/server/dist/trpc/routers/tv-library.js +0 -135
  145. package/server/dist/trpc/routers/tv-progress.js +0 -159
  146. package/server/dist/trpc/routers/tv.js +0 -551
  147. package/server/dist/trpc/routers/watchlist.js +0 -550
  148. package/server/dist/trpc/validation.js +0 -258
  149. package/server/dist/utils/cache.utils.js +0 -25
  150. package/server/dist/utils/cookie.utils.js +0 -13
  151. package/server/dist/utils/db-utils.js +0 -17
  152. package/server/dist/utils/env.utils.js +0 -77
  153. package/server/dist/utils/http.utils.js +0 -82
  154. package/server/dist/utils/request-context.js +0 -2
  155. package/server/dist/utils/security.utils.js +0 -76
  156. /package/client/dist/assets/{Asmr-D1KuQwQy.css → useAsmrPopup-D1KuQwQy.css} +0 -0
@@ -1,551 +0,0 @@
1
- import { TRPCError } from '@trpc/server';
2
- import { protectedProcedure, router } from '../index.js';
3
- import { defineSchema, failed, optStr, readCount, reqId, reqObj, reqStr } from '../validation.js';
4
- import { getTmdbKey, TMDB_BASE, TMDB_IMAGE } from '../../lib/tmdb.js';
5
- import { parseJsonBody } from '../../utils/http.utils.js';
6
- async function resolveTvMeta(mediaType, numericTmdbId, partial) {
7
- const meta = { ...partial };
8
- if (meta.title && meta.imdbId && meta.year)
9
- return meta;
10
- try {
11
- const tmdbKey = await getTmdbKey();
12
- if (tmdbKey) {
13
- const tmdbRes = await fetch(`${TMDB_BASE}/${mediaType}/${numericTmdbId}?api_key=${tmdbKey}&append_to_response=external_ids`, { headers: { 'User-Agent': 'Mozilla/5.0' }, signal: AbortSignal.timeout(4000) });
14
- if (tmdbRes.ok) {
15
- const d = await parseJsonBody(tmdbRes);
16
- if (!meta.title)
17
- meta.title = d.title || d.name || '';
18
- if (!meta.year)
19
- meta.year = (d.release_date || d.first_air_date || '').split('-')[0] || '';
20
- if (!meta.imdbId)
21
- meta.imdbId = d.external_ids?.imdb_id || d.imdb_id || '';
22
- if (mediaType === 'tv' && d.number_of_seasons)
23
- meta.totalSeasons = String(d.number_of_seasons);
24
- }
25
- }
26
- }
27
- catch {
28
- // ignore
29
- }
30
- return meta;
31
- }
32
- function toSearchResult(item, type) {
33
- return {
34
- id: item.id,
35
- title: item.title || item.name || '',
36
- year: (item.release_date || item.first_air_date || '').split('-')[0],
37
- type,
38
- image: item.poster_path ? `${TMDB_IMAGE}/w500${item.poster_path}` : '',
39
- backdrop: item.backdrop_path ? `${TMDB_IMAGE}/w780${item.backdrop_path}` : '',
40
- overview: item.overview || '',
41
- vote_average: item.vote_average || 0,
42
- adult: item.adult === true,
43
- genre_ids: item.genre_ids || [],
44
- };
45
- }
46
- const tvSearchInput = () => defineSchema((value) => {
47
- const obj = reqObj(value);
48
- const out = {};
49
- const q = optStr(obj, 'q');
50
- if (q !== undefined)
51
- out.q = q;
52
- if (obj.page !== undefined)
53
- out.page = readCount(obj, 'page', 1);
54
- const type = optStr(obj, 'type');
55
- if (type !== undefined)
56
- out.type = type;
57
- const genre = optStr(obj, 'genre');
58
- if (genre !== undefined)
59
- out.genre = genre;
60
- const year = optStr(obj, 'year');
61
- if (year !== undefined)
62
- out.year = year;
63
- const sortBy = optStr(obj, 'sortBy');
64
- if (sortBy !== undefined)
65
- out.sortBy = sortBy;
66
- return out;
67
- });
68
- const tvTrendingInput = () => defineSchema((value) => {
69
- const obj = reqObj(value);
70
- const out = {};
71
- const mediaType = optStr(obj, 'mediaType');
72
- if (mediaType !== undefined)
73
- out.mediaType = mediaType;
74
- const timeWindow = optStr(obj, 'timeWindow');
75
- if (timeWindow !== undefined)
76
- out.timeWindow = timeWindow;
77
- if (obj.page !== undefined)
78
- out.page = readCount(obj, 'page', 1);
79
- return out;
80
- });
81
- const tvDetailsInput = () => defineSchema((value) => {
82
- const obj = reqObj(value);
83
- return { type: reqStr(obj, 'type'), id: reqId(obj, 'id') };
84
- });
85
- const tvEpisodesInput = () => defineSchema((value) => {
86
- const obj = reqObj(value);
87
- return { id: reqId(obj, 'id'), season: reqId(obj, 'season') };
88
- });
89
- const tvLookupImdbInput = () => defineSchema((value) => ({
90
- imdbId: reqStr(reqObj(value), 'imdbId'),
91
- }));
92
- const tvSearchImdbInput = () => defineSchema((value) => {
93
- const obj = reqObj(value);
94
- const out = {};
95
- const q = optStr(obj, 'q');
96
- if (q !== undefined)
97
- out.q = q;
98
- return out;
99
- });
100
- const tvSubtitlesInput = () => defineSchema((value) => {
101
- const obj = reqObj(value);
102
- const out = { type: reqStr(obj, 'type'), tmdbId: reqId(obj, 'tmdbId') };
103
- const season = optStr(obj, 'season');
104
- if (season !== undefined)
105
- out.season = season;
106
- const episode = optStr(obj, 'episode');
107
- if (episode !== undefined)
108
- out.episode = episode;
109
- return out;
110
- });
111
- const tvSourcesInput = () => defineSchema((value) => {
112
- const obj = reqObj(value);
113
- const out = {
114
- provider: reqStr(obj, 'provider'),
115
- type: reqStr(obj, 'type'),
116
- tmdbId: reqId(obj, 'tmdbId'),
117
- };
118
- if (obj.season !== undefined)
119
- out.season = readCount(obj, 'season', 1);
120
- if (obj.episode !== undefined)
121
- out.episode = readCount(obj, 'episode', 1);
122
- const server = optStr(obj, 'server');
123
- if (server !== undefined)
124
- out.server = server;
125
- const title = optStr(obj, 'title');
126
- if (title !== undefined)
127
- out.title = title;
128
- const year = optStr(obj, 'year');
129
- if (year !== undefined)
130
- out.year = year;
131
- const imdbId = optStr(obj, 'imdbId');
132
- if (imdbId !== undefined)
133
- out.imdbId = imdbId;
134
- const totalSeasons = optStr(obj, 'totalSeasons');
135
- if (totalSeasons !== undefined)
136
- out.totalSeasons = totalSeasons;
137
- return out;
138
- });
139
- export const tvRouter = router({
140
- search: protectedProcedure.input(tvSearchInput()).query(async ({ ctx, input }) => {
141
- const query = input.q || '';
142
- const page = input.page || 1;
143
- const type = input.type || 'multi';
144
- const genre = input.genre || '';
145
- const year = input.year || '';
146
- const sortBy = input.sortBy || 'popularity.desc';
147
- const cacheKey = `tv-search-${query.toLowerCase()}-${page}-${type}-${genre}-${year}-${sortBy}`;
148
- const cached = ctx.apiCache.get(cacheKey);
149
- if (cached)
150
- return cached;
151
- const key = await getTmdbKey();
152
- if (!key)
153
- throw failed('No TMDB API key available');
154
- try {
155
- let url;
156
- if (type === 'tv' || type === 'movie') {
157
- if (!query.trim()) {
158
- const params = new URLSearchParams({
159
- api_key: key,
160
- page: String(page),
161
- sort_by: sortBy,
162
- });
163
- if (genre)
164
- params.set('with_genres', genre);
165
- if (year) {
166
- if (type === 'tv')
167
- params.set('first_air_date_year', year);
168
- else
169
- params.set('primary_release_year', year);
170
- }
171
- url = `${TMDB_BASE}/discover/${type}?${params.toString()}`;
172
- }
173
- else {
174
- const params = new URLSearchParams({
175
- api_key: key,
176
- query: encodeURIComponent(query.trim()),
177
- page: String(page),
178
- include_adult: 'true',
179
- });
180
- url = `${TMDB_BASE}/search/${type}?${params.toString()}`;
181
- }
182
- }
183
- else if (!query.trim()) {
184
- const params = new URLSearchParams({
185
- api_key: key,
186
- page: String(page),
187
- sort_by: sortBy,
188
- });
189
- if (genre)
190
- params.set('with_genres', genre);
191
- if (year)
192
- params.set('first_air_date_year', year);
193
- url = `${TMDB_BASE}/discover/tv?${params.toString()}`;
194
- }
195
- else {
196
- const params = new URLSearchParams({
197
- api_key: key,
198
- query: encodeURIComponent(query),
199
- page: String(page),
200
- include_adult: 'true',
201
- });
202
- url = `${TMDB_BASE}/search/multi?${params.toString()}`;
203
- }
204
- const r = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
205
- if (!r.ok)
206
- throw failed('TMDB search failed');
207
- const d = await parseJsonBody(r);
208
- let results;
209
- if (type === 'tv' || type === 'movie') {
210
- results = (d.results || []).map((item) => toSearchResult(item, type));
211
- }
212
- else {
213
- results = (d.results || [])
214
- .filter((item) => item.media_type !== 'person')
215
- .map((item) => toSearchResult(item, item.media_type || 'tv'));
216
- }
217
- const payload = {
218
- results,
219
- total_results: d.total_results || 0,
220
- total_pages: d.total_pages || 0,
221
- page: d.page || page,
222
- };
223
- ctx.apiCache.set(cacheKey, payload, 1800);
224
- return payload;
225
- }
226
- catch (e) {
227
- if (e instanceof TRPCError)
228
- throw e;
229
- throw failed(e.message);
230
- }
231
- }),
232
- trending: protectedProcedure.input(tvTrendingInput()).query(async ({ ctx, input }) => {
233
- const mediaType = input.mediaType || 'all';
234
- const timeWindow = input.timeWindow || 'week';
235
- const page = input.page || 1;
236
- const cacheKey = `tv-trending-${mediaType}-${timeWindow}-${page}`;
237
- const cached = ctx.apiCache.get(cacheKey);
238
- if (cached)
239
- return cached;
240
- const key = await getTmdbKey();
241
- if (!key)
242
- throw failed('No TMDB API key available');
243
- try {
244
- const r = await fetch(`${TMDB_BASE}/trending/${mediaType}/${timeWindow}?api_key=${key}&page=${page}`, { headers: { 'User-Agent': 'Mozilla/5.0' } });
245
- if (!r.ok)
246
- throw failed('TMDB trending failed');
247
- const d = await parseJsonBody(r);
248
- const results = (d.results || [])
249
- .filter((item) => item.media_type !== 'person')
250
- .map((item) => toSearchResult(item, item.media_type || 'tv'));
251
- const payload = {
252
- results,
253
- total_results: d.total_results || 0,
254
- total_pages: d.total_pages || 0,
255
- page: d.page || page,
256
- };
257
- ctx.apiCache.set(cacheKey, payload, 3600);
258
- return payload;
259
- }
260
- catch (e) {
261
- if (e instanceof TRPCError)
262
- throw e;
263
- throw failed(e.message);
264
- }
265
- }),
266
- genres: protectedProcedure.query(async ({ ctx }) => {
267
- const cacheKey = 'tv-genres-list';
268
- const cached = ctx.apiCache.get(cacheKey);
269
- if (cached)
270
- return cached;
271
- const key = await getTmdbKey();
272
- if (!key)
273
- throw failed('No TMDB API key available');
274
- try {
275
- const [tvRes, movieRes] = await Promise.all([
276
- fetch(`${TMDB_BASE}/genre/tv/list?api_key=${key}`, {
277
- headers: { 'User-Agent': 'Mozilla/5.0' },
278
- }),
279
- fetch(`${TMDB_BASE}/genre/movie/list?api_key=${key}`, {
280
- headers: { 'User-Agent': 'Mozilla/5.0' },
281
- }),
282
- ]);
283
- const tvData = tvRes.ok
284
- ? await parseJsonBody(tvRes)
285
- : { genres: [] };
286
- const movieData = movieRes.ok
287
- ? await parseJsonBody(movieRes)
288
- : { genres: [] };
289
- const payload = {
290
- tv: (tvData.genres || []).map((g) => ({
291
- id: g.id,
292
- name: g.name,
293
- })),
294
- movie: (movieData.genres || []).map((g) => ({
295
- id: g.id,
296
- name: g.name,
297
- })),
298
- };
299
- ctx.apiCache.set(cacheKey, payload, 86400);
300
- return payload;
301
- }
302
- catch (e) {
303
- if (e instanceof TRPCError)
304
- throw e;
305
- throw failed(e.message);
306
- }
307
- }),
308
- details: protectedProcedure.input(tvDetailsInput()).query(async ({ input }) => {
309
- const type = input.type;
310
- const id = input.id;
311
- const key = await getTmdbKey();
312
- if (!key)
313
- throw failed('No TMDB API key available');
314
- try {
315
- const r = await fetch(`${TMDB_BASE}/${type}/${id}?api_key=${key}&append_to_response=external_ids`, { headers: { 'User-Agent': 'Mozilla/5.0' } });
316
- if (!r.ok)
317
- throw failed('TMDB details failed');
318
- const d = await parseJsonBody(r);
319
- const result = {
320
- id: d.id,
321
- imdb_id: d.external_ids?.imdb_id || d.imdb_id || null,
322
- title: d.title || d.name,
323
- overview: d.overview,
324
- vote_average: d.vote_average,
325
- year: (d.release_date || d.first_air_date || '').split('-')[0],
326
- poster: d.poster_path ? `${TMDB_IMAGE}/w500${d.poster_path}` : '',
327
- backdrop: d.backdrop_path ? `${TMDB_IMAGE}/original${d.backdrop_path}` : '',
328
- adult: d.adult === true,
329
- };
330
- if (type === 'tv') {
331
- result.seasons = (d.seasons || [])
332
- .filter((s) => s.season_number > 0)
333
- .map((s) => ({
334
- season_number: s.season_number,
335
- episode_count: s.episode_count,
336
- }));
337
- result.number_of_seasons = d.number_of_seasons;
338
- }
339
- return result;
340
- }
341
- catch (e) {
342
- if (e instanceof TRPCError)
343
- throw e;
344
- throw failed(e.message);
345
- }
346
- }),
347
- episodes: protectedProcedure.input(tvEpisodesInput()).query(async ({ input }) => {
348
- const id = input.id;
349
- const season = input.season;
350
- const key = await getTmdbKey();
351
- if (!key)
352
- throw failed('No TMDB API key available');
353
- try {
354
- const r = await fetch(`${TMDB_BASE}/tv/${id}/season/${season}?api_key=${key}`, {
355
- headers: { 'User-Agent': 'Mozilla/5.0' },
356
- });
357
- if (!r.ok)
358
- throw failed('TMDB episodes failed');
359
- const d = await parseJsonBody(r);
360
- const episodes = (d.episodes || []).map((ep) => ({
361
- episode_number: ep.episode_number,
362
- name: ep.name,
363
- vote_average: ep.vote_average,
364
- overview: ep.overview,
365
- still_path: ep.still_path,
366
- }));
367
- return { episodes };
368
- }
369
- catch (e) {
370
- if (e instanceof TRPCError)
371
- throw e;
372
- throw failed(e.message);
373
- }
374
- }),
375
- lookupImdb: protectedProcedure.input(tvLookupImdbInput()).query(async ({ input }) => {
376
- const key = await getTmdbKey();
377
- if (!key)
378
- return { tmdbId: null, error: 'No TMDB API key available' };
379
- try {
380
- const r = await fetch(`${TMDB_BASE}/find/${input.imdbId}?api_key=${key}&external_source=imdb_id`, { headers: { 'User-Agent': 'Mozilla/5.0' } });
381
- if (!r.ok)
382
- return { tmdbId: null, error: `TMDB error ${r.status}` };
383
- const d = await parseJsonBody(r);
384
- const movie = d.movie_results?.[0];
385
- const tv = d.tv_results?.[0];
386
- const result = movie || tv;
387
- return {
388
- tmdbId: result?.id || null,
389
- type: movie ? 'movie' : tv ? 'tv' : null,
390
- title: result?.title || result?.name || null,
391
- year: (result?.release_date || result?.first_air_date || '').substring(0, 4) || null,
392
- };
393
- }
394
- catch (e) {
395
- return { tmdbId: null, error: e.message };
396
- }
397
- }),
398
- searchImdb: protectedProcedure.input(tvSearchImdbInput()).query(async ({ ctx, input }) => {
399
- const query = input.q || '';
400
- if (!query)
401
- return [];
402
- const cacheKey = `tv-imdb-search-${query.toLowerCase()}`;
403
- const cached = ctx.apiCache.get(cacheKey);
404
- if (cached)
405
- return cached;
406
- try {
407
- const response = await fetch(`https://v3.sg.media-imdb.com/suggestion/x/${encodeURIComponent(query)}.json`, { headers: { 'User-Agent': 'Mozilla/5.0' } });
408
- if (!response.ok)
409
- throw failed('IMDB search failed');
410
- const data = await parseJsonBody(response);
411
- const TV_TYPES = new Set(['tvSeries', 'tvMiniSeries', 'movie']);
412
- const matches = (data.d || [])
413
- .filter((entry) => Boolean(entry.id && entry.l) && TV_TYPES.has(entry.qid || ''))
414
- .slice(0, 10)
415
- .map((entry) => ({
416
- id: entry.id,
417
- title: entry.l,
418
- year: entry.y,
419
- type: entry.qid,
420
- image: entry.i?.imageUrl || '',
421
- }));
422
- ctx.apiCache.set(cacheKey, matches, 3600);
423
- return matches;
424
- }
425
- catch (e) {
426
- if (e instanceof TRPCError)
427
- throw e;
428
- throw failed(e.message);
429
- }
430
- }),
431
- subtitles: protectedProcedure.input(tvSubtitlesInput()).query(async ({ ctx, input }) => {
432
- const type = input.type;
433
- const tmdbId = input.tmdbId;
434
- const numericTmdbId = parseInt(tmdbId, 10);
435
- if (!numericTmdbId)
436
- return { subtitles: [] };
437
- const mediaType = type === 'movie' ? 'movie' : 'tv';
438
- const season = input.season || '1';
439
- const episode = input.episode || '1';
440
- const cacheKey = mediaType === 'tv'
441
- ? `tv-subs-${numericTmdbId}-${season}-${episode}`
442
- : `tv-subs-${numericTmdbId}-movie`;
443
- const cached = ctx.apiCache.get(cacheKey);
444
- if (cached)
445
- return cached;
446
- try {
447
- const searchUrl = mediaType === 'tv'
448
- ? `https://subtitles.vidy.st/search?id=${numericTmdbId}&season=${encodeURIComponent(season)}&episode=${encodeURIComponent(episode)}`
449
- : `https://subtitles.vidy.st/search?id=${numericTmdbId}`;
450
- const r = await fetch(searchUrl, {
451
- headers: { 'User-Agent': 'Mozilla/5.0' },
452
- signal: AbortSignal.timeout(10000),
453
- });
454
- if (!r.ok)
455
- return { subtitles: [] };
456
- const items = (await parseJsonBody(r));
457
- const subtitles = (Array.isArray(items) ? items : [])
458
- .filter((s) => typeof s.url === 'string' && s.url.startsWith('https://'))
459
- .map((s) => ({
460
- language: String(s.language || 'en'),
461
- label: String(s.display || s.language || 'Unknown'),
462
- url: String(s.url),
463
- trusted: s.isTrusted === true,
464
- hi: s.isHearingImpaired === true,
465
- downloads: Number(s.downloadCount) || 0,
466
- media: String(s.media || s.release || ''),
467
- }))
468
- .sort((a, b) => {
469
- const aEn = a.language.toLowerCase().startsWith('en') ? 0 : 1;
470
- const bEn = b.language.toLowerCase().startsWith('en') ? 0 : 1;
471
- if (aEn !== bEn)
472
- return aEn - bEn;
473
- if (a.trusted !== b.trusted)
474
- return a.trusted ? -1 : 1;
475
- return b.downloads - a.downloads;
476
- })
477
- .slice(0, 50);
478
- const payload = { subtitles };
479
- ctx.apiCache.set(cacheKey, payload, 3600);
480
- return payload;
481
- }
482
- catch {
483
- return { subtitles: [] };
484
- }
485
- }),
486
- sources: protectedProcedure.input(tvSourcesInput()).query(async ({ ctx, input }) => {
487
- const provider = input.provider;
488
- const type = input.type;
489
- const tmdbId = input.tmdbId;
490
- const mediaType = type === 'movie' ? 'movie' : 'tv';
491
- const numericTmdbId = parseInt(tmdbId, 10);
492
- if (!numericTmdbId)
493
- return { sources: [], audioTracks: [], error: 'Bad tmdb id' };
494
- const mod = ctx.getTvProvider(String(provider).toLowerCase());
495
- if (!mod || typeof mod.getSources !== 'function') {
496
- return { sources: [], audioTracks: [], error: `Unknown TV provider ${provider}` };
497
- }
498
- const season = input.season || 1;
499
- const episode = input.episode || 1;
500
- const server = input.server;
501
- const meta = await resolveTvMeta(mediaType, numericTmdbId, {
502
- title: input.title || '',
503
- year: input.year || '',
504
- imdbId: input.imdbId || '',
505
- totalSeasons: input.totalSeasons || '1',
506
- });
507
- const media = {
508
- tmdbId: numericTmdbId,
509
- type: mediaType,
510
- season,
511
- episode,
512
- title: meta.title,
513
- year: meta.year,
514
- imdbId: meta.imdbId,
515
- totalSeasons: parseInt(meta.totalSeasons, 10) || 1,
516
- };
517
- try {
518
- const result = await mod.getSources(media, server);
519
- if (!result || !Array.isArray(result.sources) || result.sources.length === 0) {
520
- return {
521
- provider: mod.name,
522
- server: result?.server || server,
523
- sources: [],
524
- audioTracks: [],
525
- valid: false,
526
- error: 'No sources found',
527
- };
528
- }
529
- return {
530
- provider: mod.name,
531
- server: result.server || server,
532
- servers: result.servers,
533
- embedUrl: result.embedUrl,
534
- sources: result.sources,
535
- audioTracks: result.audioTracks || [],
536
- subtitles: result.subtitles || [],
537
- referer: result.referer || '',
538
- valid: true,
539
- };
540
- }
541
- catch (e) {
542
- return {
543
- provider: mod.name,
544
- sources: [],
545
- audioTracks: [],
546
- valid: false,
547
- error: e.message,
548
- };
549
- }
550
- }),
551
- });