Skip to content

Commit

Permalink
Added some secret debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 22, 2024
1 parent bbcdc3b commit 292a10e
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions services/b1g-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -251,6 +252,8 @@ class B1GHandler {
page += 1;
}

debug.saveRequestData(events, 'b1g+', 'epg');

await parseAirings(events);
} catch (e) {
console.error(e);
Expand Down
3 changes: 3 additions & 0 deletions services/cbs-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -380,6 +381,8 @@ class CBSHandler {
},
});

debug.saveRequestData(data, 'cbssports', 'epg');

data.forEach(e => {
if (
(e.video.authentication.includes('adobe') || _.isEqual(e.video.authentication, [])) &&
Expand Down
26 changes: 26 additions & 0 deletions services/debug.ts
Original file line number Diff line number Diff line change
@@ -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();
7 changes: 7 additions & 0 deletions services/espn-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
};

Expand All @@ -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;
};

Expand Down
3 changes: 3 additions & 0 deletions services/flo-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 => {
Expand Down
3 changes: 3 additions & 0 deletions services/fox-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -430,6 +431,8 @@ class FoxHandler {
},
);

debug.saveRequestData(data, 'foxsports', 'epg');

_.forEach(data.panels.member, member => {
_.forEach(member.items.member, m => {
if (
Expand Down
5 changes: 5 additions & 0 deletions services/init-directories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions services/mlb-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions services/mw-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,6 +99,8 @@ class MountainWestHandler {
},
});

debug.saveRequestData(data, 'mtnwest', 'epg');

await parseAirings(data.data);
} catch (e) {
console.error(e);
Expand Down
3 changes: 3 additions & 0 deletions services/nesn-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)']}`,
Expand Down
3 changes: 3 additions & 0 deletions services/nfl-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -381,6 +382,8 @@ class NflHandler {
},
});

debug.saveRequestData(data, 'nfl', 'epg');

data.data.items.forEach(i => {
if (moment(i.startTime).isBefore(endSchedule)) {
if (
Expand Down
5 changes: 5 additions & 0 deletions services/paramount-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -446,6 +449,8 @@ class ParamountHandler {
})}`,
);

debug.saveRequestData(data, 'paramount+channels', 'epg');

const channels: IChannel[] = [];

for (const c of data.carousel) {
Expand Down

0 comments on commit 292a10e

Please sign in to comment.