diff --git a/packages/addon/src/addon.ts b/packages/addon/src/addon.ts index 4eaf70bb..114735b8 100644 --- a/packages/addon/src/addon.ts +++ b/packages/addon/src/addon.ts @@ -29,6 +29,7 @@ import { addonDetails, createProxiedMediaFlowUrl, getMediaFlowConfig, + getTimeTakenSincePoint, Settings, } from '@aiostreams/utils'; import { errorStream } from './responses'; @@ -43,23 +44,7 @@ export class AIOStreams { public async getStreams(streamRequest: StreamRequest): Promise { const streams: Stream[] = []; const startTime = new Date().getTime(); - const getTimeTakenSincePoint = (point: number) => { - const timeNow = new Date().getTime(); - const duration = timeNow - point; - // format duration and choose unit and return - const nanos = duration * 1_000_000; // Convert to nanoseconds - const micros = duration * 1_000; // Convert to microseconds - if (nanos < 1) { - return `${nanos.toFixed(2)}ns`; - } else if (micros < 1) { - return `${micros.toFixed(2)}µs`; - } else if (duration < 1000) { - return `${duration.toFixed(2)}ms`; - } else { - return `${(duration / 1000).toFixed(2)}s`; - } - }; const { errorStreams, parsedStreams } = await this.getParsedStreams(streamRequest); @@ -436,11 +421,6 @@ export class AIOStreams { if (!proxiedUrl) { throw new Error('Could not create MediaFlow proxied URL'); } - if (Settings.LOG_SENSITIVE_INFO) { - console.log( - `|INF| addon > createMediaFlowStream: Proxied URL for ${name}: ${proxiedUrl}` - ); - } const combinedTags = [ parsedStream.resolution, parsedStream.quality, @@ -471,13 +451,6 @@ export class AIOStreams { private shouldProxyStream(stream: ParsedStream): boolean { const mediaFlowConfig = getMediaFlowConfig(this.config); - if (Settings.LOG_SENSITIVE_INFO) { - console.debug( - `|DBG| addon > shouldProxyStream: MediaFlow config: ${JSON.stringify( - mediaFlowConfig - )}` - ); - } if (!mediaFlowConfig.mediaFlowEnabled) return false; if (!stream.url) return false; // now check if mediaFlowConfig.proxiedAddons or mediaFlowConfig.proxiedServices is not null @@ -487,11 +460,6 @@ export class AIOStreams { mediaFlowConfig.proxiedAddons.length > 0 && !mediaFlowConfig.proxiedAddons.includes(stream.addon.id) ) { - if (Settings.LOG_SENSITIVE_INFO) { - console.debug( - `|DBG| addon > shouldProxyStream: Stream from addon ${stream.addon.id} is not proxied so skipping` - ); - } return false; } @@ -505,20 +473,9 @@ export class AIOStreams { !stream.provider && !mediaFlowConfig.proxiedServices.includes('none')) ) { - if (Settings.LOG_SENSITIVE_INFO) { - console.debug( - `|DBG| addon > shouldProxyStream: Stream from provider ${stream.provider?.id} is not proxied so skipping` - ); - } return false; } - if (Settings.LOG_SENSITIVE_INFO) { - console.debug( - `|DBG| addon > shouldProxyStream: Stream from addon ${stream.addon.id} and provider ${stream.provider?.id} with URL ${stream.url} is eligible for proxying, attempting to create MediaFlow stream` - ); - } - return true; } @@ -581,11 +538,6 @@ export class AIOStreams { let stream: Stream; const shouldProxy = this.shouldProxyStream(parsedStream); - if (Settings.LOG_SENSITIVE_INFO) { - console.debug( - `|DBG| addon > createStreamObject: Determined that stream ${name} should${shouldProxy ? '' : ' not'} be proxied` - ); - } if (shouldProxy) { try { const mediaFlowStream = this.createMediaFlowStream( @@ -877,6 +829,7 @@ export class AIOStreams { addon.id; const addonId = `${addon.id}-${JSON.stringify(addon.options)}`; try { + const startTime = new Date().getTime(); const streams = await this.getStreamsFromAddon( addon, addonId, @@ -884,7 +837,7 @@ export class AIOStreams { ); parsedStreams.push(...streams); console.log( - `|INF| addon > getParsedStreams: Got ${streams.length} streams from addon ${addonName}` + `|INF| addon > getParsedStreams: Got ${streams.length} streams from addon ${addonName} in ${getTimeTakenSincePoint(startTime)}` ); } catch (error: any) { console.error( diff --git a/packages/utils/src/general.ts b/packages/utils/src/general.ts new file mode 100644 index 00000000..e2e3c093 --- /dev/null +++ b/packages/utils/src/general.ts @@ -0,0 +1,17 @@ +export const getTimeTakenSincePoint = (point: number) => { + const timeNow = new Date().getTime(); + const duration = timeNow - point; + // format duration and choose unit and return + const nanos = duration * 1_000_000; // Convert to nanoseconds + const micros = duration * 1_000; // Convert to microseconds + + if (nanos < 1) { + return `${nanos.toFixed(2)}ns`; + } else if (micros < 1) { + return `${micros.toFixed(2)}µs`; + } else if (duration < 1000) { + return `${duration.toFixed(2)}ms`; + } else { + return `${(duration / 1000).toFixed(2)}s`; + } +}; diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 5134cc0d..a3624606 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -3,3 +3,4 @@ export * from './details'; export * from './settings'; export * from './mediaflow'; export * from './cache'; +export * from './general'; diff --git a/packages/utils/src/mediaflow.ts b/packages/utils/src/mediaflow.ts index 7f49d410..6f2c84fe 100644 --- a/packages/utils/src/mediaflow.ts +++ b/packages/utils/src/mediaflow.ts @@ -106,10 +106,6 @@ export async function getMediaFlowPublicIp( return cachedPublicIp; } - console.debug( - '|DBG| mediaflow > getMediaFlowPublicIp > GET /proxy/ip?api_password=***' - ); - const proxyIpUrl = mediaFlowUrl; const proxyIpPath = '/proxy/ip'; proxyIpUrl.pathname = `${proxyIpUrl.pathname === '/' ? '' : proxyIpUrl.pathname}${proxyIpPath}`; @@ -117,6 +113,16 @@ export async function getMediaFlowPublicIp( api_password: mediaFlowConfig.apiPassword, }).toString(); + if (Settings.LOG_SENSITIVE_INFO) { + console.debug( + `|DBG| mediaflow > getMediaFlowPublicIp > GET ${proxyIpUrl.toString()}` + ); + } else { + console.debug( + '|DBG| mediaflow > getMediaFlowPublicIp > GET /proxy/ip?api_password=***' + ); + } + const response = await fetch(proxyIpUrl.toString(), { method: 'GET', headers: {