UNPKG

panjareh

Version:

Panjareh using aparat and phoenix-video-player to play videos on desktops and tvs.

187 lines (163 loc) 4.87 kB
import urls from "./urls"; const FULL_TITLE_DIVIVER = " . "; const ADULT_CHILD_AGE_CONTENT_BORDER = 7; function resolveImage(image) { if (!image) return ""; if (Array.isArray(image)) { if (image.length > 0) return (urls.baseUrl + image[0].url) .replace(/\/\//g, "/") .replace("https:/", "https://"); } else if (typeof image === "object") { return (urls.baseUrl + image.url) .replace(/\/\//g, "/") .replace("https:/", "https://"); } else if (typeof image === "string") { return (urls.baseUrl + image) .replace(/\/\//g, "/") .replace("https:/", "https://"); } else return ""; return ""; } // remove and flatten serialData with product to get cleaner series object function normalizeSeriesData(data) { if (data.serialData) { let normalized = { ...data, ...data.serialData }; delete normalized.serialData; return normalized; } return data; } const ProductStatusType = { WATCH: "watch", UNAVAILABLE: "unavailable", COMINGSOON: "comingSoon", FREE: "free", BANNED: "vpn", UPGRADE: "upgrade", SUBSCRIPTION: "subscription", EXPIRE: "expire", EKRAN: "ekran", }; class Product { // static SomeObject = ; constructor(data) { Object.assign(this, normalizeSeriesData(data)); } // get StaticType() { // static // } getId() { return this.nid; } isEkran() { return !!this.hasEkran; } isSeries() { return this.isSerial || false; } getToken() { if (this.ekranData) return this.ekranData.token; } getTitle() { return this.title; } getDuration(textual = false) { if (textual) { return "'" + this.duration + ` دقیقه `; } return parseInt(this.duration); } getFullTitle() { let title = ""; if (this.isSeries()) { const { serialSeason, serialPart, serialSpecialTitle } = this; if (serialSeason) { title += `${"فصل"}${" "}${serialSeason}`; } if (serialPart) { title += `${FULL_TITLE_DIVIVER}${"قسمت"}${" "}${serialPart}`; } if (serialSpecialTitle) { title += `${FULL_TITLE_DIVIVER}${serialSpecialTitle}`; } } else { title += this.getTitle(); } return title; } getImage(type) { switch (type) { case "vb": // vertical big poster return resolveImage(this.poster || this.verticalPoster); case "vs": // vertical small poster // Tips: we dont have small poster yet return resolveImage(this.poster || this.verticalPoster); case "hb": // horizontal big poster return resolveImage(this.horizontalBigPoster); case "hs": // horizontal small poster return resolveImage(this.horizontalSmallPoster); case "mb": // main big poster return resolveImage(this.mainAndProductBigPoster); case "ms": // main small poster return resolveImage(this.mainAndProductSmallPoster); case "sp": // special poster return resolveImage(this.specialPoster); default: return resolveImage(this.poster || this.verticalPoster); } // mainAndProductBigPoster } getSeasons() { if (!this.isSeries()) return; return this.seasonExist || []; } getNextEpisode() { if (!this.isSeries()) return; if (this.next) { return new Product(this.next); } } // TODO: examine if this method (getProviderIds) still needed getProviderIds() { const _data = { arvan: null, kavimo: null, daya: null, filmgardi: null, defaultStream: null, }; if (this.provider) { if (this.provider.stream) _data.defaultStream = this.provider.stream; } if (this.providerId) { // Object.assign(_data, data.providerId); if (this.providerId.ad) _data.arvan = this.providerId.ad; if (this.providerId.kd) _data.kavimo = this.providerId.kd; if (this.providerId.dd) _data.daya = this.providerId.dd; if (this.providerId.fd) _data.filmgardi = this.providerId.fd; } return _data; } getProductStatus() { if (this.isEkran()) return ProductStatusType.EKRAN; const productStatus = this.productStatus; if (productStatus && productStatus.length > 0) { const _productStatus = productStatus[0]; if (_productStatus.tid === 164) return ProductStatusType.UNAVAILABLE; else if (_productStatus.tid === 165) return ProductStatusType.COMINGSOON; else if (_productStatus.tid === "vpn") return ProductStatusType.BANNED; else return ProductStatusType.WATCH; } else return ProductStatusType.WATCH; } canWatch() { return this.getProductStatus() === ProductStatusType.WATCH; } isAdultContent() { return this.ageClassification ? this.ageClassification > ADULT_CHILD_AGE_CONTENT_BORDER : !0; } } export { resolveImage }; export default Product;