UNPKG

@iptv/xtream-api

Version:

Standardized access to Xtream compatible player API

305 lines (304 loc) 8.05 kB
import D from "camelcase-keys"; import { defineSerializers as J } from "./index.js"; const W = J("Standardized", { profile: (e) => { const { auth: o, expDate: a, maxConnections: r, activeCons: i, createdAt: t, ...s } = D(e); return { id: s.username, ...s, isTrial: s.isTrial === "1", maxConnections: Number(r), activeConnections: Number(i), createdAt: new Date(Number(t) * 1e3), expiresAt: new Date(Number(a) * 1e3) }; }, serverInfo: (e) => { const { timestampNow: o, ...a } = D(e); return { id: e.url, ...a, timeNow: new Date(Number(o) * 1e3) }; }, channelCategories: (e) => B(e), movieCategories: (e) => B(e), showCategories: (e) => B(e), channels: (e) => D(e).map((a) => { const { added: r, num: i, streamId: t, categoryIds: s, streamIcon: m, epgChannelId: u, tvArchive: c, url: l, name: g, tvArchiveDuration: I } = a; return { id: t.toString(), name: g, number: i, tvArchive: c === 1, tvArchiveDuration: I, logo: m, epgId: u, createdAt: new Date(Number(r) * 1e3), categoryIds: s.map((N) => N.toString()), url: l }; }), movies: (e) => D(e).map((a) => { const { streamIcon: r, streamId: i, releaseDate: t, rating: s, added: m, categoryIds: u, episodeRunTime: c, genre: l, cast: g, director: I, youtubeTrailer: N, title: w, plot: f, url: y } = a; return { id: i.toString(), name: w, plot: f, genre: l?.split(",").map((n) => n.trim()) ?? [], cast: g?.split(",").map((n) => n.trim()) ?? [], director: I?.split(",").map((n) => n.trim()) ?? [], poster: r, duration: Number(c) * 60, voteAverage: Number(s), releaseDate: t ? new Date(t) : null, youtubeId: N, createdAt: new Date(Number(m) * 1e3), categoryIds: u.map((n) => n.toString()), url: y }; }), movie: (e) => { const o = D(e, { deep: !0 }), { director: a, actors: r, genre: i, cast: t, oName: s, releaseDate: m, mpaaRating: u, age: c, rating: l, duration: g, durationSecs: I, backdropPath: N, movieImage: w, kinopoiskUrl: f, youtubeTrailer: y, tmdbId: n, name: z, description: C, plot: S, country: T, subtitles: d } = o.info, { categoryIds: v, streamId: b, added: h } = o.movieData; return { id: b.toString(), name: z, description: C, plot: S, country: T, informationUrl: f, originalName: s, cover: N[0], poster: w, duration: I, durationFormatted: g, voteAverage: l, director: a?.split(",").map((p) => p.trim()) ?? [], actors: r?.split(",").map((p) => p.trim()) ?? [], cast: t?.split(",").map((p) => p.trim()) ?? [], genre: i?.split(",").map((p) => p.trim()) ?? [], categoryIds: v.map((p) => p.toString()), tmdbId: n.toString(), youtubeId: y, releaseDate: m ? new Date(m) : null, createdAt: new Date(Number(h) * 1e3), rating: { mpaa: u, age: Number(c) }, subtitles: d, url: o.url }; }, shows: (e) => D(e).map((a) => { const { rating: r, seriesId: i, cover: t, categoryIds: s, backdropPath: m, releaseDate: u, episodeRunTime: c, lastModified: l, cast: g, director: I, genre: N, youtubeTrailer: w, title: f, plot: y } = a; return { id: i.toString(), name: f, plot: y, cast: g?.split(",").map((n) => n.trim()) ?? [], director: I?.split(",").map((n) => n.trim()) ?? [], genre: N?.split(",").map((n) => n.trim()) ?? [], voteAverage: Number(r), poster: t, cover: m[0], duration: Number(c) * 60, releaseDate: u ? new Date(u) : null, updatedAt: new Date(Number(l) * 1e3), categoryIds: s.map((n) => n.toString()), youtubeId: w }; }), show: (e) => { const { seasons: o, info: a, episodes: r } = D(e, { deep: !0 }), { rating: i, seriesId: t, cover: s, categoryIds: m, backdropPath: u, releaseDate: c, episodeRunTime: l, lastModified: g, cast: I, director: N, genre: w, youtubeTrailer: f, title: y, plot: n } = a; if (typeof t > "u") throw new Error("seriesId is required"); const C = Object.values(r).flat().map((d) => { const { id: v, season: b, episodeNum: h, added: p, info: E, title: P, url: k, subtitles: x } = d, { releaseDate: A, movieImage: M, coverBig: R, rating: j, durationSecs: F, duration: G, tmdbId: L, plot: O, video: U, audio: q, bitrate: K } = E, $ = o.find((H) => H.seasonNumber === b)?.id.toString() || b.toString(); return { id: v, number: Number(h), plot: O, title: P, tmdbId: L?.toString(), poster: M, voteAverage: j, cover: R, duration: F, durationFormatted: G, releaseDate: A ? new Date(A) : null, createdAt: new Date(Number(p) * 1e3), showId: t.toString(), seasonId: $, url: k, subtitles: x, video: U, audio: q, bitrate: K }; }); let S = o; S.length === 0 && (S = Object.keys(r).map((d) => { const v = d, b = r[d][0]; return { id: Number(v), name: `Season ${v}`, episodeCount: r[d].length, overview: "", airDate: b.info.releaseDate, cover: b.info.movieImage, seasonNumber: Number(v), voteAverage: Number(b.info.rating), coverBig: b.info.movieImage }; })); const T = S.map((d) => { const { id: v, seasonNumber: b, coverBig: h, airDate: p, name: E, episodeCount: P, overview: k, voteAverage: x } = d; return { id: v.toString(), name: E, episodeCount: P, overview: k, voteAverage: x, releaseDate: p ? new Date(p) : null, number: b, cover: h, showId: t.toString(), episodes: C.filter((A) => A.seasonId === v.toString()) }; }); return { id: t.toString(), name: y, plot: n, voteAverage: Number(i), poster: s, cover: u[0], duration: Number(l) * 60, cast: I?.split(",").map((d) => d.trim()) ?? [], director: N?.split(",").map((d) => d.trim()) ?? [], genre: w?.split(",").map((d) => d.trim()) ?? [], youtubeId: f, releaseDate: c ? new Date(c) : null, updatedAt: new Date(Number(g) * 1e3), categoryIds: m.map((d) => d.toString()), seasons: T }; }, shortEPG: (e) => { const { epgListings: o } = D(e, { deep: !0 }); return o.map((a) => { const { lang: r, start: i, end: t, title: s, description: m, id: u, epgId: c, channelId: l } = a; return { id: u, epgId: c, channelId: l, start: new Date(i), end: new Date(Number(t) * 1e3), title: atob(s), description: atob(m), language: r }; }); }, fullEPG: (e) => { const { epgListings: o } = D(e, { deep: !0 }); return o.map((a) => { const { lang: r, start: i, end: t, title: s, description: m, nowPlaying: u, hasArchive: c, id: l, epgId: g, channelId: I } = a; return { id: l, epgId: g, channelId: I, start: new Date(i), end: new Date(t), title: atob(s), description: atob(m), language: r, nowPlaying: !!u, hasArchive: !!c }; }); } }); function B(e) { return D(e).map((a) => { const { categoryId: r, categoryName: i, parentId: t } = a; return { id: r.toString(), name: i, parentId: t.toString() }; }); } export { W as standardizedSerializer };