|
1 | 1 | import { UserAgent } from "./useragents.js"; |
2 | 2 |
|
3 | | -export const config = { |
4 | | - baseUrl: "https://tvlistings.gracenote.com/api/grid", |
5 | | - lineupId: |
| 3 | +function processLineupId(): string { |
| 4 | + const lineupId = |
6 | 5 | process.env["LINEUP_ID"] || |
7 | 6 | process.argv.find((arg) => arg.startsWith("--lineupId="))?.split("=")[1] || |
8 | | - "USA-lineupId-DEFAULT", |
9 | | - timespan: |
10 | | - process.env["TIMESPAN"] || |
11 | | - process.argv.find((arg) => arg.startsWith("--timespan="))?.split("=")[1] || |
12 | | - "6", |
13 | | - country: |
14 | | - process.env["COUNTRY"] || |
15 | | - process.argv.find((arg) => arg.startsWith("--country="))?.split("=")[1] || |
16 | | - "USA", |
17 | | - postalCode: |
18 | | - process.env["POSTAL_CODE"] || |
19 | | - process.argv |
20 | | - .find((arg) => arg.startsWith("--postalCode=")) |
21 | | - ?.split("=")[1] || |
22 | | - "30309", |
23 | | - pref: |
24 | | - process.env["PREF"] || |
25 | | - process.argv.find((arg) => arg.startsWith("--pref="))?.split("=")[1] || |
26 | | - "", |
27 | | - timezone: process.env.TZ || "America/New_York", |
28 | | - userAgent: |
29 | | - process.env["USER_AGENT"] || |
30 | | - process.argv.find((arg) => arg.startsWith("--userAgent="))?.split("=")[1] || |
31 | | - UserAgent, |
32 | | - outputFile: |
33 | | - process.env["OUTPUT_FILE"] || |
34 | | - process.argv |
35 | | - .find((arg) => arg.startsWith("--outputFile=")) |
36 | | - ?.split("=")[1] || |
37 | | - "xmltv.xml", |
38 | | -}; |
| 7 | + "USA-lineupId-DEFAULT"; |
| 8 | + |
| 9 | + if (lineupId.includes("OTA")) { |
| 10 | + return "USA-lineupId-DEFAULT"; |
| 11 | + } |
| 12 | + |
| 13 | + return lineupId; |
| 14 | +} |
| 15 | + |
| 16 | +function getHeadendId(lineupId: string): string { |
| 17 | + const match = lineupId.match(/^(USA|CAN)-(.*?)(?:-[A-Z]+)?$/); |
| 18 | + |
| 19 | + return match?.[2] || "lineup"; |
| 20 | +} |
| 21 | + |
| 22 | +export function getConfig() { |
| 23 | + const lineupId = processLineupId(); |
| 24 | + const headendId = getHeadendId(lineupId); |
| 25 | + |
| 26 | + return { |
| 27 | + baseUrl: "https://tvlistings.gracenote.com/api/grid", |
| 28 | + lineupId, |
| 29 | + headendId, |
| 30 | + timespan: |
| 31 | + process.env["TIMESPAN"] || |
| 32 | + process.argv |
| 33 | + .find((arg) => arg.startsWith("--timespan=")) |
| 34 | + ?.split("=")[1] || |
| 35 | + "6", |
| 36 | + country: |
| 37 | + process.env["COUNTRY"] || |
| 38 | + process.argv.find((arg) => arg.startsWith("--country="))?.split("=")[1] || |
| 39 | + "USA", |
| 40 | + postalCode: |
| 41 | + process.env["POSTAL_CODE"] || |
| 42 | + process.argv |
| 43 | + .find((arg) => arg.startsWith("--postalCode=")) |
| 44 | + ?.split("=")[1] || |
| 45 | + "30309", |
| 46 | + pref: |
| 47 | + process.env["PREF"] || |
| 48 | + process.argv.find((arg) => arg.startsWith("--pref="))?.split("=")[1] || |
| 49 | + "", |
| 50 | + timezone: process.env.TZ || "America/New_York", |
| 51 | + userAgent: |
| 52 | + process.env["USER_AGENT"] || |
| 53 | + process.argv |
| 54 | + .find((arg) => arg.startsWith("--userAgent=")) |
| 55 | + ?.split("=")[1] || |
| 56 | + UserAgent, |
| 57 | + outputFile: |
| 58 | + process.env["OUTPUT_FILE"] || |
| 59 | + process.argv |
| 60 | + .find((arg) => arg.startsWith("--outputFile=")) |
| 61 | + ?.split("=")[1] || |
| 62 | + "xmltv.xml", |
| 63 | + }; |
| 64 | +} |
0 commit comments