diff --git a/docs/providers/flixhq.md b/docs/providers/flixhq.md index a05928e43..7d72d8213 100644 --- a/docs/providers/flixhq.md +++ b/docs/providers/flixhq.md @@ -364,3 +364,93 @@ output: {...}, ] ``` + +### fetchByCountry + +

Parameters

+ +| Parameter | Type | Description | +| --------------- | -------- | ----------------------------------------------------------------------- | +| country | `string` | param to filter by country. (*In this case, We're filtering by `KR`*) | +| page (optional) | `number` | page number (default: 1) | + +```ts +flixhq.fetchByCountry('KR').then(data => { + console.log(data); +}) +``` + +returns a promise which resolves into an array of movies/tv series. (*[`Promise>`](https://github.com/consumet/extensions/blob/master/src/models/types.ts#L233-L241)*)\ +output: +```js +{ + currentPage: 1, + hasNextPage: true, + results: [ + { + id: 'tv/watch-wedding-impossible-106609', + title: 'Wedding Impossible', + url: 'https://flixhq.to/tv/watch-wedding-impossible-106609', + image: 'https://img.flixhq.to/xxrz/250x400/379/d1/8c/d18c569318ce319a57ba681c69b01d73/d18c569318ce319a57ba681c69b01d73.jpg', + season: 'SS 1', + latestEpisode: 'EPS 1', + type: 'TV Series' + }, + { + id: 'tv/watch-a-killer-paradox-106036', + title: 'A Killer Paradox', + url: 'https://flixhq.to/tv/watch-a-killer-paradox-106036', + image: 'https://img.flixhq.to/xxrz/250x400/379/89/a0/89a0eede251cff2c9acf24fe64e2fe01/89a0eede251cff2c9acf24fe64e2fe01.jpg', + season: 'SS 1', + latestEpisode: 'EPS 8', + type: 'TV Series' + }, + {...} + ] +} +``` + +### fetchByGenre + +

Parameters

+ +| Parameter | Type | Description | +| --------------- | -------- | ---------------------------------------------------------------------- | +| genre | `string` | param to filter by genre. (*In this case, We're filtering by `drama`*) | +| page (optional) | `number` | page number (default: 1) | + +```ts +flixhq.fetchByGenre('drama').then(data => { + console.log(data); +}) +``` + +returns a promise which resolves into an array of movies/tv series. (*[`Promise>`](https://github.com/consumet/extensions/blob/master/src/models/types.ts#L233-L241)*)\ +output: +```js +{ + currentPage: 1, + hasNextPage: true, + results: [ + { + id: 'movie/watch-no-new-friends-105202', + title: 'No New Friends', + url: 'https://flixhq.to/movie/watch-no-new-friends-105202', + image: 'https://img.flixhq.to/xxrz/250x400/379/16/30/16304d1c6302e6b078f6b74d5ff58347/16304d1c6302e6b078f6b74d5ff58347.jpg', + releaseDate: '2024', + seasons: undefined, + type: 'Movie' + }, + { + id: 'tv/watch-shogun-106618', + title: 'Shōgun', + url: 'https://flixhq.to/tv/watch-shogun-106618', + image: 'https://img.flixhq.to/xxrz/250x400/379/a7/fc/a7fca6a36c98856de5e71d120a16e521/a7fca6a36c98856de5e71d120a16e521.jpg', + releaseDate: undefined, + seasons: 1, + type: 'TV Series' + }, + {...} + ] +} +``` diff --git a/src/providers/movies/flixhq.ts b/src/providers/movies/flixhq.ts index 3846b4fed..a7d2db82b 100644 --- a/src/providers/movies/flixhq.ts +++ b/src/providers/movies/flixhq.ts @@ -401,12 +401,12 @@ class FlixHQ extends MovieParser { $('div.container > section.block_area > div.block_area-content > div.film_list-wrap > div.flw-item') .each((i, el) => { result.results.push({ - id: $(el).find('div.film-poster > a').attr('href')?.slice(1)!, - title: $(el).find('div.film-detail > h2.film-name > a').attr('title')!, + id: $(el).find('div.film-poster > a').attr('href')?.slice(1) ?? '', + title: $(el).find('div.film-detail > h2.film-name > a').attr('title') ?? '', url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`, image: $(el).find('div.film-poster > img').attr('data-src'), season: $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text(), - latestEpisode: $(el).find('div.film-detail > div.fd-infor > span:nth-child(3)').text() || null, + latestEpisode: $(el).find('div.film-detail > div.fd-infor > span:nth-child(3)').text() ?? null, type: $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie' ? TvType.MOVIE @@ -420,15 +420,55 @@ class FlixHQ extends MovieParser { throw new Error((err as Error).message); } }; + + fetchByGenre = async (genre: string, page: number = 1): Promise> => { + const result: ISearch = { + currentPage: page, + hasNextPage: false, + results: [], + }; + try { + const { data } = await this.client.get( + `${this.baseUrl}/genre/${genre}?page=${page}` + ); + + const $ = load(data); + + const navSelector = 'div.pre-pagination:nth-child(3) > nav:nth-child(1) > ul:nth-child(1)'; + + result.hasNextPage = + $(navSelector).length > 0 ? !$(navSelector).children().last().hasClass('active') : false; + + $('.film_list-wrap > div.flw-item').each((i, el) => { + const releaseDate = $(el).find('div.film-detail > div.fd-infor > span:nth-child(1)').text(); + result.results.push({ + id: $(el).find('div.film-poster > a').attr('href')?.slice(1) ?? '', + title: $(el).find('div.film-detail > h2 > a').attr('title') ?? '', + url: `${this.baseUrl}${$(el).find('div.film-poster > a').attr('href')}`, + image: $(el).find('div.film-poster > img').attr('data-src'), + releaseDate: isNaN(parseInt(releaseDate)) ? undefined : releaseDate, + seasons: releaseDate.includes('SS') ? parseInt(releaseDate.split('SS')[1]) : undefined, + type: + $(el).find('div.film-detail > div.fd-infor > span.float-right').text() === 'Movie' + ? TvType.MOVIE + : TvType.TVSERIES, + }); + }); + + return result; + } catch (err) { + throw new Error((err as Error).message); + } + }; } // (async () => { -// const movie = new FlixHQ(); +// const movie = new FlixHQ(); // const search = await movie.search('the flash'); // // const movieInfo = await movie.fetchEpisodeSources('1168337', 'tv/watch-vincenzo-67955'); // // const recentTv = await movie.fetchTrendingTvShows(); -// // const search = await movie.fetchByCountry('KR') -// // console.log(search); -//})(); +// // const genre = await movie.fetchByCountry('KR') +// // console.log(genre) +// })(); export default FlixHQ; diff --git a/test/movies/flixhq.test.ts b/test/movies/flixhq.test.ts index 31ee0cc3c..ecdb80e76 100644 --- a/test/movies/flixhq.test.ts +++ b/test/movies/flixhq.test.ts @@ -24,3 +24,8 @@ test('returns a filled object of movies/tv data by country', async () => { const data = await flixhq.fetchByCountry('KR'); expect(data.results).not.toEqual([]); }); + +test('returns a filled object of movies/tv data by genre', async () => { + const data = await flixhq.fetchByGenre('drama'); + expect(data.results).not.toEqual([]); +});