fix: args work now (#54)
This commit is contained in:
14
.github/workflows/ci.yaml
vendored
14
.github/workflows/ci.yaml
vendored
@@ -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
|
||||||
|
|||||||
@@ -1,14 +1,37 @@
|
|||||||
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";
|
||||||
|
|
||||||
|
if (lineupId.includes("OTA")) {
|
||||||
|
return "USA-lineupId-DEFAULT";
|
||||||
|
}
|
||||||
|
|
||||||
|
return lineupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHeadendId(lineupId: string): string {
|
||||||
|
const match = lineupId.match(/^(USA|CAN)-(.*?)(?:-[A-Z]+)?$/);
|
||||||
|
|
||||||
|
return match?.[2] || "lineup";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getConfig() {
|
||||||
|
const lineupId = processLineupId();
|
||||||
|
const headendId = getHeadendId(lineupId);
|
||||||
|
|
||||||
|
return {
|
||||||
|
baseUrl: "https://tvlistings.gracenote.com/api/grid",
|
||||||
|
lineupId,
|
||||||
|
headendId,
|
||||||
timespan:
|
timespan:
|
||||||
process.env["TIMESPAN"] ||
|
process.env["TIMESPAN"] ||
|
||||||
process.argv.find((arg) => arg.startsWith("--timespan="))?.split("=")[1] ||
|
process.argv
|
||||||
|
.find((arg) => arg.startsWith("--timespan="))
|
||||||
|
?.split("=")[1] ||
|
||||||
"6",
|
"6",
|
||||||
country:
|
country:
|
||||||
process.env["COUNTRY"] ||
|
process.env["COUNTRY"] ||
|
||||||
@@ -27,7 +50,9 @@ export const config = {
|
|||||||
timezone: process.env.TZ || "America/New_York",
|
timezone: process.env.TZ || "America/New_York",
|
||||||
userAgent:
|
userAgent:
|
||||||
process.env["USER_AGENT"] ||
|
process.env["USER_AGENT"] ||
|
||||||
process.argv.find((arg) => arg.startsWith("--userAgent="))?.split("=")[1] ||
|
process.argv
|
||||||
|
.find((arg) => arg.startsWith("--userAgent="))
|
||||||
|
?.split("=")[1] ||
|
||||||
UserAgent,
|
UserAgent,
|
||||||
outputFile:
|
outputFile:
|
||||||
process.env["OUTPUT_FILE"] ||
|
process.env["OUTPUT_FILE"] ||
|
||||||
@@ -36,3 +61,4 @@ export const config = {
|
|||||||
?.split("=")[1] ||
|
?.split("=")[1] ||
|
||||||
"xmltv.xml",
|
"xmltv.xml",
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -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")) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user