mikmc commited on
Commit
0a67e7c
·
verified ·
1 Parent(s): 81362d5

Upload 22 files

Browse files
.dockerignore CHANGED
@@ -3,7 +3,6 @@ db
3
  log
4
  node_modules
5
  .dockerignore
6
- .env
7
  .gitattributes
8
  .gitignore
9
  Dockerfile
 
3
  log
4
  node_modules
5
  .dockerignore
 
6
  .gitattributes
7
  .gitignore
8
  Dockerfile
.env CHANGED
@@ -1,26 +1,28 @@
1
- # Change exposition port
2
- PORT=3000
3
-
4
- # URL to access the addon
5
  BASE_URL=http://localhost:3000
6
 
7
- CACHE_CATALOG_CONTENT_DURATION_DAYS=3
8
- CACHE_POSTER_CONTENT_DURATION_DAYS=7
 
9
 
10
- # Enable public instance
11
- TMDB_BEARER_TOKEN=
 
12
 
13
- # Define streaming catalog providers based on region
14
- # TMDB_LANGUAGE = iso_639_1 code from doc/languages.json
15
- # TMDB_WATCH_REGION= = iso_3166_1 code from doc/regions.json
16
- TMDB_LANGUAGE=en
17
- TMDB_WATCH_REGION=GB
18
 
19
- # Possible values are: info, debug
20
- # Default is 'info' if not specified; 'debug' provides more detailed logs
21
  LOG_LEVEL=info
22
 
23
- # The value can be expressed in days (d), weeks (w), or months (M).
24
- # For example, '3d' means that log files will be kept for 3 days before being deleted.
25
- # If LOG_INTERVAL_DELETION is not defined in the environment variables, the default value is '3d'.
26
- LOG_INTERVAL_DELETION=3d
 
 
 
 
1
+ # BASE_URL is the base URL for accessing the addon without a trailing slash.
2
+ # Example: https://tmdb-dice.stremio
3
+ # Ensure this URL is correctly configured for your environment.
 
4
  BASE_URL=http://localhost:3000
5
 
6
+ # Specifies the cache expiration duration for catalog content.
7
+ # The format is either days or hours, e.g., '3d' for 3 days or '3h' for 3 hours.
8
+ CATALOG_CONTENT_CACHE_DURATION=3d
9
 
10
+ # Specifies the cache expiration duration for RPDB posters.
11
+ # The format is either days or hours, e.g., '3d' for 3 days or '3h' for 3 hours.
12
+ RPDB_POSTER_CACHE_DURATION=3d
13
 
14
+ # The number of days after which application logs will be automatically deleted.
15
+ # Set this to a suitable duration to manage log file size and retention.
16
+ LOG_INTERVAL_DELETION=3d
 
 
17
 
18
+ # Defines the logging level for the application.
19
+ # Set to "info" for standard logging or "debug" for more detailed logs.
20
  LOG_LEVEL=info
21
 
22
+ # The environment in which the application is running.
23
+ # Typically set to "production" for live environments or "development" for testing and debugging.
24
+ NODE_ENV=production
25
+
26
+ # The port on which the addon will listen for incoming connections.
27
+ # Make sure this port is open and not used by other services.
28
+ PORT=3000
Dockerfile CHANGED
@@ -1,20 +1,11 @@
1
  FROM node:18-slim
2
 
3
- # Create the log and db directories and set permissions
4
- RUN mkdir -p /usr/src/app/log /usr/src/app/db && \
5
- chown -R node:node /usr/src/app/log /usr/src/app/db
6
-
7
- # Set the working directory
8
  WORKDIR /usr/src/app
9
 
10
- # Copy package.json and package-lock.json first
11
  COPY package*.json ./
12
 
13
- # Install dependencies
14
  RUN npm install
15
 
16
- # Copy the rest of your application files
17
  COPY . .
18
 
19
- # Command to run your application
20
- CMD ["node", "index.js"]
 
1
  FROM node:18-slim
2
 
 
 
 
 
 
3
  WORKDIR /usr/src/app
4
 
 
5
  COPY package*.json ./
6
 
 
7
  RUN npm install
8
 
 
9
  COPY . .
10
 
11
+ CMD ["node", "index.js"]
 
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 redd-ravenn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
index.js CHANGED
@@ -12,8 +12,6 @@ app.use(cors());
12
 
13
  app.use(express.static(path.join(__dirname, 'public')));
14
 
15
- app.use(express.json());
16
-
17
  app.use('/', routes);
18
 
19
  app.listen(PORT, () => {
 
12
 
13
  app.use(express.static(path.join(__dirname, 'public')));
14
 
 
 
15
  app.use('/', routes);
16
 
17
  app.listen(PORT, () => {
package-lock.json CHANGED
@@ -1,20 +1,18 @@
1
  {
2
- "name": "stremio-catalogs-providers",
3
  "version": "1.0.0",
4
  "lockfileVersion": 3,
5
  "requires": true,
6
  "packages": {
7
  "": {
8
- "name": "stremio-catalogs-providers",
9
  "version": "1.0.0",
10
  "license": "ISC",
11
  "dependencies": {
12
- "async": "^3.2.6",
13
- "axios": "^1.7.5",
14
- "bottleneck": "^2.19.5",
15
  "cors": "^2.8.5",
16
  "dotenv": "^16.4.5",
17
- "express": "^4.19.2",
18
  "sqlite3": "^5.1.7",
19
  "winston": "^3.14.2",
20
  "winston-daily-rotate-file": "^5.0.0"
@@ -123,13 +121,13 @@
123
  }
124
  },
125
  "node_modules/agent-base/node_modules/debug": {
126
- "version": "4.3.6",
127
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz",
128
- "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==",
129
  "license": "MIT",
130
  "optional": true,
131
  "dependencies": {
132
- "ms": "2.1.2"
133
  },
134
  "engines": {
135
  "node": ">=6.0"
@@ -141,9 +139,9 @@
141
  }
142
  },
143
  "node_modules/agent-base/node_modules/ms": {
144
- "version": "2.1.2",
145
- "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
146
- "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
147
  "license": "MIT",
148
  "optional": true
149
  },
@@ -225,9 +223,9 @@
225
  "license": "MIT"
226
  },
227
  "node_modules/axios": {
228
- "version": "1.7.5",
229
- "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.5.tgz",
230
- "integrity": "sha512-fZu86yCo+svH3uqJ/yTdQ0QHpQu5oL+/QE+QPSv6BZSkDAoky9vytxp7u5qk83OJFS3kEBcesWni9WTZAv3tSw==",
231
  "license": "MIT",
232
  "dependencies": {
233
  "follow-redirects": "^1.15.6",
@@ -283,9 +281,9 @@
283
  }
284
  },
285
  "node_modules/body-parser": {
286
- "version": "1.20.2",
287
- "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
288
- "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==",
289
  "license": "MIT",
290
  "dependencies": {
291
  "bytes": "3.1.2",
@@ -296,7 +294,7 @@
296
  "http-errors": "2.0.0",
297
  "iconv-lite": "0.4.24",
298
  "on-finished": "2.4.1",
299
- "qs": "6.11.0",
300
  "raw-body": "2.5.2",
301
  "type-is": "~1.6.18",
302
  "unpipe": "1.0.0"
@@ -306,11 +304,20 @@
306
  "npm": "1.2.8000 || >= 1.4.16"
307
  }
308
  },
309
- "node_modules/bottleneck": {
310
- "version": "2.19.5",
311
- "resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
312
- "integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==",
313
- "license": "MIT"
 
 
 
 
 
 
 
 
 
314
  },
315
  "node_modules/brace-expansion": {
316
  "version": "1.1.11",
@@ -680,9 +687,9 @@
680
  "license": "MIT"
681
  },
682
  "node_modules/encodeurl": {
683
- "version": "1.0.2",
684
- "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
685
- "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
686
  "license": "MIT",
687
  "engines": {
688
  "node": ">= 0.8"
@@ -783,37 +790,37 @@
783
  }
784
  },
785
  "node_modules/express": {
786
- "version": "4.19.2",
787
- "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz",
788
- "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==",
789
  "license": "MIT",
790
  "dependencies": {
791
  "accepts": "~1.3.8",
792
  "array-flatten": "1.1.1",
793
- "body-parser": "1.20.2",
794
  "content-disposition": "0.5.4",
795
  "content-type": "~1.0.4",
796
  "cookie": "0.6.0",
797
  "cookie-signature": "1.0.6",
798
  "debug": "2.6.9",
799
  "depd": "2.0.0",
800
- "encodeurl": "~1.0.2",
801
  "escape-html": "~1.0.3",
802
  "etag": "~1.8.1",
803
  "finalhandler": "1.2.0",
804
  "fresh": "0.5.2",
805
  "http-errors": "2.0.0",
806
- "merge-descriptors": "1.0.1",
807
  "methods": "~1.1.2",
808
  "on-finished": "2.4.1",
809
  "parseurl": "~1.3.3",
810
- "path-to-regexp": "0.1.7",
811
  "proxy-addr": "~2.0.7",
812
  "qs": "6.11.0",
813
  "range-parser": "~1.2.1",
814
  "safe-buffer": "5.2.1",
815
- "send": "0.18.0",
816
- "serve-static": "1.15.0",
817
  "setprototypeof": "1.2.0",
818
  "statuses": "2.0.1",
819
  "type-is": "~1.6.18",
@@ -863,6 +870,15 @@
863
  "node": ">= 0.8"
864
  }
865
  },
 
 
 
 
 
 
 
 
 
866
  "node_modules/fn.name": {
867
  "version": "1.1.0",
868
  "resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz",
@@ -870,9 +886,9 @@
870
  "license": "MIT"
871
  },
872
  "node_modules/follow-redirects": {
873
- "version": "1.15.6",
874
- "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
875
- "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
876
  "funding": [
877
  {
878
  "type": "individual",
@@ -1136,13 +1152,13 @@
1136
  }
1137
  },
1138
  "node_modules/http-proxy-agent/node_modules/debug": {
1139
- "version": "4.3.6",
1140
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz",
1141
- "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==",
1142
  "license": "MIT",
1143
  "optional": true,
1144
  "dependencies": {
1145
- "ms": "2.1.2"
1146
  },
1147
  "engines": {
1148
  "node": ">=6.0"
@@ -1154,9 +1170,9 @@
1154
  }
1155
  },
1156
  "node_modules/http-proxy-agent/node_modules/ms": {
1157
- "version": "2.1.2",
1158
- "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
1159
- "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
1160
  "license": "MIT",
1161
  "optional": true
1162
  },
@@ -1175,13 +1191,13 @@
1175
  }
1176
  },
1177
  "node_modules/https-proxy-agent/node_modules/debug": {
1178
- "version": "4.3.6",
1179
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz",
1180
- "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==",
1181
  "license": "MIT",
1182
  "optional": true,
1183
  "dependencies": {
1184
- "ms": "2.1.2"
1185
  },
1186
  "engines": {
1187
  "node": ">=6.0"
@@ -1193,9 +1209,9 @@
1193
  }
1194
  },
1195
  "node_modules/https-proxy-agent/node_modules/ms": {
1196
- "version": "2.1.2",
1197
- "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
1198
- "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
1199
  "license": "MIT",
1200
  "optional": true
1201
  },
@@ -1444,10 +1460,13 @@
1444
  }
1445
  },
1446
  "node_modules/merge-descriptors": {
1447
- "version": "1.0.1",
1448
- "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
1449
- "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==",
1450
- "license": "MIT"
 
 
 
1451
  },
1452
  "node_modules/methods": {
1453
  "version": "1.1.2",
@@ -1840,9 +1859,9 @@
1840
  }
1841
  },
1842
  "node_modules/path-to-regexp": {
1843
- "version": "0.1.7",
1844
- "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
1845
- "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==",
1846
  "license": "MIT"
1847
  },
1848
  "node_modules/prebuild-install": {
@@ -1912,9 +1931,9 @@
1912
  "license": "MIT"
1913
  },
1914
  "node_modules/pump": {
1915
- "version": "3.0.0",
1916
- "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
1917
- "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
1918
  "license": "MIT",
1919
  "dependencies": {
1920
  "end-of-stream": "^1.1.0",
@@ -2064,9 +2083,9 @@
2064
  }
2065
  },
2066
  "node_modules/send": {
2067
- "version": "0.18.0",
2068
- "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz",
2069
- "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==",
2070
  "license": "MIT",
2071
  "dependencies": {
2072
  "debug": "2.6.9",
@@ -2087,6 +2106,15 @@
2087
  "node": ">= 0.8.0"
2088
  }
2089
  },
 
 
 
 
 
 
 
 
 
2090
  "node_modules/send/node_modules/ms": {
2091
  "version": "2.1.3",
2092
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
@@ -2094,9 +2122,9 @@
2094
  "license": "MIT"
2095
  },
2096
  "node_modules/serve-static": {
2097
- "version": "1.15.0",
2098
- "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz",
2099
- "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==",
2100
  "license": "MIT",
2101
  "dependencies": {
2102
  "encodeurl": "~1.0.2",
@@ -2108,6 +2136,45 @@
2108
  "node": ">= 0.8.0"
2109
  }
2110
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2111
  "node_modules/set-blocking": {
2112
  "version": "2.0.0",
2113
  "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
@@ -2259,13 +2326,13 @@
2259
  }
2260
  },
2261
  "node_modules/socks-proxy-agent/node_modules/debug": {
2262
- "version": "4.3.6",
2263
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz",
2264
- "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==",
2265
  "license": "MIT",
2266
  "optional": true,
2267
  "dependencies": {
2268
- "ms": "2.1.2"
2269
  },
2270
  "engines": {
2271
  "node": ">=6.0"
@@ -2277,9 +2344,9 @@
2277
  }
2278
  },
2279
  "node_modules/socks-proxy-agent/node_modules/ms": {
2280
- "version": "2.1.2",
2281
- "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
2282
- "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
2283
  "license": "MIT",
2284
  "optional": true
2285
  },
 
1
  {
2
+ "name": "stremio-tmdb-dice",
3
  "version": "1.0.0",
4
  "lockfileVersion": 3,
5
  "requires": true,
6
  "packages": {
7
  "": {
8
+ "name": "stremio-tmdb-dice",
9
  "version": "1.0.0",
10
  "license": "ISC",
11
  "dependencies": {
12
+ "axios": "^1.7.7",
 
 
13
  "cors": "^2.8.5",
14
  "dotenv": "^16.4.5",
15
+ "express": "^4.20.0",
16
  "sqlite3": "^5.1.7",
17
  "winston": "^3.14.2",
18
  "winston-daily-rotate-file": "^5.0.0"
 
121
  }
122
  },
123
  "node_modules/agent-base/node_modules/debug": {
124
+ "version": "4.3.7",
125
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
126
+ "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
127
  "license": "MIT",
128
  "optional": true,
129
  "dependencies": {
130
+ "ms": "^2.1.3"
131
  },
132
  "engines": {
133
  "node": ">=6.0"
 
139
  }
140
  },
141
  "node_modules/agent-base/node_modules/ms": {
142
+ "version": "2.1.3",
143
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
144
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
145
  "license": "MIT",
146
  "optional": true
147
  },
 
223
  "license": "MIT"
224
  },
225
  "node_modules/axios": {
226
+ "version": "1.7.7",
227
+ "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz",
228
+ "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==",
229
  "license": "MIT",
230
  "dependencies": {
231
  "follow-redirects": "^1.15.6",
 
281
  }
282
  },
283
  "node_modules/body-parser": {
284
+ "version": "1.20.3",
285
+ "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz",
286
+ "integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==",
287
  "license": "MIT",
288
  "dependencies": {
289
  "bytes": "3.1.2",
 
294
  "http-errors": "2.0.0",
295
  "iconv-lite": "0.4.24",
296
  "on-finished": "2.4.1",
297
+ "qs": "6.13.0",
298
  "raw-body": "2.5.2",
299
  "type-is": "~1.6.18",
300
  "unpipe": "1.0.0"
 
304
  "npm": "1.2.8000 || >= 1.4.16"
305
  }
306
  },
307
+ "node_modules/body-parser/node_modules/qs": {
308
+ "version": "6.13.0",
309
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz",
310
+ "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
311
+ "license": "BSD-3-Clause",
312
+ "dependencies": {
313
+ "side-channel": "^1.0.6"
314
+ },
315
+ "engines": {
316
+ "node": ">=0.6"
317
+ },
318
+ "funding": {
319
+ "url": "https://github.com/sponsors/ljharb"
320
+ }
321
  },
322
  "node_modules/brace-expansion": {
323
  "version": "1.1.11",
 
687
  "license": "MIT"
688
  },
689
  "node_modules/encodeurl": {
690
+ "version": "2.0.0",
691
+ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
692
+ "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
693
  "license": "MIT",
694
  "engines": {
695
  "node": ">= 0.8"
 
790
  }
791
  },
792
  "node_modules/express": {
793
+ "version": "4.20.0",
794
+ "resolved": "https://registry.npmjs.org/express/-/express-4.20.0.tgz",
795
+ "integrity": "sha512-pLdae7I6QqShF5PnNTCVn4hI91Dx0Grkn2+IAsMTgMIKuQVte2dN9PeGSSAME2FR8anOhVA62QDIUaWVfEXVLw==",
796
  "license": "MIT",
797
  "dependencies": {
798
  "accepts": "~1.3.8",
799
  "array-flatten": "1.1.1",
800
+ "body-parser": "1.20.3",
801
  "content-disposition": "0.5.4",
802
  "content-type": "~1.0.4",
803
  "cookie": "0.6.0",
804
  "cookie-signature": "1.0.6",
805
  "debug": "2.6.9",
806
  "depd": "2.0.0",
807
+ "encodeurl": "~2.0.0",
808
  "escape-html": "~1.0.3",
809
  "etag": "~1.8.1",
810
  "finalhandler": "1.2.0",
811
  "fresh": "0.5.2",
812
  "http-errors": "2.0.0",
813
+ "merge-descriptors": "1.0.3",
814
  "methods": "~1.1.2",
815
  "on-finished": "2.4.1",
816
  "parseurl": "~1.3.3",
817
+ "path-to-regexp": "0.1.10",
818
  "proxy-addr": "~2.0.7",
819
  "qs": "6.11.0",
820
  "range-parser": "~1.2.1",
821
  "safe-buffer": "5.2.1",
822
+ "send": "0.19.0",
823
+ "serve-static": "1.16.0",
824
  "setprototypeof": "1.2.0",
825
  "statuses": "2.0.1",
826
  "type-is": "~1.6.18",
 
870
  "node": ">= 0.8"
871
  }
872
  },
873
+ "node_modules/finalhandler/node_modules/encodeurl": {
874
+ "version": "1.0.2",
875
+ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
876
+ "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
877
+ "license": "MIT",
878
+ "engines": {
879
+ "node": ">= 0.8"
880
+ }
881
+ },
882
  "node_modules/fn.name": {
883
  "version": "1.1.0",
884
  "resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz",
 
886
  "license": "MIT"
887
  },
888
  "node_modules/follow-redirects": {
889
+ "version": "1.15.9",
890
+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
891
+ "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
892
  "funding": [
893
  {
894
  "type": "individual",
 
1152
  }
1153
  },
1154
  "node_modules/http-proxy-agent/node_modules/debug": {
1155
+ "version": "4.3.7",
1156
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
1157
+ "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
1158
  "license": "MIT",
1159
  "optional": true,
1160
  "dependencies": {
1161
+ "ms": "^2.1.3"
1162
  },
1163
  "engines": {
1164
  "node": ">=6.0"
 
1170
  }
1171
  },
1172
  "node_modules/http-proxy-agent/node_modules/ms": {
1173
+ "version": "2.1.3",
1174
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
1175
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
1176
  "license": "MIT",
1177
  "optional": true
1178
  },
 
1191
  }
1192
  },
1193
  "node_modules/https-proxy-agent/node_modules/debug": {
1194
+ "version": "4.3.7",
1195
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
1196
+ "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
1197
  "license": "MIT",
1198
  "optional": true,
1199
  "dependencies": {
1200
+ "ms": "^2.1.3"
1201
  },
1202
  "engines": {
1203
  "node": ">=6.0"
 
1209
  }
1210
  },
1211
  "node_modules/https-proxy-agent/node_modules/ms": {
1212
+ "version": "2.1.3",
1213
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
1214
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
1215
  "license": "MIT",
1216
  "optional": true
1217
  },
 
1460
  }
1461
  },
1462
  "node_modules/merge-descriptors": {
1463
+ "version": "1.0.3",
1464
+ "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
1465
+ "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
1466
+ "license": "MIT",
1467
+ "funding": {
1468
+ "url": "https://github.com/sponsors/sindresorhus"
1469
+ }
1470
  },
1471
  "node_modules/methods": {
1472
  "version": "1.1.2",
 
1859
  }
1860
  },
1861
  "node_modules/path-to-regexp": {
1862
+ "version": "0.1.10",
1863
+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.10.tgz",
1864
+ "integrity": "sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==",
1865
  "license": "MIT"
1866
  },
1867
  "node_modules/prebuild-install": {
 
1931
  "license": "MIT"
1932
  },
1933
  "node_modules/pump": {
1934
+ "version": "3.0.1",
1935
+ "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.1.tgz",
1936
+ "integrity": "sha512-2ynnAmUu45oUSq51AQbeugLkMSKaz8FqVpZ6ykTqzOVkzXe8u/ezkGsYrFJqKZx+D9cVxoDrSbR7CeAwxFa5cQ==",
1937
  "license": "MIT",
1938
  "dependencies": {
1939
  "end-of-stream": "^1.1.0",
 
2083
  }
2084
  },
2085
  "node_modules/send": {
2086
+ "version": "0.19.0",
2087
+ "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz",
2088
+ "integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==",
2089
  "license": "MIT",
2090
  "dependencies": {
2091
  "debug": "2.6.9",
 
2106
  "node": ">= 0.8.0"
2107
  }
2108
  },
2109
+ "node_modules/send/node_modules/encodeurl": {
2110
+ "version": "1.0.2",
2111
+ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
2112
+ "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
2113
+ "license": "MIT",
2114
+ "engines": {
2115
+ "node": ">= 0.8"
2116
+ }
2117
+ },
2118
  "node_modules/send/node_modules/ms": {
2119
  "version": "2.1.3",
2120
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
 
2122
  "license": "MIT"
2123
  },
2124
  "node_modules/serve-static": {
2125
+ "version": "1.16.0",
2126
+ "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.0.tgz",
2127
+ "integrity": "sha512-pDLK8zwl2eKaYrs8mrPZBJua4hMplRWJ1tIFksVC3FtBEBnl8dxgeHtsaMS8DhS9i4fLObaon6ABoc4/hQGdPA==",
2128
  "license": "MIT",
2129
  "dependencies": {
2130
  "encodeurl": "~1.0.2",
 
2136
  "node": ">= 0.8.0"
2137
  }
2138
  },
2139
+ "node_modules/serve-static/node_modules/encodeurl": {
2140
+ "version": "1.0.2",
2141
+ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
2142
+ "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
2143
+ "license": "MIT",
2144
+ "engines": {
2145
+ "node": ">= 0.8"
2146
+ }
2147
+ },
2148
+ "node_modules/serve-static/node_modules/ms": {
2149
+ "version": "2.1.3",
2150
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
2151
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
2152
+ "license": "MIT"
2153
+ },
2154
+ "node_modules/serve-static/node_modules/send": {
2155
+ "version": "0.18.0",
2156
+ "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz",
2157
+ "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==",
2158
+ "license": "MIT",
2159
+ "dependencies": {
2160
+ "debug": "2.6.9",
2161
+ "depd": "2.0.0",
2162
+ "destroy": "1.2.0",
2163
+ "encodeurl": "~1.0.2",
2164
+ "escape-html": "~1.0.3",
2165
+ "etag": "~1.8.1",
2166
+ "fresh": "0.5.2",
2167
+ "http-errors": "2.0.0",
2168
+ "mime": "1.6.0",
2169
+ "ms": "2.1.3",
2170
+ "on-finished": "2.4.1",
2171
+ "range-parser": "~1.2.1",
2172
+ "statuses": "2.0.1"
2173
+ },
2174
+ "engines": {
2175
+ "node": ">= 0.8.0"
2176
+ }
2177
+ },
2178
  "node_modules/set-blocking": {
2179
  "version": "2.0.0",
2180
  "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
 
2326
  }
2327
  },
2328
  "node_modules/socks-proxy-agent/node_modules/debug": {
2329
+ "version": "4.3.7",
2330
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
2331
+ "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
2332
  "license": "MIT",
2333
  "optional": true,
2334
  "dependencies": {
2335
+ "ms": "^2.1.3"
2336
  },
2337
  "engines": {
2338
  "node": ">=6.0"
 
2344
  }
2345
  },
2346
  "node_modules/socks-proxy-agent/node_modules/ms": {
2347
+ "version": "2.1.3",
2348
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
2349
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
2350
  "license": "MIT",
2351
  "optional": true
2352
  },
package.json CHANGED
@@ -1,8 +1,9 @@
1
  {
2
- "name": "stremio-catalogs-providers",
3
  "version": "1.0.0",
4
  "main": "index.js",
5
  "scripts": {
 
6
  "test": "echo \"Error: no test specified\" && exit 1"
7
  },
8
  "keywords": [],
@@ -10,12 +11,10 @@
10
  "license": "ISC",
11
  "description": "",
12
  "dependencies": {
13
- "async": "^3.2.6",
14
- "axios": "^1.7.5",
15
- "bottleneck": "^2.19.5",
16
  "cors": "^2.8.5",
17
  "dotenv": "^16.4.5",
18
- "express": "^4.19.2",
19
  "sqlite3": "^5.1.7",
20
  "winston": "^3.14.2",
21
  "winston-daily-rotate-file": "^5.0.0"
 
1
  {
2
+ "name": "stremio-tmdb-dice",
3
  "version": "1.0.0",
4
  "main": "index.js",
5
  "scripts": {
6
+ "start": "node index.js",
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
  },
9
  "keywords": [],
 
11
  "license": "ISC",
12
  "description": "",
13
  "dependencies": {
14
+ "axios": "^1.7.7",
 
 
15
  "cors": "^2.8.5",
16
  "dotenv": "^16.4.5",
17
+ "express": "^4.20.0",
18
  "sqlite3": "^5.1.7",
19
  "winston": "^3.14.2",
20
  "winston-daily-rotate-file": "^5.0.0"
public/configure.html ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="fr">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Configure - Stremio-TMDB-Dic</title>
7
+ <link rel="stylesheet" href="css/styles.css">
8
+ </head>
9
+ <body class="dark-mode">
10
+ <div class="container">
11
+ <div class="dark-mode-toggle" id="dark-mode-toggle">🌞</div>
12
+
13
+ <h1>Stremio TMDB Dice</h1>
14
+
15
+ <div class="form-group">
16
+ <label for="language">Language</label>
17
+ <select id="language">
18
+ <option value="">Select your language</option>
19
+ </select>
20
+ </div>
21
+
22
+ <div class="form-group">
23
+ <label for="api-key">TMDB API Key (<a href="https://www.themoviedb.org/settings/api" target="_blank" style="color: #007aff;">Get it here</a>)</label>
24
+ <input type="text" id="tmdb-api-key">
25
+ </div>
26
+
27
+ <div class="form-group">
28
+ <label for="rpdb-api-key">RPDB API Key (<a href="https://ratingposterdb.com/api-key" target="_blank" style="color: #007aff;">Get it here</a>)</label>
29
+ <input type="text" id="rpdb-api-key">
30
+ </div>
31
+
32
+ <div class="form-group">
33
+ <label for="fanart-api-key">Fanart API Key (<a href="https://fanart.tv/get-an-api-key" target="_blank" style="color: #007aff;">Get it here</a>)</label>
34
+ <input type="text" id="fanart-api-key">
35
+ </div>
36
+
37
+ <div class="form-group">
38
+ <div class="label-checkbox-group">
39
+ <input type="checkbox" id="hide-no-poster">
40
+ <label for="hide-no-poster">Hide items without poster</label>
41
+ </div>
42
+ <p class="hint">Most of the time it is not quality items that deserve attention that are returned.</p>
43
+ </div>
44
+
45
+ <div class="button-group">
46
+ <button class="btn install">Install</button>
47
+ <button class="btn copy-link">Copy link</button>
48
+ </div>
49
+ </div>
50
+
51
+ <div class="modal-overlay" id="modal-overlay"></div>
52
+ <div class="modal" id="modal">
53
+ <div class="modal-header" id="modal-header">Warning</div>
54
+ <div class="modal-body" id="modal-body">Please fill in all required fields: TMDB API Key and Language.</div>
55
+ <div class="modal-footer">
56
+ <button class="btn btn-error" id="close-modal">OK</button>
57
+ </div>
58
+ </div>
59
+
60
+ <div class="notification-success" id="notification-success">
61
+ <span>&#10004;</span>
62
+ <span id="notification-text">Link copied to clipboard!</span>
63
+ </div>
64
+
65
+ <script src="js/languages.js"></script>
66
+ <script>
67
+ document.addEventListener('DOMContentLoaded', () => {
68
+ const toggle = document.getElementById('dark-mode-toggle');
69
+ toggle.textContent = '🌜';
70
+
71
+ toggle.addEventListener('click', () => {
72
+ document.body.classList.toggle('dark-mode');
73
+ toggle.textContent = document.body.classList.contains('dark-mode') ? '🌜' : '🌞';
74
+ });
75
+
76
+ function populateLanguageDropdown() {
77
+ const dropdown = document.getElementById('language');
78
+ languages.forEach(lang => {
79
+ const option = document.createElement('option');
80
+ option.value = lang.iso_639_1;
81
+ option.textContent = lang.english_name + (lang.name ? ` (${lang.name})` : '');
82
+ dropdown.appendChild(option);
83
+ });
84
+ }
85
+ populateLanguageDropdown();
86
+
87
+ function getConfig() {
88
+ const tmdbApiKey = document.getElementById('tmdb-api-key').value;
89
+ const rpdbApiKey = document.getElementById('rpdb-api-key').value;
90
+ const fanartApiKey = document.getElementById('fanart-api-key').value;
91
+ const language = document.getElementById('language').value;
92
+
93
+ if (!tmdbApiKey || !language) {
94
+ showModal('Warning', 'Please fill in all required fields: TMDB API Key and Language.', 'btn-error');
95
+ return null;
96
+ }
97
+
98
+ const config = {
99
+ tmdbApiKey: tmdbApiKey,
100
+ rpdbApiKey: rpdbApiKey,
101
+ fanartApiKey: fanartApiKey,
102
+ language: language,
103
+ hideNoPoster: document.getElementById('hide-no-poster').checked,
104
+ };
105
+ return config;
106
+ }
107
+
108
+ function showModal(headerText, message, buttonClass) {
109
+ const modal = document.getElementById('modal');
110
+ const overlay = document.getElementById('modal-overlay');
111
+ const modalHeader = document.getElementById('modal-header');
112
+ const modalBody = document.getElementById('modal-body');
113
+ const closeModalButton = document.getElementById('close-modal');
114
+
115
+ modalHeader.textContent = headerText;
116
+ modalBody.textContent = message;
117
+ closeModalButton.className = 'btn ' + buttonClass;
118
+ modal.classList.add('show');
119
+ overlay.classList.add('show');
120
+
121
+ closeModalButton.onclick = () => {
122
+ modal.classList.remove('show');
123
+ overlay.classList.remove('show');
124
+ };
125
+ }
126
+
127
+ function showSuccessNotification(message) {
128
+ const notification = document.getElementById('notification-success');
129
+ const notificationText = document.getElementById('notification-text');
130
+
131
+ notificationText.textContent = message;
132
+ notification.classList.add('show');
133
+
134
+ setTimeout(() => {
135
+ notification.classList.remove('show');
136
+ }, 3000);
137
+ }
138
+
139
+ function getStremioLink() {
140
+ const config = getConfig();
141
+ if (!config) return;
142
+ return "stremio://" + window.location.host + "/" + encodeURIComponent(JSON.stringify(config)) + "/manifest.json";
143
+ }
144
+
145
+ function getHttpsLink() {
146
+ const config = getConfig();
147
+ if (!config) return;
148
+ return "https://" + window.location.host + "/" + encodeURIComponent(JSON.stringify(config)) + "/manifest.json";
149
+ }
150
+
151
+ document.querySelector('.install').addEventListener('click', () => {
152
+ const installURL = getStremioLink();
153
+ if (installURL) {
154
+ window.location.href = installURL;
155
+ }
156
+ });
157
+
158
+ document.querySelector('.copy-link').addEventListener('click', () => {
159
+ const copyURL = getHttpsLink();
160
+ if (copyURL) {
161
+ navigator.clipboard.writeText(copyURL).then(() => {
162
+ showSuccessNotification('Link copied to clipboard!');
163
+ }).catch(err => {
164
+ console.error('Failed to copy the link: ', err);
165
+ });
166
+ }
167
+ });
168
+ });
169
+ </script>
170
+ </body>
171
+ </html>
public/css/styles.css ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ * {
2
+ margin: 0;
3
+ padding: 0;
4
+ box-sizing: border-box;
5
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
6
+ }
7
+
8
+ body {
9
+ background-color: #f5f5f7;
10
+ color: #333;
11
+ display: flex;
12
+ justify-content: center;
13
+ align-items: center;
14
+ min-height: 100vh;
15
+ padding: 20px;
16
+ transition: background-color 0.3s, color 0.3s;
17
+ }
18
+
19
+ .container {
20
+ background-color: #fff;
21
+ border-radius: 16px;
22
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
23
+ padding: 40px;
24
+ max-width: 400px;
25
+ width: 100%;
26
+ transition: background-color 0.3s;
27
+ position: relative;
28
+ }
29
+
30
+ .dark-mode-toggle {
31
+ position: absolute;
32
+ top: 10px;
33
+ right: 10px;
34
+ cursor: pointer;
35
+ font-size: 24px;
36
+ transition: transform 0.3s;
37
+ }
38
+
39
+ .dark-mode-toggle:hover {
40
+ transform: scale(1.1);
41
+ }
42
+
43
+ h1 {
44
+ font-size: 24px;
45
+ margin-bottom: 20px;
46
+ text-align: center;
47
+ }
48
+
49
+ .toggle-dark-mode {
50
+ display: flex;
51
+ align-items: center;
52
+ margin-bottom: 20px;
53
+ }
54
+
55
+ .toggle-dark-mode label {
56
+ margin-left: 8px;
57
+ }
58
+
59
+ .form-group {
60
+ margin-bottom: 20px;
61
+ }
62
+
63
+ .label-checkbox-group {
64
+ display: flex;
65
+ align-items: center;
66
+ margin-bottom: 5px;
67
+ }
68
+
69
+ label {
70
+ font-weight: 600;
71
+ color: inherit;
72
+ }
73
+
74
+ input[type="text"],
75
+ select {
76
+ width: 100%;
77
+ padding: 12px;
78
+ border-radius: 8px;
79
+ border: 1px solid #ddd;
80
+ font-size: 14px;
81
+ background-color: #f5f5f7;
82
+ transition: border-color 0.3s, background-color 0.3s;
83
+ margin-top: 8px;
84
+ }
85
+
86
+ input[type="text"]:focus,
87
+ select:focus {
88
+ border-color: #007aff;
89
+ outline: none;
90
+ }
91
+
92
+ input[type="checkbox"] {
93
+ appearance: none;
94
+ width: 20px;
95
+ height: 20px;
96
+ background-color: #f5f5f7;
97
+ border: 2px solid #ddd;
98
+ border-radius: 5px;
99
+ display: inline-block;
100
+ position: relative;
101
+ cursor: pointer;
102
+ transition: background-color 0.3s, border-color 0.3s;
103
+ margin-right: 10px;
104
+ }
105
+
106
+ input[type="checkbox"]:checked {
107
+ background-color: #007aff;
108
+ border-color: #007aff;
109
+ }
110
+
111
+ input[type="checkbox"]:checked::after {
112
+ content: '';
113
+ position: absolute;
114
+ left: 50%;
115
+ top: 50%;
116
+ width: 6px;
117
+ height: 12px;
118
+ border: solid white;
119
+ border-width: 0 2px 2px 0;
120
+ transform: translate(-50%, -50%) rotate(45deg);
121
+ }
122
+
123
+ .hint {
124
+ font-size: 12px;
125
+ color: #888;
126
+ margin-top: 4px;
127
+ line-height: 1.4;
128
+ }
129
+
130
+ .button-group {
131
+ display: flex;
132
+ justify-content: space-between;
133
+ }
134
+
135
+ .btn {
136
+ background-color: #007aff;
137
+ color: #fff;
138
+ border: none;
139
+ padding: 12px 24px;
140
+ border-radius: 8px;
141
+ cursor: pointer;
142
+ font-size: 14px;
143
+ transition: background-color 0.3s;
144
+ }
145
+
146
+ .btn:hover {
147
+ background-color: #005bb5;
148
+ }
149
+
150
+ .modal {
151
+ position: fixed;
152
+ top: 50%;
153
+ left: 50%;
154
+ transform: translate(-50%, -50%);
155
+ background-color: #fff;
156
+ border-radius: 16px;
157
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
158
+ width: 300px;
159
+ padding: 20px;
160
+ text-align: center;
161
+ z-index: 1000;
162
+ display: none;
163
+ transition: opacity 0.3s ease, transform 0.3s ease;
164
+ }
165
+
166
+ .modal.show {
167
+ display: block;
168
+ opacity: 1;
169
+ }
170
+
171
+ .modal-header {
172
+ font-size: 18px;
173
+ margin-bottom: 10px;
174
+ font-weight: bold;
175
+ }
176
+
177
+ .modal-body {
178
+ font-size: 14px;
179
+ color: #333;
180
+ margin-bottom: 20px;
181
+ }
182
+
183
+ .modal-footer {
184
+ display: flex;
185
+ justify-content: center;
186
+ }
187
+
188
+ .modal-footer .btn {
189
+ width: 80px;
190
+ }
191
+
192
+ .modal-footer .btn-error {
193
+ background-color: #d9534f;
194
+ }
195
+
196
+ .modal-footer .btn-success {
197
+ background-color: #28a745;
198
+ }
199
+
200
+ .modal-overlay {
201
+ position: fixed;
202
+ top: 0;
203
+ left: 0;
204
+ width: 100%;
205
+ height: 100%;
206
+ background-color: rgba(0, 0, 0, 0.4);
207
+ backdrop-filter: blur(5px);
208
+ z-index: 999;
209
+ display: none;
210
+ }
211
+
212
+ .modal-overlay.show {
213
+ display: block;
214
+ }
215
+
216
+ body.dark-mode .modal {
217
+ background-color: #2c2c2e;
218
+ color: #f5f5f7;
219
+ }
220
+
221
+ body.dark-mode .modal-body {
222
+ color: #ddd;
223
+ }
224
+
225
+ .notification-success {
226
+ position: fixed;
227
+ top: 20px;
228
+ right: 20px;
229
+ background-color: #28a745;
230
+ color: white;
231
+ padding: 10px 20px;
232
+ border-radius: 8px;
233
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
234
+ display: flex;
235
+ align-items: center;
236
+ gap: 8px;
237
+ opacity: 0;
238
+ transition: opacity 0.3s ease, transform 0.3s ease;
239
+ z-index: 1000;
240
+ }
241
+
242
+ .notification-success.show {
243
+ opacity: 1;
244
+ }
245
+
246
+ body.dark-mode {
247
+ background-color: #1c1c1e;
248
+ color: #f5f5f7;
249
+ }
250
+
251
+ body.dark-mode .container {
252
+ background-color: #2c2c2e;
253
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
254
+ }
255
+
256
+ body.dark-mode input[type="text"],
257
+ body.dark-mode select {
258
+ background-color: #3a3a3c;
259
+ border: 1px solid #505052;
260
+ color: #f5f5f7;
261
+ }
262
+
263
+ body.dark-mode input[type="checkbox"] {
264
+ background-color: #3a3a3c;
265
+ border-color: #505052;
266
+ }
267
+
268
+ body.dark-mode .hint {
269
+ color: #aaa;
270
+ }
271
+
272
+ body.dark-mode .btn {
273
+ background-color: #007aff;
274
+ }
275
+
276
+ body.dark-mode .btn:hover {
277
+ background-color: #005bb5;
278
+ }
279
+
public/js/languages.js ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const languages = [
2
+ {iso_639_1: "bi", english_name: "Bislama", name: "" },
3
+ {iso_639_1: "cs", english_name: "Czech", name: "Český" },
4
+ {iso_639_1: "ba", english_name: "Bashkir", name: "" },
5
+ {iso_639_1: "ae", english_name: "Avestan", name: "" },
6
+ {iso_639_1: "av", english_name: "Avaric", name: "" },
7
+ {iso_639_1: "de", english_name: "German", name: "Deutsch" },
8
+ {iso_639_1: "mt", english_name: "Maltese", name: "Malti" },
9
+ {iso_639_1: "om", english_name: "Oromo", name: "" },
10
+ {iso_639_1: "rm", english_name: "Raeto-Romance", name: "" },
11
+ {iso_639_1: "so", english_name: "Somali", name: "Somali" },
12
+ {iso_639_1: "ts", english_name: "Tsonga", name: "" },
13
+ {iso_639_1: "vi", english_name: "Vietnamese", name: "Tiếng Việt" },
14
+ {iso_639_1: "gn", english_name: "Guarani", name: "" },
15
+ {iso_639_1: "ig", english_name: "Igbo", name: "" },
16
+ {iso_639_1: "it", english_name: "Italian", name: "Italiano" },
17
+ {iso_639_1: "ki", english_name: "Kikuyu", name: "" },
18
+ {iso_639_1: "ku", english_name: "Kurdish", name: "" },
19
+ {iso_639_1: "la", english_name: "Latin", name: "Latin" },
20
+ {iso_639_1: "ln", english_name: "Lingala", name: "" },
21
+ {iso_639_1: "lb", english_name: "Letzeburgesch", name: "" },
22
+ {iso_639_1: "ny", english_name: "Chichewa; Nyanja", name: "" },
23
+ {iso_639_1: "pl", english_name: "Polish", name: "Polski" },
24
+ {iso_639_1: "si", english_name: "Sinhalese", name: "සිංහල" },
25
+ {iso_639_1: "to", english_name: "Tonga", name: "" },
26
+ {iso_639_1: "az", english_name: "Azerbaijani", name: "Azərbaycan" },
27
+ {iso_639_1: "ce", english_name: "Chechen", name: "" },
28
+ {iso_639_1: "cu", english_name: "Slavic", name: "" },
29
+ {iso_639_1: "da", english_name: "Danish", name: "Dansk" },
30
+ {iso_639_1: "hz", english_name: "Herero", name: "" },
31
+ {iso_639_1: "ie", english_name: "Interlingue", name: "" },
32
+ {iso_639_1: "rw", english_name: "Kinyarwanda", name: "Kinyarwanda" },
33
+ {iso_639_1: "mi", english_name: "Maori", name: "" },
34
+ {iso_639_1: "no", english_name: "Norwegian", name: "Norsk" },
35
+ {iso_639_1: "pi", english_name: "Pali", name: "" },
36
+ {iso_639_1: "sk", english_name: "Slovak", name: "Slovenčina" },
37
+ {iso_639_1: "se", english_name: "Northern Sami", name: "" },
38
+ {iso_639_1: "sm", english_name: "Samoan", name: "" },
39
+ {iso_639_1: "uk", english_name: "Ukrainian", name: "Український" },
40
+ {iso_639_1: "en", english_name: "English", name: "English" },
41
+ {iso_639_1: "ay", english_name: "Aymara", name: "" },
42
+ {iso_639_1: "ca", english_name: "Catalan", name: "Català" },
43
+ {iso_639_1: "eo", english_name: "Esperanto", name: "Esperanto" },
44
+ {iso_639_1: "ha", english_name: "Hausa", name: "Hausa" },
45
+ {iso_639_1: "ho", english_name: "Hiri Motu", name: "" },
46
+ {iso_639_1: "hu", english_name: "Hungarian", name: "Magyar" },
47
+ {iso_639_1: "io", english_name: "Ido", name: "" },
48
+ {iso_639_1: "ii", english_name: "Yi", name: "" },
49
+ {iso_639_1: "kn", english_name: "Kannada", name: "?????" },
50
+ {iso_639_1: "kv", english_name: "Komi", name: "" },
51
+ {iso_639_1: "li", english_name: "Limburgish", name: "" },
52
+ {iso_639_1: "oj", english_name: "Ojibwa", name: "" },
53
+ {iso_639_1: "ru", english_name: "Russian", name: "Pусский" },
54
+ {iso_639_1: "sr", english_name: "Serbian", name: "Srpski" },
55
+ {iso_639_1: "sv", english_name: "Swedish", name: "svenska" },
56
+ {iso_639_1: "ty", english_name: "Tahitian", name: "" },
57
+ {iso_639_1: "zu", english_name: "Zulu", name: "isiZulu" },
58
+ {iso_639_1: "ka", english_name: "Georgian", name: "ქართული" },
59
+ {iso_639_1: "ch", english_name: "Chamorro", name: "Finu' Chamorro" },
60
+ {iso_639_1: "be", english_name: "Belarusian", name: "беларуская мова" },
61
+ {iso_639_1: "br", english_name: "Breton", name: "" },
62
+ {iso_639_1: "kw", english_name: "Cornish", name: "" },
63
+ {iso_639_1: "fi", english_name: "Finnish", name: "suomi" },
64
+ {iso_639_1: "sh", english_name: "Serbo-Croatian", name: "" },
65
+ {iso_639_1: "nn", english_name: "Norwegian Nynorsk", name: "" },
66
+ {iso_639_1: "tt", english_name: "Tatar", name: "" },
67
+ {iso_639_1: "tg", english_name: "Tajik", name: "" },
68
+ {iso_639_1: "vo", english_name: "Volapük", name: "" },
69
+ {iso_639_1: "ps", english_name: "Pushto", name: "پښتو" },
70
+ {iso_639_1: "mk", english_name: "Macedonian", name: "" },
71
+ {iso_639_1: "fr", english_name: "French", name: "Français" },
72
+ {iso_639_1: "bm", english_name: "Bambara", name: "Bamanankan" },
73
+ {iso_639_1: "eu", english_name: "Basque", name: "euskera" },
74
+ {iso_639_1: "fj", english_name: "Fijian", name: "" },
75
+ {iso_639_1: "id", english_name: "Indonesian", name: "Bahasa indonesia" },
76
+ {iso_639_1: "mg", english_name: "Malagasy", name: "" },
77
+ {iso_639_1: "na", english_name: "Nauru", name: "" },
78
+ {iso_639_1: "xx", english_name: "No Language", name: "No Language" },
79
+ {iso_639_1: "qu", english_name: "Quechua", name: "" },
80
+ {iso_639_1: "sq", english_name: "Albanian", name: "shqip" },
81
+ {iso_639_1: "ti", english_name: "Tigrinya", name: "" },
82
+ {iso_639_1: "tw", english_name: "Twi", name: "" },
83
+ {iso_639_1: "wa", english_name: "Walloon", name: "" },
84
+ {iso_639_1: "ab", english_name: "Abkhazian", name: "" },
85
+ {iso_639_1: "bs", english_name: "Bosnian", name: "Bosanski" },
86
+ {iso_639_1: "af", english_name: "Afrikaans", name: "Afrikaans" },
87
+ {iso_639_1: "an", english_name: "Aragonese", name: "" },
88
+ {iso_639_1: "fy", english_name: "Frisian", name: "" },
89
+ {iso_639_1: "gu", english_name: "Gujarati", name: "" },
90
+ {iso_639_1: "ik", english_name: "Inupiaq", name: "" },
91
+ {iso_639_1: "ja", english_name: "Japanese", name: "日本語" },
92
+ {iso_639_1: "ko", english_name: "Korean", name: "한국어/조선말" },
93
+ {iso_639_1: "lg", english_name: "Ganda", name: "" },
94
+ {iso_639_1: "nl", english_name: "Dutch", name: "Nederlands" },
95
+ {iso_639_1: "os", english_name: "Ossetian; Ossetic", name: "" },
96
+ {iso_639_1: "el", english_name: "Greek", name: "ελληνικά" },
97
+ {iso_639_1: "bn", english_name: "Bengali", name: "বাংলা" },
98
+ {iso_639_1: "cr", english_name: "Cree", name: "" },
99
+ {iso_639_1: "km", english_name: "Khmer", name: "" },
100
+ {iso_639_1: "lo", english_name: "Lao", name: "" },
101
+ {iso_639_1: "nd", english_name: "Ndebele", name: "" },
102
+ {iso_639_1: "ne", english_name: "Nepali", name: "" },
103
+ {iso_639_1: "sc", english_name: "Sardinian", name: "" },
104
+ {iso_639_1: "sw", english_name: "Swahili", name: "Kiswahili" },
105
+ {iso_639_1: "tl", english_name: "Tagalog", name: "" },
106
+ {iso_639_1: "ur", english_name: "Urdu", name: "اردو" },
107
+ {iso_639_1: "ee", english_name: "Ewe", name: "Èʋegbe" },
108
+ {iso_639_1: "aa", english_name: "Afar", name: "" },
109
+ {iso_639_1: "co", english_name: "Corsican", name: "" },
110
+ {iso_639_1: "et", english_name: "Estonian", name: "Eesti" },
111
+ {iso_639_1: "is", english_name: "Icelandic", name: "Íslenska" },
112
+ {iso_639_1: "ks", english_name: "Kashmiri", name: "" },
113
+ {iso_639_1: "kr", english_name: "Kanuri", name: "" },
114
+ {iso_639_1: "ky", english_name: "Kirghiz", name: "??????" },
115
+ {iso_639_1: "kj", english_name: "Kuanyama", name: "" },
116
+ {iso_639_1: "nr", english_name: "Ndebele", name: "" },
117
+ {iso_639_1: "or", english_name: "Oriya", name: "" },
118
+ {iso_639_1: "wo", english_name: "Wolof", name: "Wolof" },
119
+ {iso_639_1: "za", english_name: "Zhuang", name: "" },
120
+ {iso_639_1: "ar", english_name: "Arabic", name: "العربية" },
121
+ {iso_639_1: "cv", english_name: "Chuvash", name: "" },
122
+ {iso_639_1: "fo", english_name: "Faroese", name: "" },
123
+ {iso_639_1: "hr", english_name: "Croatian", name: "Hrvatski" },
124
+ {iso_639_1: "ms", english_name: "Malay", name: "Bahasa melayu" },
125
+ {iso_639_1: "nb", english_name: "Norwegian Bokmål", name: "Bokmål" },
126
+ {iso_639_1: "rn", english_name: "Rundi", name: "Kirundi" },
127
+ {iso_639_1: "sn", english_name: "Shona", name: "" },
128
+ {iso_639_1: "st", english_name: "Sotho", name: "" },
129
+ {iso_639_1: "tr", english_name: "Turkish", name: "Türkçe" },
130
+ {iso_639_1: "am", english_name: "Amharic", name: "" },
131
+ {iso_639_1: "fa", english_name: "Persian", name: "فارسی" },
132
+ {iso_639_1: "hy", english_name: "Armenian", name: "" },
133
+ {iso_639_1: "pa", english_name: "Punjabi", name: "ਪੰਜਾਬੀ" },
134
+ {iso_639_1: "as", english_name: "Assamese", name: "" },
135
+ {iso_639_1: "ia", english_name: "Interlingua", name: "" },
136
+ {iso_639_1: "lv", english_name: "Latvian", name: "Latviešu" },
137
+ {iso_639_1: "lu", english_name: "Luba-Katanga", name: "" },
138
+ {iso_639_1: "mr", english_name: "Marathi", name: "" },
139
+ {iso_639_1: "mn", english_name: "Mongolian", name: "" },
140
+ {iso_639_1: "pt", english_name: "Portuguese", name: "Português" },
141
+ {iso_639_1: "th", english_name: "Thai", name: "ภาษาไทย" },
142
+ {iso_639_1: "tk", english_name: "Turkmen", name: "" },
143
+ {iso_639_1: "ve", english_name: "Venda", name: "" },
144
+ {iso_639_1: "dv", english_name: "Divehi", name: "" },
145
+ {iso_639_1: "gv", english_name: "Manx", name: "" },
146
+ {iso_639_1: "kl", english_name: "Kalaallisut", name: "" },
147
+ {iso_639_1: "kk", english_name: "Kazakh", name: "қазақ" },
148
+ {iso_639_1: "lt", english_name: "Lithuanian", name: "Lietuvių" },
149
+ {iso_639_1: "my", english_name: "Burmese", name: "" },
150
+ {iso_639_1: "sl", english_name: "Slovenian", name: "Slovenščina" },
151
+ {iso_639_1: "sd", english_name: "Sindhi", name: "" },
152
+ {iso_639_1: "cn", english_name: "Cantonese", name: "广州话 / 廣州話" },
153
+ {iso_639_1: "hi", english_name: "Hindi", name: "हिन्दी" },
154
+ {iso_639_1: "cy", english_name: "Welsh", name: "Cymraeg" },
155
+ {iso_639_1: "ht", english_name: "Haitian; Haitian Creole", name: "" },
156
+ {iso_639_1: "iu", english_name: "Inuktitut", name: "" },
157
+ {iso_639_1: "jv", english_name: "Javanese", name: "" },
158
+ {iso_639_1: "mh", english_name: "Marshall", name: "" },
159
+ {iso_639_1: "sa", english_name: "Sanskrit", name: "" },
160
+ {iso_639_1: "ss", english_name: "Swati", name: "" },
161
+ {iso_639_1: "te", english_name: "Telugu", name: "తెలుగు" },
162
+ {iso_639_1: "kg", english_name: "Kongo", name: "" },
163
+ {iso_639_1: "ml", english_name: "Malayalam", name: "" },
164
+ {iso_639_1: "uz", english_name: "Uzbek", name: "ozbek" },
165
+ {iso_639_1: "sg", english_name: "Sango", name: "" },
166
+ {iso_639_1: "xh", english_name: "Xhosa", name: "" },
167
+ {iso_639_1: "es", english_name: "Spanish", name: "Español" },
168
+ {iso_639_1: "su", english_name: "Sundanese", name: "" },
169
+ {iso_639_1: "ug", english_name: "Uighur", name: "" },
170
+ {iso_639_1: "yi", english_name: "Yiddish", name: "" },
171
+ {iso_639_1: "yo", english_name: "Yoruba", name: "Èdè Yorùbá" },
172
+ {iso_639_1: "zh", english_name: "Mandarin", name: "普通话" },
173
+ {iso_639_1: "he", english_name: "Hebrew", name: "עִבְרִית" },
174
+ {iso_639_1: "bo", english_name: "Tibetan", name: "" },
175
+ {iso_639_1: "ak", english_name: "Akan", name: "" },
176
+ {iso_639_1: "mo", english_name: "Moldavian", name: "" },
177
+ {iso_639_1: "ng", english_name: "Ndonga", name: "" },
178
+ {iso_639_1: "dz", english_name: "Dzongkha", name: "" },
179
+ {iso_639_1: "ff", english_name: "Fulah", name: "Fulfulde" },
180
+ {iso_639_1: "gd", english_name: "Gaelic", name: "" },
181
+ {iso_639_1: "ga", english_name: "Irish", name: "Gaeilge" },
182
+ {iso_639_1: "gl", english_name: "Galician", name: "Galego" },
183
+ {iso_639_1: "nv", english_name: "Navajo", name: "" },
184
+ {iso_639_1: "oc", english_name: "Occitan", name: "" },
185
+ {iso_639_1: "ro", english_name: "Romanian", name: "Română" },
186
+ {iso_639_1: "ta", english_name: "Tamil", name: "தமிழ்" },
187
+ {iso_639_1: "tn", english_name: "Tswana", name: "" },
188
+ {iso_639_1: "bg", english_name: "Bulgarian", name: "български език"
189
+ }
190
+ ];
191
+
192
+ languages.sort((a, b) => {
193
+ const nameA = a.english_name.toUpperCase();
194
+ const nameB = b.english_name.toUpperCase();
195
+ if (nameA < nameB) {
196
+ return -1;
197
+ }
198
+ if (nameA > nameB) {
199
+ return 1;
200
+ }
201
+ return 0;
202
+ });
src/api/fanart.js ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const axios = require('axios');
2
+ const log = require('../helpers/logger');
3
+
4
+ const getFanartPoster = async (tmdbId, preferredLang, fanartApiKey) => {
5
+ try {
6
+ const url = `https://webservice.fanart.tv/v3/movies/${tmdbId}/?api_key=${fanartApiKey}`;
7
+
8
+ log.debug(`Fetching Fanart logos from: ${url}`);
9
+
10
+ const response = await axios.get(url);
11
+ const logos = response.data.hdmovielogo || [];
12
+
13
+ log.debug(`Logos fetched: ${JSON.stringify(logos)}`);
14
+
15
+ const preferredLangLogos = logos.filter(logo => logo.lang === preferredLang);
16
+ log.debug(`Logos in preferred language (${preferredLang}): ${JSON.stringify(preferredLangLogos)}`);
17
+
18
+ const bestLogoInPreferredLang = preferredLangLogos.sort((a, b) => b.likes - a.likes)[0];
19
+ log.debug(`Best logo in preferred language: ${JSON.stringify(bestLogoInPreferredLang)}`);
20
+
21
+ if (!bestLogoInPreferredLang) {
22
+ const englishLogos = logos.filter(logo => logo.lang === 'en');
23
+ log.debug(`Logos in English: ${JSON.stringify(englishLogos)}`);
24
+
25
+ const bestLogoInEnglish = englishLogos.sort((a, b) => b.likes - a.likes)[0];
26
+ log.debug(`Best logo in English: ${JSON.stringify(bestLogoInEnglish)}`);
27
+
28
+ return bestLogoInEnglish ? bestLogoInEnglish.url.replace('http://', 'https://') : '';
29
+ }
30
+
31
+ const bestLogoUrl = bestLogoInPreferredLang.url.replace('http://', 'https://');
32
+ log.debug(`Best logo URL: ${bestLogoUrl}`);
33
+ return bestLogoUrl;
34
+ } catch (error) {
35
+ log.error(`Error fetching logos from Fanart.tv for TMDB ID ${tmdbId}:`, error.message);
36
+ return '';
37
+ }
38
+ };
39
+
40
+ module.exports = { getFanartPoster };
src/api/rpdb.js ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const axios = require('axios');
2
+ const log = require('../helpers/logger');
3
+ const { setCachedPoster, getCachedPoster } = require('../helpers/cache');
4
+
5
+ const getRpdbPoster = (type, id, language, rpdbkey) => {
6
+ const tier = rpdbkey.split("-")[0];
7
+ const lang = language.split("-")[0];
8
+ const baseUrl = `https://api.ratingposterdb.com/${rpdbkey}/tmdb/poster-default/${type}-${id}.jpg`;
9
+
10
+ return (tier === "t0" || tier === "t1")
11
+ ? baseUrl
12
+ : `${baseUrl}&lang=${lang}`;
13
+ };
14
+
15
+ const posterCacheQueue = new Set();
16
+ const cachedPosters = new Set();
17
+
18
+ const getPosterUrl = async (content, rpdbApiKey) => {
19
+ const posterId = `poster:${content.id}`;
20
+
21
+ if (rpdbApiKey) {
22
+ const cachedPoster = await getCachedPoster(posterId);
23
+ if (cachedPoster) {
24
+ log.debug(`Using cached poster URL for id ${posterId}`);
25
+ return cachedPoster.poster_url;
26
+ }
27
+ }
28
+
29
+ let posterUrl;
30
+
31
+ if (rpdbApiKey) {
32
+ const rpdbImage = getRpdbPoster('movie', content.id, 'fr', rpdbApiKey);
33
+ log.debug(`Fetching RPDB poster from URL: ${rpdbImage}`);
34
+
35
+ try {
36
+ const response = await axios.head(rpdbImage);
37
+ if (response.status === 200) {
38
+ log.debug(`RPDB poster found for id ${posterId}`);
39
+ posterUrl = rpdbImage;
40
+
41
+ if (!cachedPosters.has(posterId)) {
42
+ posterCacheQueue.add({ id: posterId, url: posterUrl });
43
+ cachedPosters.add(posterId);
44
+ }
45
+ } else {
46
+ throw new Error('Not found');
47
+ }
48
+ } catch (error) {
49
+ log.warn(`Error fetching RPDB poster: ${error.message}. Falling back to TMDB poster.`);
50
+ posterUrl = `https://image.tmdb.org/t/p/w500${content.poster_path}`;
51
+ }
52
+ } else {
53
+ posterUrl = `https://image.tmdb.org/t/p/w500${content.poster_path}`;
54
+ }
55
+
56
+ return posterUrl;
57
+ };
58
+
59
+
60
+ const cachePosters = async () => {
61
+ for (const { id, url } of posterCacheQueue) {
62
+ try {
63
+ await setCachedPoster(id, url);
64
+ } catch (error) {
65
+ log.error(`Failed to cache poster id ${id}: ${error.message}`);
66
+ }
67
+ }
68
+ posterCacheQueue.clear();
69
+ cachedPosters.clear();
70
+ };
71
+
72
+ module.exports = {
73
+ getRpdbPoster,
74
+ getPosterUrl,
75
+ cachePosters
76
+ };
src/api/tmdb.js ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const axios = require('axios');
2
+ const log = require('../helpers/logger');
3
+ const { genresDb, cacheDb } = require('../helpers/db');
4
+ const { getCatalogCache, setCatalogCache } = require('../helpers/cache');
5
+ const queue = require('../helpers/ratelimit');
6
+ const { getFanartPoster } = require('./fanart');
7
+ const { getPosterUrl, cachePosters } = require('./rpdb');
8
+
9
+ const TMDB_BASE_URL = 'https://api.themoviedb.org/3';
10
+
11
+ const getGenreId = (mediaType, genreName) =>
12
+ new Promise((resolve, reject) => {
13
+ const query = `SELECT genre_id FROM genres WHERE media_type = ? AND genre_name = ?`;
14
+ genresDb.get(query, [mediaType, genreName], (err, row) => {
15
+ if (err) return reject(err);
16
+ resolve(row ? row.genre_id : null);
17
+ });
18
+ });
19
+
20
+ const buildQueryParams = (params, mediaType) => {
21
+ const queryParams = [];
22
+
23
+ if (params.year) {
24
+ const [startYear, endYear] = params.year.split('-');
25
+ if (startYear && endYear) {
26
+ if (mediaType === 'movie') {
27
+ queryParams.push(`primary_release_date.gte=${startYear}-01-01`);
28
+ queryParams.push(`primary_release_date.lte=${endYear}-12-31`);
29
+ } else if (mediaType === 'tv') {
30
+ queryParams.push(`first_air_date.gte=${startYear}-01-01`);
31
+ queryParams.push(`first_air_date.lte=${endYear}-12-31`);
32
+ }
33
+ }
34
+ }
35
+
36
+ if (params.rating) {
37
+ const [minRating, maxRating] = params.rating.split('-');
38
+ if (minRating && maxRating) {
39
+ queryParams.push(`vote_average.gte=${minRating}`);
40
+ queryParams.push(`vote_average.lte=${maxRating}`);
41
+ }
42
+ }
43
+
44
+ Object.entries(params).forEach(([key, value]) => {
45
+ if (value !== undefined && value !== null && !['year', 'rating', 'hideNoPoster', 'skip', 'genre'].includes(key)) {
46
+ queryParams.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
47
+ }
48
+ });
49
+
50
+ return queryParams.join('&');
51
+ };
52
+
53
+ const fetchData = async (type, id, extra, cacheDuration = '3d', tmdbApiKey, rpdbApiKey, fanartApiKey) => {
54
+ try {
55
+ const mediaType = type === 'series' ? 'tv' : type;
56
+ const language = extra.language || 'default';
57
+ const genre = extra.genre || null;
58
+ const year = extra.year || null;
59
+ const rating = extra.rating || null;
60
+ const skip = extra.skip || 0;
61
+
62
+ const cacheKey = `catalog_${mediaType}_${id}_${JSON.stringify(extra)}_lang_${language}_genre_${genre}_year_${year}_rating_${rating}`;
63
+ log.debug(`Cache key generated: ${cacheKey}`);
64
+
65
+ const cachedData = await getCatalogCache(cacheKey, cacheDuration);
66
+ if (cachedData) {
67
+ log.info(`Using cached data for key: ${cacheKey}`);
68
+ return cachedData.value;
69
+ }
70
+
71
+ log.debug(`Skip value: ${skip}`);
72
+
73
+ const initialQueryParams = buildQueryParams({
74
+ ...extra,
75
+ page: 1
76
+ }, mediaType);
77
+ const initialUrl = `${TMDB_BASE_URL}/discover/${mediaType}?api_key=${tmdbApiKey}&${initialQueryParams}`;
78
+ log.debug(`Fetching initial data from TMDB to get total_pages: ${initialUrl}`);
79
+
80
+ const initialResponse = await axios.get(initialUrl);
81
+ let total_pages = initialResponse.data.total_pages;
82
+ log.info(`Total pages available: ${total_pages}`);
83
+
84
+ if (total_pages > 500) {
85
+ total_pages = 500;
86
+ log.warn(`Capping total pages at 500 (TMDB limitation)`);
87
+ }
88
+
89
+ const fetchedPages = await getFetchedPages(genre, year, rating, mediaType, cacheDb);
90
+ log.debug(`Fetched pages: ${fetchedPages}`);
91
+
92
+ let availablePages = Array.from({ length: total_pages }, (_, i) => i + 1).filter(page => !fetchedPages.includes(page));
93
+
94
+ if (availablePages.length === 0) {
95
+ log.warn(`All pages have been fetched for the current filters.`);
96
+ return [];
97
+ }
98
+
99
+ const randomPage = availablePages[Math.floor(Math.random() * availablePages.length)];
100
+ log.debug(`Random page selected: ${randomPage}`);
101
+
102
+ const queryParams = buildQueryParams({
103
+ ...extra,
104
+ page: randomPage
105
+ }, mediaType);
106
+ const url = `${TMDB_BASE_URL}/discover/${mediaType}?api_key=${tmdbApiKey}&${queryParams}`;
107
+ log.debug(`Fetching from TMDB: ${url}`);
108
+
109
+ return new Promise((resolve, reject) => {
110
+ queue.push({
111
+ fn: async () => {
112
+ try {
113
+ const response = await axios.get(url);
114
+ const results = response.data.results;
115
+ log.info(`Fetched ${results.length} results from TMDB on page ${randomPage}`);
116
+
117
+ const metas = await Promise.all(results.map(async item => {
118
+ const genreNames = item.genre_ids && item.genre_ids.length > 0 ?
119
+ await getGenreNames(item.genre_ids, mediaType, language) :
120
+ [];
121
+
122
+ if (item.genre_ids && item.genre_ids.length === 0) {
123
+ log.warn(`No genre IDs for item ${item.id}`);
124
+ }
125
+
126
+ let logo = null;
127
+
128
+ if (fanartApiKey) {
129
+ logo = await getFanartPoster(item.id, language, fanartApiKey);
130
+ }
131
+
132
+ const posterUrl = await getPosterUrl(item, rpdbApiKey);
133
+ log.debug(`Poster URL for item ${item.id}: ${posterUrl}`);
134
+
135
+ return {
136
+ id: item.id.toString(),
137
+ name: item.title || item.name,
138
+ poster: posterUrl,
139
+ banner: item.backdrop_path ? `https://image.tmdb.org/t/p/original${item.backdrop_path}` : null,
140
+ logo: logo || null,
141
+ type: mediaType,
142
+ description: item.overview,
143
+ releaseInfo: item.release_date || item.first_air_date,
144
+ imdbRating: item.vote_average ? item.vote_average.toFixed(1) : null,
145
+ genres: genreNames
146
+ };
147
+ }));
148
+
149
+ setCatalogCache(cacheKey, metas, cacheDuration, randomPage, skip, genre, year, rating, mediaType);
150
+ await cachePosters();
151
+ resolve(metas);
152
+ } catch (error) {
153
+ log.error(`TMDB fetch error: ${error.message}`);
154
+ reject(new Error('Failed to fetch data from TMDB'));
155
+ }
156
+ }
157
+ });
158
+ });
159
+ } catch (error) {
160
+ log.error(`Error in fetchData: ${error.message}`);
161
+ throw error;
162
+ }
163
+ };
164
+
165
+ const getFetchedPages = (genre, year, rating, mediaType, cacheDb) => {
166
+ return new Promise((resolve, reject) => {
167
+ const decodedGenre = decodeURIComponent(genre || 'undefined');
168
+ const decodedYear = decodeURIComponent(year || 'undefined');
169
+ const decodedRating = decodeURIComponent(rating || 'undefined');
170
+
171
+ cacheDb.all(
172
+ `SELECT page FROM cache WHERE genre = ? AND year = ? AND rating = ? AND mediaType = ?`,
173
+ [decodedGenre, decodedYear, decodedRating, mediaType],
174
+ (err, rows) => {
175
+ if (err) {
176
+ log.error(`Error querying cache for fetched pages: ${err.message}`);
177
+ reject(err);
178
+ } else {
179
+ const fetchedPages = rows.map(row => row.page);
180
+ resolve(fetchedPages);
181
+ }
182
+ }
183
+ );
184
+ });
185
+ };
186
+
187
+ const getGenreNames = (genreIds, mediaType, language) =>
188
+ new Promise((resolve, reject) => {
189
+ if (!genreIds || genreIds.length === 0) {
190
+ log.warn(`No genre IDs provided for ${mediaType}`);
191
+ return resolve([]);
192
+ }
193
+
194
+ const placeholders = genreIds.map(() => '?').join(',');
195
+ const sql = `SELECT genre_name FROM genres WHERE genre_id IN (${placeholders}) AND media_type = ? AND language = ?`;
196
+
197
+ genresDb.all(sql, [...genreIds, mediaType, language], (err, rows) => {
198
+ if (err) {
199
+ log.error(`Error fetching genre names from database: ${err.message}`);
200
+ resolve([]);
201
+ } else {
202
+ resolve(rows.map(row => row.genre_name));
203
+ }
204
+ });
205
+ });
206
+
207
+ const fetchGenres = async (type, language, tmdbApiKey = TMDB_API_KEY) => {
208
+ const mediaType = type === 'series' ? 'tv' : 'movie';
209
+ const endpoint = `/genre/${mediaType}/list`;
210
+
211
+ try {
212
+ const response = await axios.get(`${TMDB_BASE_URL}${endpoint}`, {
213
+ params: { api_key: tmdbApiKey, language }
214
+ });
215
+ log.debug(`Genres retrieved for ${type} (${language})`);
216
+ return response.data.genres;
217
+ } catch (error) {
218
+ log.error(`Error fetching genres from TMDB: ${error.message}`);
219
+ throw error;
220
+ }
221
+ };
222
+
223
+ const storeGenresInDb = (genres, mediaType, language) =>
224
+ new Promise((resolve, reject) => {
225
+ genresDb.serialize(() => {
226
+ genresDb.run('BEGIN TRANSACTION');
227
+ const insertGenre = genresDb.prepare(`
228
+ INSERT INTO genres (genre_id, genre_name, media_type, language)
229
+ VALUES (?, ?, ?, ?)
230
+ ON CONFLICT DO NOTHING;
231
+ `);
232
+
233
+ genres.forEach((genre, index) => {
234
+ insertGenre.run(genre.id, genre.name, mediaType, language, (err) => {
235
+ if (err) {
236
+ log.error(`Error inserting genre: ${err.message}`);
237
+ genresDb.run('ROLLBACK');
238
+ reject(err);
239
+ return;
240
+ }
241
+
242
+ if (index === genres.length - 1) {
243
+ insertGenre.finalize();
244
+ genresDb.run('COMMIT');
245
+ log.info(`Genres stored for ${mediaType} (${language})`);
246
+ resolve();
247
+ }
248
+ });
249
+ });
250
+ });
251
+ });
252
+
253
+ const checkGenresExistForLanguage = async (language) =>
254
+ new Promise((resolve, reject) => {
255
+ log.debug(`Checking genres for ${language}`);
256
+ genresDb.get(
257
+ `SELECT 1 FROM genres WHERE language = ? LIMIT 1`,
258
+ [language],
259
+ (err, row) => err ? reject(err) : resolve(!!row)
260
+ );
261
+ });
262
+
263
+ const fetchAndStoreGenres = async (language, tmdbApiKey = TMDB_API_KEY) => {
264
+ try {
265
+ const movieGenres = await fetchGenres('movie', language, tmdbApiKey);
266
+ const tvGenres = await fetchGenres('series', language, tmdbApiKey);
267
+
268
+ await storeGenresInDb(movieGenres, 'movie', language);
269
+ await storeGenresInDb(tvGenres, 'tv', language);
270
+
271
+ log.info(`Genres fetched and stored for ${language}`);
272
+ } catch (error) {
273
+ log.error(`Error fetching/storing genres: ${error.message}`);
274
+ }
275
+ };
276
+
277
+ module.exports = { fetchData, getGenreId, checkGenresExistForLanguage, fetchAndStoreGenres };
src/helpers/cache.js ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const axios = require('axios');
4
+ const { cacheDb } = require('./db');
5
+ const log = require('./logger');
6
+ const baseUrl = process.env.BASE_URL || 'http://localhost:7000';
7
+
8
+ const DEFAULT_CATALOG_CACHE_DURATION = process.env.CATALOG_CONTENT_CACHE_DURATION || '3d';
9
+ const DEFAULT_RPDB_POSTER_CACHE_DURATION = process.env.RPDB_POSTER_CACHE_DURATION || '3d';
10
+
11
+ const posterDirectory = path.join(__dirname, '../../db/rpdbPosters');
12
+
13
+ if (!fs.existsSync(posterDirectory)) {
14
+ fs.mkdirSync(posterDirectory, { recursive: true });
15
+ }
16
+
17
+ const formatFileName = (posterId) => {
18
+ return posterId.replace(/[^a-zA-Z0-9-_]/g, '_');
19
+ };
20
+
21
+ const cacheDurationToSeconds = (duration) => {
22
+ const match = duration.match(/^(\d+)([dh])$/);
23
+ if (!match) throw new Error('Invalid cache duration format');
24
+
25
+ const [ , value, unit ] = match;
26
+ const number = parseInt(value, 10);
27
+
28
+ switch (unit) {
29
+ case 'd': return number * 86400;
30
+ case 'h': return number * 3600;
31
+ default: throw new Error('Invalid cache duration unit');
32
+ }
33
+ };
34
+
35
+ const setCatalogCache = (key, value, duration = DEFAULT_CATALOG_CACHE_DURATION, page = 1, skip = 0, genre = null, year = null, rating = null, mediaType = null) => {
36
+ try {
37
+ genre = genre === null ? "undefined" : genre;
38
+ year = year === null ? "undefined" : year;
39
+ rating = rating === null ? "undefined" : rating;
40
+
41
+ const durationInSeconds = cacheDurationToSeconds(duration);
42
+ const expireTime = Math.floor(Date.now() / 1000) + durationInSeconds;
43
+
44
+ const query = `INSERT OR REPLACE INTO cache (key, value, timestamp, page, skip, genre, year, rating, mediaType) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`;
45
+ cacheDb.run(query, [key, JSON.stringify(value), expireTime, page, skip, genre, year, rating, mediaType], (err) => {
46
+ if (err) {
47
+ log.error(`Failed to set cache for key ${key}: ${err.message}`);
48
+ } else {
49
+ log.debug(`Cache set for key ${key} with duration ${duration}`);
50
+ }
51
+ });
52
+ } catch (error) {
53
+ log.error(`Error in setting cache: ${error.message}`);
54
+ }
55
+ };
56
+
57
+ const getCatalogCache = (key, cacheDuration = DEFAULT_CATALOG_CACHE_DURATION) => {
58
+ const cacheDurationInSeconds = cacheDurationToSeconds(cacheDuration);
59
+
60
+ return new Promise((resolve, reject) => {
61
+ cacheDb.get(
62
+ `SELECT value, timestamp, page, skip, genre, year, rating, mediaType FROM cache WHERE key = ?`,
63
+ [key],
64
+ (err, row) => {
65
+ if (err) {
66
+ log.error(`Error retrieving cache for key ${key}: ${err.message}`);
67
+ return reject(err);
68
+ }
69
+ if (!row) {
70
+ log.debug(`Cache miss for key ${key}`);
71
+ return resolve(null);
72
+ }
73
+
74
+ const isCacheValid = (Date.now() / 1000 - row.timestamp) < cacheDurationInSeconds;
75
+ if (isCacheValid) {
76
+ log.debug(`Cache hit for key ${key}`);
77
+ resolve({
78
+ value: JSON.parse(row.value),
79
+ page: row.page,
80
+ skip: row.skip,
81
+ genre: row.genre,
82
+ year: row.year,
83
+ rating: row.rating,
84
+ mediaType: row.mediaType
85
+ });
86
+ } else {
87
+ log.debug(`Cache expired for key ${key}`);
88
+ resolve(null);
89
+ }
90
+ }
91
+ );
92
+ });
93
+ };
94
+
95
+ const getCachedPoster = async (posterId) => {
96
+ const formattedPosterId = formatFileName(posterId);
97
+ const filePath = path.join(posterDirectory, `${formattedPosterId}.jpg`);
98
+ const cacheDurationInSeconds = cacheDurationToSeconds(DEFAULT_RPDB_POSTER_CACHE_DURATION);
99
+
100
+ if (fs.existsSync(filePath)) {
101
+ const stats = fs.statSync(filePath);
102
+ const fileAgeInSeconds = (Date.now() - stats.mtimeMs) / 1000;
103
+
104
+ if (fileAgeInSeconds < cacheDurationInSeconds) {
105
+ const posterUrl = `${baseUrl}/poster/${formattedPosterId}.jpg`;
106
+ log.debug(`Cache hit for poster id ${posterId}, serving from ${posterUrl}`);
107
+ return { poster_url: posterUrl };
108
+ } else {
109
+ log.debug(`Cache expired for poster id ${posterId}`);
110
+ fs.unlinkSync(filePath); // Supprimer le fichier expiré
111
+ }
112
+ } else {
113
+ log.debug(`Cache miss for poster id ${posterId}`);
114
+ }
115
+
116
+ return null;
117
+ };
118
+
119
+ const setCachedPoster = async (posterId, posterUrl) => {
120
+ const formattedPosterId = formatFileName(posterId);
121
+ const filePath = path.join(posterDirectory, `${formattedPosterId}.jpg`);
122
+
123
+ try {
124
+ const response = await axios.get(posterUrl, { responseType: 'arraybuffer' });
125
+ fs.writeFileSync(filePath, response.data);
126
+ log.debug(`Poster id ${posterId} cached at ${filePath}`);
127
+ } catch (error) {
128
+ log.error(`Error caching poster id ${posterId} from URL ${posterUrl}: ${error.message}`);
129
+ throw error;
130
+ }
131
+ };
132
+
133
+ module.exports = {
134
+ setCatalogCache,
135
+ getCatalogCache,
136
+ setCachedPoster,
137
+ getCachedPoster
138
+ };
src/helpers/db.js ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const fs = require('fs');
2
+ const sqlite3 = require('sqlite3').verbose();
3
+ const log = require('./logger');
4
+ const path = require('path');
5
+
6
+ const dbDir = path.join(__dirname, '../../db');
7
+
8
+ if (!fs.existsSync(dbDir)) {
9
+ fs.mkdirSync(dbDir, { recursive: true });
10
+ log.debug('Database directory created');
11
+ }
12
+
13
+ const createDatabase = (dbPath, dbName) => {
14
+ return new sqlite3.Database(dbPath, (err) => {
15
+ if (err) {
16
+ log.error(`Failed to connect to ${dbName}: ${err.message}`);
17
+ } else {
18
+ log.debug(`Connected to ${dbName}`);
19
+ }
20
+ });
21
+ };
22
+
23
+ const genresDb = createDatabase(path.join(dbDir, 'genres.db'), 'genres.db');
24
+ const cacheDb = createDatabase(path.join(dbDir, 'cache.db'), 'cache.db');
25
+
26
+ const createTable = (db, query, tableName) => {
27
+ db.run(query, (err) => {
28
+ if (err) {
29
+ log.error(`Error creating ${tableName} table: ${err.message}`);
30
+ } else {
31
+ log.debug(`${tableName} table is ready`);
32
+ }
33
+ });
34
+ };
35
+
36
+ genresDb.serialize(() => {
37
+ createTable(
38
+ genresDb,
39
+ `CREATE TABLE IF NOT EXISTS genres (
40
+ genre_id INTEGER,
41
+ genre_name TEXT,
42
+ media_type TEXT,
43
+ language TEXT,
44
+ PRIMARY KEY (genre_id, media_type, language),
45
+ UNIQUE (genre_id, media_type, language)
46
+ )`,
47
+ 'genres'
48
+ );
49
+ });
50
+
51
+ cacheDb.serialize(() => {
52
+ createTable(
53
+ cacheDb,
54
+ `CREATE TABLE IF NOT EXISTS cache (
55
+ key TEXT PRIMARY KEY,
56
+ value TEXT,
57
+ timestamp INTEGER,
58
+ page INTEGER,
59
+ skip INTEGER,
60
+ genre TEXT,
61
+ year TEXT,
62
+ rating TEXT,
63
+ mediaType TEXT
64
+ )`,
65
+ 'cache'
66
+ );
67
+ });
68
+
69
+ module.exports = {
70
+ genresDb,
71
+ cacheDb
72
+ };
src/helpers/logger.js ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const winston = require('winston');
2
+ const DailyRotateFile = require('winston-daily-rotate-file');
3
+ const path = require('path');
4
+
5
+ winston.addColors({
6
+ error: 'red',
7
+ warn: 'yellow',
8
+ info: 'blue',
9
+ debug: 'green'
10
+ });
11
+
12
+ const uppercaseLevelFormat = winston.format((info) => {
13
+ info.level = info.level.toUpperCase();
14
+ return info;
15
+ })();
16
+
17
+ const LOG_LEVEL = process.env.LOG_LEVEL || 'info';
18
+ const LOG_FILE_PATH = path.join(__dirname, '../../log/application-%DATE%.log');
19
+ const MAX_FILES = process.env.LOG_INTERVAL_DELETION || '3d';
20
+
21
+ const log = winston.createLogger({
22
+ level: LOG_LEVEL,
23
+ format: winston.format.combine(
24
+ uppercaseLevelFormat,
25
+ winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
26
+ winston.format.printf(({ level, message, timestamp }) => {
27
+ return `[${timestamp}] [${level}]: ${message}`;
28
+ })
29
+ ),
30
+ transports: [
31
+ new winston.transports.Console({
32
+ format: winston.format.combine(
33
+ winston.format.colorize(),
34
+ winston.format.printf(({ level, message, timestamp }) => {
35
+ return `[${timestamp}] [${level}]: ${message}`;
36
+ })
37
+ )
38
+ }),
39
+ new DailyRotateFile({
40
+ filename: LOG_FILE_PATH,
41
+ datePattern: 'YYYY-MM-DD',
42
+ maxSize: '20m',
43
+ maxFiles: MAX_FILES
44
+ })
45
+ ]
46
+ });
47
+
48
+ log.exceptions.handle(
49
+ new DailyRotateFile({
50
+ filename: path.join(__dirname, '../../log/exceptions-%DATE%.log'),
51
+ datePattern: 'YYYY-MM-DD',
52
+ maxSize: '20m',
53
+ maxFiles: '30d'
54
+ })
55
+ );
56
+
57
+ process.on('unhandledRejection', (reason, promise) => {
58
+ log.error(`Unhandled Rejection at: ${promise}, reason: ${reason}`);
59
+ });
60
+
61
+ log.on('error', function (err) {
62
+ console.error('Erreur dans le logger:', err);
63
+ });
64
+
65
+ module.exports = log;
src/helpers/manifest.js ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const { genresDb } = require('./db');
2
+
3
+ const getCurrentYear = () => new Date().getFullYear();
4
+
5
+ const generateYearIntervals = (startYear = 1880, endYear = getCurrentYear(), interval = 4) => {
6
+ const intervals = [];
7
+ endYear = Math.max(endYear, startYear);
8
+
9
+ for (let year = endYear; year >= startYear; year -= interval) {
10
+ const nextYear = Math.max(year - interval + 1, startYear);
11
+ intervals.push(`${nextYear}-${year}`);
12
+ }
13
+
14
+ const [firstStart, firstEnd] = intervals.length
15
+ ? intervals[intervals.length - 1].split('-').map(Number)
16
+ : [startYear, endYear];
17
+
18
+ if (firstStart > startYear) {
19
+ intervals[intervals.length - 1] = `${startYear}-${firstEnd}`;
20
+ }
21
+
22
+ return intervals.length ? intervals : [`${startYear}-${endYear}`];
23
+ };
24
+
25
+ const getGenres = (type, language) =>
26
+ new Promise((resolve, reject) => {
27
+ const query = `SELECT genre_name FROM genres WHERE media_type = ? AND language = ?`;
28
+ genresDb.all(query, [type, language], (err, rows) => {
29
+ if (err) return reject(err);
30
+ resolve(rows.map(row => row.genre_name));
31
+ });
32
+ });
33
+
34
+ const generateManifest = async (language) => {
35
+ try {
36
+ const [movieGenres, seriesGenres] = await Promise.all([
37
+ getGenres('movie', language),
38
+ getGenres('tv', language)
39
+ ]);
40
+
41
+ const yearIntervals = generateYearIntervals();
42
+
43
+ return {
44
+ id: 'community.stremiotmdbdice',
45
+ version: '1.0.0',
46
+ logo: "https://www.themoviedb.org/assets/2/v4/logos/v2/blue_square_2-d537fb228cf3ded904ef09b136fe3fec72548ebc1fea3fbbd1ad9e36364db38b.svg",
47
+ name: 'Stremio TMDB Dice',
48
+ description: 'A catalog featuring content from TMDB with filters that allow for generating random content recommendations.',
49
+ types: ['movie', 'series'],
50
+ idPrefixes: ['tt'],
51
+ resources: ['catalog'],
52
+ catalogs: [
53
+ {
54
+ type: "movie",
55
+ id: "random_movies",
56
+ name: "Random Movies",
57
+ extra: [
58
+ { name: "genre", options: movieGenres.length ? movieGenres : ["No genres available"], isRequired: false },
59
+ { name: "rating", options: ["8-10", "6-8", "4-6", "2-4", "0-2"], isRequired: false },
60
+ { name: "year", options: yearIntervals, isRequired: false },
61
+ { name: 'skip', isRequired: false },
62
+ ]
63
+ },
64
+ {
65
+ type: "series",
66
+ id: "random_series",
67
+ name: "Random Series",
68
+ extra: [
69
+ { name: "genre", options: seriesGenres.length ? seriesGenres : ["No genres available"], isRequired: false },
70
+ { name: "rating", options: ["8-10", "6-8", "4-6", "2-4", "0-2"], isRequired: false },
71
+ { name: "year", options: yearIntervals, isRequired: false },
72
+ { name: 'skip', isRequired: false },
73
+ ]
74
+ }
75
+ ],
76
+ behaviorHints: {
77
+ configurable: true,
78
+ configurationRequired: false,
79
+ }
80
+ };
81
+ } catch (error) {
82
+ console.error('Error generating manifest:', error);
83
+ }
84
+ };
85
+
86
+ module.exports = generateManifest;
src/helpers/ratelimit.js ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ const async = require('async');
2
+
3
+ const queue = async.queue((task, callback) => {
4
+ task.fn().then(callback).catch(callback);
5
+ }, 45);
6
+
7
+ module.exports = queue;
src/routes/catalog.js ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const log = require('../helpers/logger');
3
+ const { fetchData, getGenreId } = require('../api/tmdb');
4
+
5
+ const router = express.Router();
6
+
7
+ router.get("/:configParameters?/catalog/:type/:id/:extra?.json", async (req, res) => {
8
+ const { configParameters, type, id, extra } = req.params;
9
+ const { cacheDuration = '3d', ...query } = req.query;
10
+ const config = configParameters ? JSON.parse(decodeURIComponent(configParameters)) : {};
11
+ const { language, hideNoPoster, tmdbApiKey, fanartApiKey, rpdbApiKey } = config;
12
+
13
+ log.info(`Catalog request: type=${type}, id=${id}, language=${language}`);
14
+ log.debug(`Extra parameters: ${JSON.stringify(query)}`);
15
+
16
+ const mediaType = type === 'series' ? 'tv' : type;
17
+ if (!['movie', 'tv'].includes(mediaType)) {
18
+ log.error(`Invalid catalog type: ${mediaType}`);
19
+ return res.status(400).json({ metas: [] });
20
+ }
21
+
22
+ try {
23
+ let extraParams = { ...query };
24
+
25
+ if (extra) {
26
+ const decodedExtra = decodeURIComponent(extra);
27
+ extraParams = {
28
+ ...extraParams,
29
+ ...Object.fromEntries(
30
+ decodedExtra.split(/(?<!\s)&(?!\s)/).map(param => {
31
+ const [key, value] = param.split('=').map(decodeURIComponent);
32
+ return [key.trim(), value.trim()];
33
+ })
34
+ )
35
+ };
36
+ }
37
+
38
+ if (language) extraParams.language = language;
39
+ if (hideNoPoster !== undefined) extraParams.hideNoPoster = String(hideNoPoster);
40
+
41
+ if (extraParams.genre) {
42
+ const genreId = await getGenreId(mediaType, extraParams.genre);
43
+ if (genreId) {
44
+ extraParams.with_genres = genreId;
45
+ } else {
46
+ log.warn(`Genre ${extraParams.genre} not found for ${mediaType}`);
47
+ }
48
+ }
49
+
50
+ log.debug(`Extra parameters after processing: ${JSON.stringify(extraParams)}`);
51
+
52
+ const metas = await fetchData(mediaType, id, extraParams, cacheDuration, tmdbApiKey, rpdbApiKey, fanartApiKey);
53
+
54
+ res.json({
55
+ metas: extraParams.hideNoPoster === 'true' ? metas.filter(meta => meta.poster) : metas
56
+ });
57
+ } catch (error) {
58
+ log.error(`Error fetching catalog data: ${error.message}`);
59
+ res.status(500).json({ metas: [] });
60
+ }
61
+ });
62
+
63
+ module.exports = router;
src/routes/configure.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const path = require('path');
3
+ const log = require('../helpers/logger');
4
+
5
+ const router = express.Router();
6
+
7
+ router.get("/", (req, res) => {
8
+ log.info('Redirecting to /configure');
9
+ res.redirect("/configure");
10
+ });
11
+
12
+ router.get("/:configParameters?/configure", (req, res) => {
13
+ log.info(`Sending public/configure.html`);
14
+ res.sendFile(path.join(__dirname, `../../public/configure.html`));
15
+ });
16
+
17
+ module.exports = router;
src/routes/index.js ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const configureRoutes = require('./configure');
3
+ const manifestRoutes = require('./manifest');
4
+ const catalogRoutes = require('./catalog');
5
+ const log = require('../helpers/logger');
6
+
7
+ const router = express.Router();
8
+
9
+ router.use((req, res, next) => {
10
+ log.info(`--- Request received ---`);
11
+ log.info(`${req.method} ${req.originalUrl}`);
12
+ next();
13
+ });
14
+
15
+ router.use(configureRoutes);
16
+ router.use(manifestRoutes);
17
+ router.use(catalogRoutes);
18
+
19
+ router.use((err, req, res, next) => {
20
+ const errorTime = new Date().toISOString();
21
+ log.error(`${errorTime} - Error: ${err.stack}`);
22
+
23
+ res.status(500).send(`Something broke! If you need help, please provide this timestamp to the developer : ${errorTime}`);
24
+ });
25
+
26
+ module.exports = router;
src/routes/manifest.js ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const log = require('../helpers/logger');
3
+ const { checkGenresExistForLanguage, fetchAndStoreGenres } = require('../api/tmdb');
4
+ const generateManifest = require('../helpers/manifest');
5
+
6
+ const router = express.Router();
7
+
8
+ router.get("/:configParameters?/manifest.json", async (req, res) => {
9
+ const { configParameters } = req.params;
10
+ const config = configParameters ? JSON.parse(decodeURIComponent(configParameters)) : {};
11
+ const { language, tmdbApiKey } = config;
12
+
13
+ log.debug(`Manifest request for language: ${language}`);
14
+
15
+ try {
16
+ if (language && !(await checkGenresExistForLanguage(language))) {
17
+ log.debug(`Fetching genres for language: ${language}`);
18
+ await fetchAndStoreGenres(language, tmdbApiKey);
19
+ }
20
+
21
+ const manifest = await generateManifest(language);
22
+ res.json(manifest);
23
+ } catch (error) {
24
+ log.error(`Error generating manifest: ${error.message}`);
25
+ res.status(500).json({ error: 'Error generating manifest' });
26
+ }
27
+ });
28
+
29
+ module.exports = router;