From 292a10e60973ff8c74d8c34065cf1709953e2622 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 22 Oct 2024 11:37:58 -0600 Subject: [PATCH] Added some secret debugging --- services/b1g-handler.ts | 3 +++ services/cbs-handler.ts | 3 +++ services/debug.ts | 26 ++++++++++++++++++++++++++ services/espn-handler.ts | 7 +++++++ services/flo-handler.ts | 3 +++ services/fox-handler.ts | 3 +++ services/init-directories.ts | 5 +++++ services/mlb-handler.ts | 4 ++++ services/mw-handler.ts | 3 +++ services/nesn-handler.ts | 3 +++ services/nfl-handler.ts | 3 +++ services/paramount-handler.ts | 5 +++++ 12 files changed, 68 insertions(+) create mode 100644 services/debug.ts diff --git a/services/b1g-handler.ts b/services/b1g-handler.ts index cf1d5a9..128ef89 100644 --- a/services/b1g-handler.ts +++ b/services/b1g-handler.ts @@ -10,6 +10,7 @@ import {configPath} from './config'; import {useB1GPlus} from './networks'; import {ClassTypeWithoutMethods, IEntry, IHeaders, IProvider} from './shared-interfaces'; import {db} from './database'; +import {debug} from './debug'; interface IEventCategory { name: string; @@ -251,6 +252,8 @@ class B1GHandler { page += 1; } + debug.saveRequestData(events, 'b1g+', 'epg'); + await parseAirings(events); } catch (e) { console.error(e); diff --git a/services/cbs-handler.ts b/services/cbs-handler.ts index bb29085..da92e5c 100644 --- a/services/cbs-handler.ts +++ b/services/cbs-handler.ts @@ -13,6 +13,7 @@ import {ClassTypeWithoutMethods, IEntry, IHeaders, IProvider} from './shared-int import {db} from './database'; import {getRandomUUID} from './shared-helpers'; import {createAdobeAuthHeader} from './adobe-helpers'; +import {debug} from './debug'; interface ICBSEvent { id: number; @@ -380,6 +381,8 @@ class CBSHandler { }, }); + debug.saveRequestData(data, 'cbssports', 'epg'); + data.forEach(e => { if ( (e.video.authentication.includes('adobe') || _.isEqual(e.video.authentication, [])) && diff --git a/services/debug.ts b/services/debug.ts new file mode 100644 index 0000000..09c7d7b --- /dev/null +++ b/services/debug.ts @@ -0,0 +1,26 @@ +import path from 'path'; +import fsExtra from 'fs-extra'; + +import {configPath} from './config'; + +export const debugPath = path.join(configPath, 'debug'); + +class Debug { + enabled: boolean; + + constructor() { + this.enabled = process.env.DEBUGGING?.toLowerCase() === 'true' ? true : false; + } + + public saveRequestData = (data: any, provider: string, type: string): void => { + if (!this.enabled) { + return; + } + + fsExtra.writeJSON(path.join(debugPath, `${provider}-${type}-${new Date().valueOf()}.json`), data, { + spaces: 2, + }); + }; +} + +export const debug = new Debug(); diff --git a/services/espn-handler.ts b/services/espn-handler.ts index 183a207..7cb03c5 100644 --- a/services/espn-handler.ts +++ b/services/espn-handler.ts @@ -30,6 +30,7 @@ import {getRandomHex} from './shared-helpers'; import {ClassTypeWithoutMethods, IEntry, IHeaders, IJWToken, IProvider} from './shared-interfaces'; import {db} from './database'; import {useLinear} from './channels'; +import {debug} from './debug'; global.WebSocket = ws; @@ -875,6 +876,9 @@ class EspnHandler { `https://watch.graph.api.espn.com/api?apiKey=${this.graphQlApiKey}&query=${query}&variables=${variables}`, ), ); + + debug.saveRequestData(entryData, network || 'espn+', 'live-epg'); + return entryData.data.airings; }; @@ -892,6 +896,9 @@ class EspnHandler { `https://watch.graph.api.espn.com/api?apiKey=${this.graphQlApiKey}&query=${query}&variables=${variables}`, ), ); + + debug.saveRequestData(entryData, network || 'espn+', 'upcoming-epg'); + return entryData.data.airings; }; diff --git a/services/flo-handler.ts b/services/flo-handler.ts index 2a34739..e8ee516 100644 --- a/services/flo-handler.ts +++ b/services/flo-handler.ts @@ -10,6 +10,7 @@ import {useFloSports} from './networks'; import {ClassTypeWithoutMethods, IEntry, IHeaders, IProvider} from './shared-interfaces'; import {db} from './database'; import {getRandomUUID} from './shared-helpers'; +import {debug} from './debug'; interface IFloEventsRes { sections: { @@ -175,6 +176,8 @@ class FloSportsHandler { }, }); + debug.saveRequestData(data, 'flosports', 'epg'); + data?.sections.forEach(e => { if (e.id === 'live-and-upcoming' || e.title === 'Live & Upcoming') { e.items.forEach(a => { diff --git a/services/fox-handler.ts b/services/fox-handler.ts index e315893..9cb4ef3 100644 --- a/services/fox-handler.ts +++ b/services/fox-handler.ts @@ -13,6 +13,7 @@ import {getRandomHex} from './shared-helpers'; import {ClassTypeWithoutMethods, IEntry, IHeaders, IProvider} from './shared-interfaces'; import {db} from './database'; import {useLinear} from './channels'; +import {debug} from './debug'; interface IAppConfig { api: { @@ -430,6 +431,8 @@ class FoxHandler { }, ); + debug.saveRequestData(data, 'foxsports', 'epg'); + _.forEach(data.panels.member, member => { _.forEach(member.items.member, m => { if ( diff --git a/services/init-directories.ts b/services/init-directories.ts index 859444f..01f829b 100644 --- a/services/init-directories.ts +++ b/services/init-directories.ts @@ -9,12 +9,17 @@ import { initializeProviders, providersDb, } from './database'; +import {debug, debugPath} from './debug'; export const initDirectories = (): void => { if (!fs.existsSync(configPath)) { fs.mkdirSync(configPath); } + if (debug.enabled && !fs.existsSync(debugPath)) { + fs.mkdirSync(debugPath); + } + if (!fs.existsSync(entriesDb)) { initializeEntries(); } diff --git a/services/mlb-handler.ts b/services/mlb-handler.ts index 6ae8185..521fabc 100644 --- a/services/mlb-handler.ts +++ b/services/mlb-handler.ts @@ -11,6 +11,7 @@ import {useMLBtv, useMLBtvOnlyFree} from './networks'; import {ClassTypeWithoutMethods, IEntry, IHeaders, IProvider} from './shared-interfaces'; import {db} from './database'; import {useLinear} from './channels'; +import {debug} from './debug'; interface IGameContent { media: { @@ -317,6 +318,9 @@ class MLBHandler { const entries = await this.getEvents(); const feeds = await this.getFeeds(); + debug.saveRequestData(entries, 'mlb', 'entries'); + debug.saveRequestData(feeds, 'mlb', 'feeds'); + const combinedEntries: ICombinedGame = {}; for (const feed of feeds) { diff --git a/services/mw-handler.ts b/services/mw-handler.ts index 232de8d..0848477 100644 --- a/services/mw-handler.ts +++ b/services/mw-handler.ts @@ -5,6 +5,7 @@ import {userAgent} from './user-agent'; import {useMountainWest} from './networks'; import {IEntry, IHeaders, IProvider} from './shared-interfaces'; import {db} from './database'; +import {debug} from './debug'; interface IMWEvent { image: string; @@ -98,6 +99,8 @@ class MountainWestHandler { }, }); + debug.saveRequestData(data, 'mtnwest', 'epg'); + await parseAirings(data.data); } catch (e) { console.error(e); diff --git a/services/nesn-handler.ts b/services/nesn-handler.ts index eb56087..1ee45cf 100644 --- a/services/nesn-handler.ts +++ b/services/nesn-handler.ts @@ -13,6 +13,7 @@ import {ClassTypeWithoutMethods, IEntry, IHeaders, IJWToken, IProvider} from './ import {db} from './database'; import {getRandomHex, getRandomUUID} from './shared-helpers'; import {useLinear} from './channels'; +import {debug} from './debug'; const ADOBE_CLIENT_ID = [ '6', @@ -379,6 +380,8 @@ class NesnHandler { }, }); + debug.saveRequestData(data, 'nesn', 'epg'); + for (const event of data) { const eventStart = moment.utc( `${event['Start Date (UTC)']} ${event['Start Time (UTC)']}`, diff --git a/services/nfl-handler.ts b/services/nfl-handler.ts index 0787d42..3e516e1 100644 --- a/services/nfl-handler.ts +++ b/services/nfl-handler.ts @@ -12,6 +12,7 @@ import {ClassTypeWithoutMethods, IEntry, IHeaders, IProvider} from './shared-int import {db} from './database'; import {getRandomUUID} from './shared-helpers'; import {useLinear} from './channels'; +import {debug} from './debug'; interface INFLRes { data: { @@ -381,6 +382,8 @@ class NflHandler { }, }); + debug.saveRequestData(data, 'nfl', 'epg'); + data.data.items.forEach(i => { if (moment(i.startTime).isBefore(endSchedule)) { if ( diff --git a/services/paramount-handler.ts b/services/paramount-handler.ts index 410198a..9d69c2c 100644 --- a/services/paramount-handler.ts +++ b/services/paramount-handler.ts @@ -12,6 +12,7 @@ import {getRandomHex} from './shared-helpers'; import {db} from './database'; import {ClassTypeWithoutMethods, IEntry, IHeaders, IProvider} from './shared-interfaces'; import {useLinear} from './channels'; +import {debug} from './debug'; const BASE_THUMB_URL = 'https://wwwimage-us.pplusstatic.com/thumbnails/photos/w370-q80/'; const BASE_URL = 'https://www.paramountplus.com'; @@ -301,6 +302,8 @@ class ParamountHandler { const channels = await this.getLiveChannels(); + debug.saveRequestData(data, 'paramount+local', 'epg'); + for (const c of channels) { try { const {data} = await instance.get( @@ -446,6 +449,8 @@ class ParamountHandler { })}`, ); + debug.saveRequestData(data, 'paramount+channels', 'epg'); + const channels: IChannel[] = []; for (const c of data.carousel) {