Skip to content

Commit

Permalink
config/server: add logoDataInterval to suppress parsing logo data f…
Browse files Browse the repository at this point in the history
…requently
  • Loading branch information
kanreisa committed Aug 7, 2021
1 parent 49a121f commit f25f43e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions api.d.ts
Expand Up @@ -205,6 +205,7 @@ export interface ConfigServer {
programGCInterval?: number;
epgGatheringInterval?: number;
epgRetrievalTime?: number;
logoDataInterval?: number;
disableEITParsing?: boolean;
}

Expand Down
2 changes: 2 additions & 0 deletions api.yml
Expand Up @@ -457,6 +457,8 @@ definitions:
type: integer
epgRetrievalTime:
type: integer
logoDataInterval:
type: integer
disableEITParsing:
type: boolean

Expand Down
2 changes: 2 additions & 0 deletions doc/Configuration.md
Expand Up @@ -26,6 +26,7 @@ eventEndTimeout: 1000 # integer (ms)
programGCInterval: 900000 # integer (ms)
epgGatheringInterval: 900000 # integer (ms)
epgRetrievalTime: 600000 # integer (ms)
logoDataInterval: 86400000 # integer (ms)
disableEITParsing: false # boolean
```

Expand All @@ -42,6 +43,7 @@ EVENT_END_TIMEOUT
PROGRAM_GC_INTERVAL
EPG_GATHERING_INTERVAL
EPG_RETRIEVAL_TIME
LOGO_DATA_INTERVAL
DISABLE_EIT_PARSING
```

Expand Down
26 changes: 24 additions & 2 deletions src/Mirakurun/TSFilter.ts
Expand Up @@ -347,7 +347,7 @@ export default class TSFilter extends stream.Transform {
this._parses.push(packet);
}
} else if (
((pid === 0x12 || pid === 0x29) && (this._parseEIT || this._provideEventId !== null)) ||
(pid === 0x12 && (this._parseEIT || this._provideEventId !== null)) ||
pid === 0x14 ||
this._parsePids.has(pid)
) {
Expand Down Expand Up @@ -584,7 +584,7 @@ export default class TSFilter extends stream.Transform {
}
}

private _onEIT(pid: number, data: any): void {
private async _onEIT(pid: number, data: any): Promise<void> {

// detect current event
if (
Expand Down Expand Up @@ -625,6 +625,28 @@ export default class TSFilter extends stream.Transform {
if (!this._epg && status.epg[this._targetNetworkId] !== true) {
status.epg[this._targetNetworkId] = true;
this._epg = new EPG();

// check logoDataInterval
const services = this._provideServiceId === null ?
_.service.findByNetworkId(this._targetNetworkId) :
[_.service.get(this._targetNetworkId, this._provideServiceId)];

const logoIdSet = new Set<number>();

for (const service of services) {
if (typeof service.logoId === "number" && service.logoId >= 0) {
logoIdSet.add(service.logoId);
}
}

const now = Date.now();
const logoDataInterval = _.config.server.logoDataInterval || 1000 * 60 * 60 * 24; // 1 day
for (const logoId of logoIdSet) {
if (now - await Service.getLogoDataMTime(this._targetNetworkId, logoId) > logoDataInterval) {
this._parsePids.add(0x29); // CDT for Logo
break;
}
}
}

if (this._epg) {
Expand Down
5 changes: 5 additions & 0 deletions src/Mirakurun/config.ts
Expand Up @@ -38,6 +38,7 @@ const {
PROGRAM_GC_INTERVAL,
EPG_GATHERING_INTERVAL,
EPG_RETRIEVAL_TIME,
LOGO_DATA_INTERVAL,
DISABLE_EIT_PARSING
} = process.env;

Expand Down Expand Up @@ -69,6 +70,7 @@ export interface Server {
readonly programGCInterval?: number;
readonly epgGatheringInterval?: number;
readonly epgRetrievalTime?: number;
readonly logoDataInterval?: number;
readonly disableEITParsing?: true;
}

Expand Down Expand Up @@ -193,6 +195,9 @@ export function loadServer(): Server {
if (typeof EPG_RETRIEVAL_TIME !== "undefined" && /^[0-9]+$/.test(EPG_RETRIEVAL_TIME)) {
config.epgRetrievalTime = parseInt(EPG_RETRIEVAL_TIME, 10);
}
if (typeof LOGO_DATA_INTERVAL !== "undefined" && /^[0-9]+$/.test(LOGO_DATA_INTERVAL)) {
config.logoDataInterval = parseInt(LOGO_DATA_INTERVAL, 10);
}
if (DISABLE_EIT_PARSING === "true") {
config.disableEITParsing = true;
}
Expand Down

0 comments on commit f25f43e

Please sign in to comment.