UNPKG

cinemeta.js

Version:

A Simple Name To IMDB Finder based on cinemeta

85 lines (62 loc) 3.07 kB
const axios = require("axios"); const searchDB = (searchStr) => (item) => item.imdb_id === searchStr || item.name.toLowerCase() === searchStr.toLowerCase() || item.name.toLowerCase().includes(searchStr.toLowerCase()); class Cinemeta { async searchMovie(input) { let res = await axios.get("https://cinemeta.strem.io/stremioget/stremio/v1/q.json?b=eyJwYXJhbXMiOltudWxsLHt9XSwibWV0aG9kIjoibmFtZXMubW92aWUiLCJpZCI6MSwianNvbnJwYyI6IjIuMCJ9"); let searchFor = searchDB(input); const result = res.data.result.filter(searchFor); result.forEach?.(x => x.type = "movie") return result; } async searchSeries(input){ let res = await axios.get("https://cinemeta.strem.io/stremioget/stremio/v1/q.json?b=eyJwYXJhbXMiOltudWxsLHt9XSwibWV0aG9kIjoibmFtZXMuc2VyaWVzIiwiaWQiOjEsImpzb25ycGMiOiIyLjAifQ"); let searchFor = searchDB(input); const result = res.data.result.filter(searchFor); result.forEach?.(x => x.type = "series") return result; } async search(name){ let arr = [] const movie = await this.searchMovie(name) const series = await this.searchSeries(name) return arr.concat(movie, series) } async searchOTBOYearMovie(year){ let res = await axios.get("https://cinemeta.strem.io/stremioget/stremio/v1/q.json?b=eyJwYXJhbXMiOltudWxsLHt9XSwibWV0aG9kIjoibmFtZXMubW92aWUiLCJpZCI6MSwianNvbnJwYyI6IjIuMCJ9"); const result = res.data.result.filter(x => x.year === year); result.forEach?.(x => x.type = "movie") return result; } async searchOTBOYearSeries(year){ let res = await axios.get("https://cinemeta.strem.io/stremioget/stremio/v1/q.json?b=eyJwYXJhbXMiOltudWxsLHt9XSwibWV0aG9kIjoibmFtZXMuc2VyaWVzIiwiaWQiOjEsImpzb25ycGMiOiIyLjAifQ"); const result = res.data.result.filter(x => x.year === year); result.forEach?.(x => x.type = "series") return result; } async searchOTBOYear(year){ let arr = [] const movie = await this.searchOTBOYearMovie(year) const series = await this.searchOTBOYearSeries(year) return arr.concat(movie, series) } async randomMovie() { let res = await axios.get("https://cinemeta.strem.io/stremioget/stremio/v1/q.json?b=eyJwYXJhbXMiOltudWxsLHt9XSwibWV0aG9kIjoibmFtZXMubW92aWUiLCJpZCI6MSwianNvbnJwYyI6IjIuMCJ9"); const random = res.data.result[Math.floor(Math.random() * res.data.result.length)] random.type = "movie" return random } async randomSeries(){ let res = await axios.get("https://cinemeta.strem.io/stremioget/stremio/v1/q.json?b=eyJwYXJhbXMiOltudWxsLHt9XSwibWV0aG9kIjoibmFtZXMuc2VyaWVzIiwiaWQiOjEsImpzb25ycGMiOiIyLjAifQ"); const random = res.data.result[Math.floor(Math.random() * res.data.result.length)] random.type = "series" return random } async random(){ const movie = await this.randomMovie() const series = await this.randomSeries() let arr = [movie, series] return arr[Math.floor(Math.random() * arr.length)] } } module.exports = new Cinemeta()