Skip to content

Commit

Permalink
Add type and name options for popular lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Navino16 committed Sep 3, 2024
1 parent 028b90f commit f3cd1e7
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 40 deletions.
62 changes: 37 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ To get started with Flixpatrol Top 10 on Trakt for Docker, follow these simple s
### Environment variable
You can pass some environment variables to the tool:

| Name | Descriptions | Values | Default |
|-----------|-----------------------------|--------------------------|---------|
| LOG_LEVEL | How verbose the log will be | error, warn, info, debug | info |
| Name | Descriptions | Values | Default |
|-----------|-----------------------------|---------------------------------|---------|
| LOG_LEVEL | How verbose the log will be | error, warn, info, debug, silly | info |

### Configuration file
The configuration file should be stored in a directory named `config` next to the binary.
Expand All @@ -107,26 +107,28 @@ At first run a default configuration file will be generated with some top10 prec

If there is any configuration error, the tool will exit whit information about the error.

| Name | Descriptions | Values | Default |
|------------------------|------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| FlixPatrolTop10 | An array containing as much as you want top10Config | | |
| top10Config.platform | Which platform to get from Flixpatrol | Any Flixpatrol platform ([see this](https://github.com/Navino16/flixpatrol-top10-on-trakt/blob/main/src/Flixpatrol/FlixPatrol.ts#L48)) | |
| top10Config.location | Which location to get from Flixpatrol | Any Flixpatrol location ([see this](https://github.com/Navino16/flixpatrol-top10-on-trakt/blob/main/src/Flixpatrol/FlixPatrol.ts#L22)) | |
| top10Config.fallback | If there is no show/movie found, should we fallback to another location? | False or any Flixpatrol location ([see this](https://github.com/Navino16/flixpatrol-top10-on-trakt/blob/main/src/Flixpatrol/FlixPatrol.ts#L22)) | false |
| top10Config.privacy | The privacy of the generated Trakt list | private, public | private |
| top10Config.limit | How many movie/show we should get from Flixpatrol | Number between 1 and 10 (included) | 10 |
| top10Config.type | Do you want movies, shows or both ? | movies, shows, both | both |
| top10Config.name | Optional name of the list | Any valid string | A generated name based on the top10 config |
| FlixPatrolPopular | An array containing as much as you want popularConfig | | |
| popularConfig.platform | Which popular platform to get from Flixpatrol | Any Flixpatrol popular platform ([see this](https://github.com/Navino16/flixpatrol-top10-on-trakt/blob/main/src/Flixpatrol/FlixPatrol.ts#L53)) | |
| popularConfig.privacy | The privacy of the generated Trakt list | private, public | private |
| popularConfig.limit | How many movie/show we should get from Flixpatrol | Number between 1 and 100 (included) | 100 |
| Trakt.saveFile | Where to save the Trakt session file | Any valid path | ./config/.trakt |
| Trakt.clientId | You clientId from Trakt ([here](https://trakt.tv/oauth/applications/new) to get a new one) | A valid traktId | |
| Trakt.clientSecret | You clientSecret from Trakt ([here](https://trakt.tv/oauth/applications/new) to get a new one) | A valid clientSecret | |
| Cache.enabled | Do you want to use cache? (You should) | true, false | true |
| Cache.savePath | Where to save the caches files | Any valid path | ./config/.cache |
| Cache.ttl | How long the cache will be valid in seconds | Any number greater than 0 | 604800 |
| Name | Descriptions | Mandatory | Values | Default |
|------------------------|------------------------------------------------------------------------------------------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| FlixPatrolTop10 | An array containing as much as you want top10Config | Yes | | |
| top10Config.platform | Which platform to get from Flixpatrol | Yes | Any Flixpatrol platform ([see this](https://github.com/Navino16/flixpatrol-top10-on-trakt/blob/main/src/Flixpatrol/FlixPatrol.ts#L48)) | |
| top10Config.location | Which location to get from Flixpatrol | Yes | Any Flixpatrol location ([see this](https://github.com/Navino16/flixpatrol-top10-on-trakt/blob/main/src/Flixpatrol/FlixPatrol.ts#L22)) | |
| top10Config.fallback | If there is no show/movie found, should we fallback to another location? | Yes | False or any Flixpatrol location ([see this](https://github.com/Navino16/flixpatrol-top10-on-trakt/blob/main/src/Flixpatrol/FlixPatrol.ts#L22)) | false |
| top10Config.privacy | The privacy of the generated Trakt list | Yes | private, public | private |
| top10Config.limit | How many movie/show we should get from Flixpatrol | Yes | Number between 1 and 10 (included) | 10 |
| top10Config.type | Do you want movies, shows or both ? | Yes | movies, shows, both | both |
| top10Config.name | Optional name of the list | No | Any valid string | A generated name based on the top10 config |
| FlixPatrolPopular | An array containing as much as you want popularConfig | Yes | | |
| popularConfig.platform | Which popular platform to get from Flixpatrol | Yes | Any Flixpatrol popular platform ([see this](https://github.com/Navino16/flixpatrol-top10-on-trakt/blob/main/src/Flixpatrol/FlixPatrol.ts#L53)) | |
| popularConfig.privacy | The privacy of the generated Trakt list | Yes | private, public | private |
| popularConfig.limit | How many movie/show we should get from Flixpatrol | Yes | Number between 1 and 100 (included) | 100 |
| popularConfig.type | Do you want movies, shows or both ? | Yes | movies, shows, both | both |
| popularConfig.name | Optional name of the list | No | Any valid string | A generated name based on the top10 config |
| Trakt.saveFile | Where to save the Trakt session file | Yes | Any valid path | ./config/.trakt |
| Trakt.clientId | You clientId from Trakt ([here](https://trakt.tv/oauth/applications/new) to get a new one) | Yes | A valid traktId | |
| Trakt.clientSecret | You clientSecret from Trakt ([here](https://trakt.tv/oauth/applications/new) to get a new one) | Yes | A valid clientSecret | |
| Cache.enabled | Do you want to use cache? (You should) | Yes | true, false | true |
| Cache.savePath | Where to save the caches files | Yes | Any valid path | ./config/.cache |
| Cache.ttl | How long the cache will be valid in seconds | Yes | Any number greater than 0 | 604800 |

#### Example file
````json
Expand Down Expand Up @@ -180,7 +182,15 @@ If there is any configuration error, the tool will exit whit information about t
{
"platform": "movie-db",
"privacy": "private",
"limit": 100
"limit": 100,
"type": "both",
"name": "Most popular titles in Movie DBs"
},
{
"platform": "imdb",
"privacy": "private",
"limit": 100,
"type": "both"
}
],
"Trakt": {
Expand All @@ -201,7 +211,9 @@ If there is any configuration error, the tool will exit whit information about t
To run this application you need to have a Trakt account and a Client ID / Client Secret.

⚠️ Trakt is limited to 5 list on free account, if you specified more than 5 platform on config the script will fail.
Remove some platform from the config or take a VIP account on Trakt
Remove some platform from the config or take a VIP account on Trakt.

If you consider taking a VIP account, use [my link](https://trakt.tv/vip/referral/9513cc9d5d23fead61043a893e68cff7) to create your trakt account. We both get **free VIP** for 1 month.

1. Go [here to create a new one](https://trakt.tv/auth/join) or [here to login](https://trakt.tv/login).
2. [Create a new application](https://trakt.tv/oauth/applications/new) on your Trakt account
Expand Down
10 changes: 9 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@
{
"platform": "movie-db",
"privacy": "private",
"limit": 100
"limit": 100,
"type": "both",
"name": "Most popular titles in Movie DBs"
},
{
"platform": "imdb",
"privacy": "private",
"limit": 100,
"type": "both"
}
],
"Trakt": {
Expand Down
22 changes: 22 additions & 0 deletions src/Utils/GetAndValidateConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface FlixPatrolPopular {
platform: FlixPatrolTop10Platform;
privacy: TraktPrivacy;
limit: number;
type: string;
name?: string;
}

export class GetAndValidateConfigs {
Expand Down Expand Up @@ -173,6 +175,26 @@ export class GetAndValidateConfigs {
logger.error(`Configuration Error: Property "FlixPatrolPopular[${index}].limit" -> limit should be a value between 1 and 100`);
process.exit(1);
}

// Check if type property is valid
if (!Object.prototype.hasOwnProperty.call(flixPatrolPopularConfig, 'type')) {
logger.error(`Configuration Error: Property "FlixPatrolPopular[${index}].type" -> type not found`);
process.exit(1);
}
if (typeof flixPatrolPopularConfig.type !== 'string') {
logger.error(`Configuration Error: Property "FlixPatrolPopular[${index}].type" -> not a valid string`);
process.exit(1);
}
if (!FlixPatrol.isFlixPatrolType(flixPatrolPopularConfig.type)) {
logger.error(`Configuration Error: Property "FlixPatrolPopular[${index}].type" -> ${flixPatrolPopularConfig.type} is not a valid type. Must be 'movies', 'shows' or 'both'`);
process.exit(1);
}

// Check if optional name property is valid
if (typeof flixPatrolPopularConfig.name !== 'string' && flixPatrolPopularConfig.name !== undefined) {
logger.error(`Configuration Error: Property "FlixPatrolPopular[${index}].name" -> not a valid string`);
process.exit(1);
}
});
} catch (err) {
logger.error(`Configuration Error: ${err}`);
Expand Down
10 changes: 9 additions & 1 deletion src/Utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ export class Utils {
+ ' "FlixPatrolPopular": [\n'
+ ' {\n'
+ ' "platform": "movie-db",\n'
+ ' "name": "Most popular titles in Movie DBs",\n'
+ ' "privacy": "private",\n'
+ ' "limit": 100\n'
+ ' "limit": 100,\n'
+ ' "type": "both",\n'
+ ' },\n'
+ ' {\n'
+ ' "platform": "imdb",\n'
+ ' "privacy": "private",\n'
+ ' "limit": 100,\n'
+ ' "type": "both",\n'
+ ' }\n'
+ ' ],\n'
+ ' "Trakt": {\n'
Expand Down
Loading

0 comments on commit f3cd1e7

Please sign in to comment.