From 518d70d4a8454723456762f0771e46fab8339132 Mon Sep 17 00:00:00 2001 From: Nathan JAUNET Date: Wed, 11 Oct 2023 14:37:58 +0200 Subject: [PATCH 1/2] #11: Fix Apple tv parsing --- src/Flixpatrol/FlixPatrol.ts | 22 +++++++++++++++++----- src/Trakt/TraktAPI.ts | 4 +++- src/app.ts | 17 +++++------------ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Flixpatrol/FlixPatrol.ts b/src/Flixpatrol/FlixPatrol.ts index 9ee0ca9..f69bb1d 100644 --- a/src/Flixpatrol/FlixPatrol.ts +++ b/src/Flixpatrol/FlixPatrol.ts @@ -84,7 +84,8 @@ export class FlixPatrol { const dom = new JSDOM(html); let expression; if (location !== 'world') { - expression = `//h3[text() = "TOP 10 ${type}"]/following-sibling::div//a[@class="hover:underline"]/@href`; + const searchType = platform === 'apple-tv' ? 'Overall' : type; + expression = `//h3[text() = "TOP 10 ${searchType}"]/following-sibling::div//a[@class="hover:underline"]/@href`; } else { const id = type === 'Movies' ? 1 : 2; expression = `//div[@id="${platform}-${id}"]//a[contains(@class, "hover:underline")]/@href`; @@ -106,7 +107,7 @@ export class FlixPatrol { return results; } - private async convertToTMDBId(result: FlixPatrolMatchResult) : Promise { + private async convertToTMDBId(result: FlixPatrolMatchResult, type: FlixPatrolType) : Promise { const html = await this.getFlixPatrolHTMLPage(result); if (html === null) { logger.error('FlixPatrol Error: unable to get FlixPatrol detail page'); @@ -122,11 +123,22 @@ export class FlixPatrol { null, ); - const regex = match.stringValue.match(/(themoviedb\.org)(\D*)(\d+)/i); + let regex; + if (type === 'Movies') { + regex = match.stringValue.match(/(themoviedb\.org\/movie)(\D*)(\d+)/i); + } else { + regex = match.stringValue.match(/(themoviedb\.org\/tv)(\D*)(\d+)/i); + } + return regex ? regex[3] : null; } - public async getTop10(type: FlixPatrolType, platform: FlixPatrolPlatform, location: FlixPatrolLocation, fallback: FlixPatrolLocation | false): Promise { + public async getTop10( + type: FlixPatrolType, + platform: FlixPatrolPlatform, + location: FlixPatrolLocation, + fallback: FlixPatrolLocation | false, + ): Promise { const html = await this.getFlixPatrolHTMLPage(`/top10/${platform}/${location}`); if (html === null) { logger.error('FlixPatrol Error: unable to get FlixPatrol top10 page'); @@ -143,7 +155,7 @@ export class FlixPatrol { // eslint-disable-next-line no-restricted-syntax for (const result of results) { // eslint-disable-next-line no-await-in-loop - const id = await this.convertToTMDBId(result); + const id = await this.convertToTMDBId(result, type); if (id) { TMDBIds.push(id); } diff --git a/src/Trakt/TraktAPI.ts b/src/Trakt/TraktAPI.ts index df17624..26e4d46 100644 --- a/src/Trakt/TraktAPI.ts +++ b/src/Trakt/TraktAPI.ts @@ -167,6 +167,8 @@ export class TraktAPI { // Avoid Trakt rate limite await Utils.sleep(2000); } - await this.addItemsToList(list, tmdbIDs, traktType); + if (tmdbIDs.length > 0) { + await this.addItemsToList(list, tmdbIDs, traktType); + } } } diff --git a/src/app.ts b/src/app.ts index eb69945..53581a6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -25,25 +25,18 @@ trakt.connect().then(async () => { // eslint-disable-next-line no-restricted-syntax for (const flixPatrolConfig of flixPatrolConfigs) { const listName = `${flixPatrolConfig.platform}-${flixPatrolConfig.location}-top10-${flixPatrolConfig.fallback === false ? 'without-fallback' : `with-${flixPatrolConfig.fallback}-fallback`}`; + const top10Movies = await flixpatrol.getTop10('Movies', flixPatrolConfig.platform, flixPatrolConfig.location, flixPatrolConfig.fallback); logger.debug(`${flixPatrolConfig.platform} movies: ${top10Movies}`); - if (top10Movies.length > 0) { - await trakt.pushToList(top10Movies, listName, 'Movies', flixPatrolConfig.privacy); - logger.info(`List ${listName} updated with new movies`); - } else { - logger.warn(`No movies found for ${flixPatrolConfig.platform}`); - } + await trakt.pushToList(top10Movies, listName, 'Movies', flixPatrolConfig.privacy); + logger.info(`List ${listName} updated with ${top10Movies.length} new movies`); // Avoid rate limit on Trakt and spam FlixPatrol await Utils.sleep(5000); const top10Shows = await flixpatrol.getTop10('TV Shows', flixPatrolConfig.platform, flixPatrolConfig.location, flixPatrolConfig.fallback); logger.debug(`${flixPatrolConfig.platform} shows: ${top10Shows}`); - if (top10Shows.length > 0) { - await trakt.pushToList(top10Shows, listName, 'TV Shows', flixPatrolConfig.privacy); - logger.info(`List ${listName} updated with new shows`); - } else { - logger.warn(`No shows found for ${flixPatrolConfig.platform}`); - } + await trakt.pushToList(top10Shows, listName, 'TV Shows', flixPatrolConfig.privacy); + logger.info(`List ${listName} updated with ${top10Shows.length} new shows`); } }); From cb8f4521f5a3a1057a149d501d4464948d459e0f Mon Sep 17 00:00:00 2001 From: Nathan JAUNET Date: Wed, 11 Oct 2023 14:46:51 +0200 Subject: [PATCH 2/2] Bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5cd817e..d4985f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flixpatrol-top10", - "version": "1.2.3", + "version": "1.2.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "flixpatrol-top10", - "version": "1.2.3", + "version": "1.2.5", "license": "GPL-3.0", "dependencies": { "axios": "^1.5.1", diff --git a/package.json b/package.json index 27d0369..1956c68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flixpatrol-top10", - "version": "1.2.4", + "version": "1.2.5", "description": "Get top10 list from flixpatrol and upload them to trakt", "main": "app.js", "scripts": {