fix: args work now (#54)

This commit is contained in:
Jef LeCompte
2025-07-21 22:30:56 -07:00
committed by GitHub
parent e077f2721c
commit ad7aa8e581
4 changed files with 83 additions and 39 deletions

View File

@@ -27,6 +27,7 @@ jobs:
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version-file: package.json node-version-file: package.json
cache: npm
- name: Install dependencies - name: Install dependencies
run: npm ci run: npm ci
@@ -37,5 +38,16 @@ jobs:
- name: Lint - name: Lint
run: npm run lint run: npm run lint
- name: Test - name: Unit tests
run: npm run test:run run: npm run test:run
- name: Integration tests
run: |
node dist/index.js --lineupId=USA-DITV751-X --timespan=3 --postalCode=80020 --outputFile=dtv.xml
node dist/index.js --lineupId=USA-OTA80020 --timespan=3 --postalCode=80020 --outputFile=ota.xml
# Error if they are the same
if cmp -s dtv.xml ota.xml; then
echo "DTV and OTA outputs are the same, which is unexpected."
exit 1
fi

View File

@@ -1,38 +1,64 @@
import { UserAgent } from "./useragents.js"; import { UserAgent } from "./useragents.js";
export const config = { function processLineupId(): string {
baseUrl: "https://tvlistings.gracenote.com/api/grid", const lineupId =
lineupId:
process.env["LINEUP_ID"] || process.env["LINEUP_ID"] ||
process.argv.find((arg) => arg.startsWith("--lineupId="))?.split("=")[1] || process.argv.find((arg) => arg.startsWith("--lineupId="))?.split("=")[1] ||
"USA-lineupId-DEFAULT", "USA-lineupId-DEFAULT";
timespan:
process.env["TIMESPAN"] || if (lineupId.includes("OTA")) {
process.argv.find((arg) => arg.startsWith("--timespan="))?.split("=")[1] || return "USA-lineupId-DEFAULT";
"6", }
country:
process.env["COUNTRY"] || return lineupId;
process.argv.find((arg) => arg.startsWith("--country="))?.split("=")[1] || }
"USA",
postalCode: function getHeadendId(lineupId: string): string {
process.env["POSTAL_CODE"] || const match = lineupId.match(/^(USA|CAN)-(.*?)(?:-[A-Z]+)?$/);
process.argv
.find((arg) => arg.startsWith("--postalCode=")) return match?.[2] || "lineup";
?.split("=")[1] || }
"30309",
pref: export function getConfig() {
process.env["PREF"] || const lineupId = processLineupId();
process.argv.find((arg) => arg.startsWith("--pref="))?.split("=")[1] || const headendId = getHeadendId(lineupId);
"",
timezone: process.env.TZ || "America/New_York", return {
userAgent: baseUrl: "https://tvlistings.gracenote.com/api/grid",
process.env["USER_AGENT"] || lineupId,
process.argv.find((arg) => arg.startsWith("--userAgent="))?.split("=")[1] || headendId,
UserAgent, timespan:
outputFile: process.env["TIMESPAN"] ||
process.env["OUTPUT_FILE"] || process.argv
process.argv .find((arg) => arg.startsWith("--timespan="))
.find((arg) => arg.startsWith("--outputFile=")) ?.split("=")[1] ||
?.split("=")[1] || "6",
"xmltv.xml", country:
}; process.env["COUNTRY"] ||
process.argv.find((arg) => arg.startsWith("--country="))?.split("=")[1] ||
"USA",
postalCode:
process.env["POSTAL_CODE"] ||
process.argv
.find((arg) => arg.startsWith("--postalCode="))
?.split("=")[1] ||
"30309",
pref:
process.env["PREF"] ||
process.argv.find((arg) => arg.startsWith("--pref="))?.split("=")[1] ||
"",
timezone: process.env.TZ || "America/New_York",
userAgent:
process.env["USER_AGENT"] ||
process.argv
.find((arg) => arg.startsWith("--userAgent="))
?.split("=")[1] ||
UserAgent,
outputFile:
process.env["OUTPUT_FILE"] ||
process.argv
.find((arg) => arg.startsWith("--outputFile="))
?.split("=")[1] ||
"xmltv.xml",
};
}

View File

@@ -1,7 +1,9 @@
import { writeFileSync } from "node:fs"; import { writeFileSync } from "node:fs";
import { getTVListings } from "./tvlistings.js"; import { getTVListings } from "./tvlistings.js";
import { buildXmltv } from "./xmltv.js"; import { buildXmltv } from "./xmltv.js";
import { config } from "./config.js"; import { getConfig } from "./config.js";
const config = getConfig();
function isHelp() { function isHelp() {
if (process.argv.includes("--help")) { if (process.argv.includes("--help")) {

View File

@@ -1,4 +1,6 @@
import { config } from "./config.js"; import { getConfig } from "./config.js";
const config = getConfig();
export interface Program { export interface Program {
/** "title": "GMA3" */ /** "title": "GMA3" */
@@ -82,7 +84,7 @@ function buildUrl(time: number, timespan: number): string {
const params = { const params = {
lineupId: config.lineupId, lineupId: config.lineupId,
timespan: timespan.toString(), timespan: timespan.toString(),
headendId: "lineupId", headendId: config.headendId,
country: config.country, country: config.country,
timezone: config.timezone, timezone: config.timezone,
postalCode: config.postalCode, postalCode: config.postalCode,
@@ -91,6 +93,8 @@ function buildUrl(time: number, timespan: number): string {
aid: "orbebb", aid: "orbebb",
languagecode: "en-us", languagecode: "en-us",
time: time.toString(), time: time.toString(),
device: "X",
userId: "-",
}; };
const urlParams = new URLSearchParams(params).toString(); const urlParams = new URLSearchParams(params).toString();
@@ -119,7 +123,7 @@ export async function getTVListings(): Promise<GridApiResponse> {
}).then(async (response) => { }).then(async (response) => {
if (!response.ok) { if (!response.ok) {
throw new Error( throw new Error(
`Failed to fetch: ${response.status} ${response.statusText}` `Failed to fetch: ${response.status} ${response.statusText}`,
); );
} }
const chunkData = (await response.json()) as GridApiResponse; const chunkData = (await response.json()) as GridApiResponse;