Skip to content

Commit

Permalink
feat: implement multi epg view
Browse files Browse the repository at this point in the history
  • Loading branch information
4gray committed Sep 8, 2022
1 parent e2c7848 commit b4db751
Show file tree
Hide file tree
Showing 9 changed files with 550 additions and 15 deletions.
28 changes: 22 additions & 6 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
EPG_FETCH,
EPG_FETCH_DONE,
EPG_GET_CHANNELS,
EPG_GET_CHANNELS_BY_RANGE,
EPG_GET_CHANNELS_BY_RANGE_RESPONSE,
EPG_GET_CHANNELS_DONE,
EPG_GET_PROGRAM,
EPG_GET_PROGRAM_DONE,
Expand Down Expand Up @@ -192,6 +194,19 @@ export class Api {
)
.on(EPG_ERROR, (event, arg) =>
this.mainWindow.webContents.send(EPG_ERROR, arg)
)
.on(EPG_GET_CHANNELS_BY_RANGE, (event, arg) => {
console.log(JSON.stringify(arg));
this.workerWindow.webContents.send(
EPG_GET_CHANNELS_BY_RANGE,
arg
);
})
.on(EPG_GET_CHANNELS_BY_RANGE_RESPONSE, (event, arg) =>
this.mainWindow.webContents.send(
EPG_GET_CHANNELS_BY_RANGE_RESPONSE,
arg
)
);

ipcMain.on(
Expand Down Expand Up @@ -244,7 +259,7 @@ export class Api {
PLAYLIST_UPDATE_POSITIONS,
(event, playlists: Partial<Playlist[]>) =>
playlists.forEach((list, index) => {
this.updatePlaylistById(list._id, {
this.updatePlaylistById((list as Playlist)._id, {
...list,
position: index,
});
Expand Down Expand Up @@ -369,7 +384,7 @@ export class Api {
session.defaultSession.webRequest.onBeforeSendHeaders(
(details, callback) => {
details.requestHeaders['User-Agent'] = userAgent;
details.requestHeaders['Referer'] = referer;
details.requestHeaders['Referer'] = referer as string;
callback({ requestHeaders: details.requestHeaders });
}
);
Expand Down Expand Up @@ -505,10 +520,11 @@ export class Api {
this.updatePlaylistById(id, {
updateState: PlaylistUpdateState.NOT_UPDATED,
});
event.sender.send(ERROR, {
message: `File not found. Please check the entered playlist URL again.`,
status: err.response.status,
});
if (event)
event.sender.send(ERROR, {
message: `File not found. Please check the entered playlist URL again.`,
status: err.response.status,
});
}
}

Expand Down
39 changes: 39 additions & 0 deletions epg-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
EPG_FETCH,
EPG_FETCH_DONE,
EPG_GET_CHANNELS,
EPG_GET_CHANNELS_BY_RANGE,
EPG_GET_CHANNELS_BY_RANGE_RESPONSE,
EPG_GET_CHANNELS_DONE,
EPG_GET_PROGRAM,
EPG_GET_PROGRAM_DONE,
Expand All @@ -17,6 +19,9 @@ import { EpgProgram } from './src/app/player/models/epg-program.model';

// EPG data store
let EPG_DATA: { channels: EpgChannel[]; programs: EpgProgram[] };
let EPG_DATA_MERGED: {
[id: string]: EpgChannel & { programs: EpgProgram[] };
} = {};
const loggerLabel = '[EPG Worker]';

/**
Expand Down Expand Up @@ -62,10 +67,36 @@ const fetchEpgDataFromUrl = (epgUrl: string) => {
const parseAndSetEpg = (xmlString) => {
console.log(loggerLabel, 'start parsing...');
EPG_DATA = parser.parse(xmlString.toString());
// map programs to channels
EPG_DATA_MERGED = convertEpgData();
ipcRenderer.send(EPG_FETCH_DONE);
console.log(loggerLabel, 'done, parsing was finished...');
};

const convertEpgData = () => {
let result: {
[id: string]: EpgChannel & { programs: EpgProgram[] };
} = {};

EPG_DATA?.programs?.forEach((program) => {
if (!result[program.channel]) {
const channel = EPG_DATA?.channels?.find(
(channel) => channel.id === program.channel
) as EpgChannel;
result[program.channel] = {
...channel,
programs: [program],
};
} else {
result[program.channel] = {
...result[program.channel],
programs: [...result[program.channel].programs, program],
};
}
});
return result;
};

// fetches epg data from the provided URL
ipcRenderer.on(EPG_FETCH, (event, arg) => {
console.log(loggerLabel, 'epg fetch command was triggered');
Expand Down Expand Up @@ -113,3 +144,11 @@ ipcRenderer.on(EPG_GET_CHANNELS, (event, args) => {
payload: EPG_DATA,
});
});

ipcRenderer.on(EPG_GET_CHANNELS_BY_RANGE, (event, args) => {
ipcRenderer.send(EPG_GET_CHANNELS_BY_RANGE_RESPONSE, {
payload: Object.entries(EPG_DATA_MERGED)
.slice(args.skip, args.limit)
.map((entry) => entry[1]),
});
});
3 changes: 3 additions & 0 deletions shared/ipc-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const EPG_GET_PROGRAM = 'EPG:GET_PROGRAM';
export const EPG_GET_PROGRAM_DONE = 'EPG:GET_PROGRAM_DONE';
export const EPG_GET_CHANNELS = 'EPG:GET_CHANNELS';
export const EPG_GET_CHANNELS_DONE = 'EPG:GET_CHANNELS_DONE';
export const EPG_GET_CHANNELS_BY_RANGE = 'EPG:EPG_GET_CHANNELS_BY_RANGE';
export const EPG_GET_CHANNELS_BY_RANGE_RESPONSE =
'EPG:EPG_GET_CHANNELS_BY_RANGE_RESPONSE';

// Playlist related commands
export const PLAYLIST_GET_ALL = 'PLAYLIST:GET_ALL';
Expand Down
142 changes: 142 additions & 0 deletions src/app/player/components/multi-epg/multi-epg-container.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<div id="epg-navigation">
<button
[matTooltip]="'CLOSE' | translate"
mat-button
(click)="close()"
color="accent"
>
<mat-icon>close</mat-icon> {{ 'CLOSE' | translate }}
</button>
<button
[matTooltip]="'EPG.NEXT_DAY' | translate"
mat-icon-button
(click)="switchDay('prev')"
>
<mat-icon>navigate_before</mat-icon>
</button>
<button
[matTooltip]="'EPG.PREVIOUS_DAY' | translate"
mat-icon-button
(click)="switchDay('next')"
>
<mat-icon>navigate_next</mat-icon>
</button>
<div class="today-date">
{{ today | momentDate: 'YYYYMMDD':'MMMM Do, dddd' }}
</div>
<button mat-icon-button (click)="zoomIn()" [disabled]="hourWidth >= 800">
<mat-icon>zoom_in</mat-icon>
</button>
<button mat-icon-button [disabled]="hourWidth <= 50" (click)="zoomOut()">
<mat-icon>zoom_out</mat-icon>
</button>
<button
mat-button
[disabled]="channelsLowerRange === 0"
(click)="previousChannels()"
>
Previous channels
</button>
<button mat-button (click)="nextChannels()">Next channels</button>
</div>
<div class="parent" #epgContainer>
<svg id="channels-column">
<g *ngFor="let item of channels; let i = index">
<!-- channel name -->
<g class="channel">
<rect
width="100"
[attr.height]="barHeight"
[attr.y]="barHeight * i + barHeight"
stroke="black"
></rect>
<image
*ngIf="item.icon[0]"
[attr.y]="barHeight * i + barHeight + 1"
[attr.href]="item.icon[0]"
[attr.height]="barHeight - 2"
width="100"
[matTooltip]="item.name[0].value"
></image>
<foreignObject
*ngIf="!item.icon[0]"
[attr.y]="barHeight * i + barHeight"
width="100"
[attr.height]="barHeight"
>
<div class="channel-name">
{{ item.name[0].value }}
</div>
</foreignObject>
</g>
</g>
</svg>
<div id="epg-container">
<svg [attr.width]="24 * hourWidth" height="100%" id="epg-svg">
<!-- time headline -->
<g *ngFor="let a of timeHeader; let i = index">
<rect
[matTooltip]="i + ':00'"
[attr.width]="hourWidth"
[attr.height]="barHeight"
[attr.x]="i * hourWidth"
fill="#000"
></rect>
<text
[attr.x]="i * hourWidth"
y="10"
font-size="14"
fill="white"
transform="translate(20,20)"
>
{{ i }}:00
</text>
</g>

<!-- epg channels with programs -->
<g *ngFor="let item of channels; let i = index">
<g
*ngFor="let program of item.programs; let a = index"
[matTooltip]="program.title[0].value"
class="program-item"
>
<!-- program item -->
<rect
[attr.width]="program.width"
[attr.height]="barHeight"
[attr.x]="program.startPosition"
[attr.y]="barHeight * i + barHeight"
fill="#000"
></rect>
<foreignObject
(click)="showDescription(program)"
[attr.width]="program.width"
[attr.height]="barHeight"
[attr.y]="barHeight * i + barHeight"
[attr.x]="program.startPosition"
>
<div
[innerHtml]="program.title[0]?.value"
class="program-name"
></div>
</foreignObject>
</g>
<line
[attr.x1]="0"
[attr.y1]="barHeight * i + barHeight"
[attr.x2]="24 * hourWidth"
[attr.y2]="barHeight * i + barHeight"
stroke="#676767"
/>
</g>
<line
[attr.x1]="currentTimeLine"
[attr.y1]="barHeight"
[attr.x2]="currentTimeLine"
id="current-time-line"
y2="1000"
stroke="black"
/>
</svg>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.program-item {
cursor: pointer;
}

rect {
stroke: #676767;
cursor: pointer;
}

.channel > rect {
stroke: #676767;
}

.program-item:hover > rect {
fill: #333;
}

.program-name,
.channel-name {
-webkit-line-clamp: 2;
height: 32px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
padding: 6px 2px;
}

#epg-container {
width: calc(100vw - 100px);
height: calc(100vh - 73px);
overflow-x: scroll;
overflow-y: hidden;
}

.parent {
display: flex;
background-color: black;
}

#channels-column {
width: 100px;
flex: none;
border-right: 2px solid #ccc;
}

.channel-name {
margin: 0 5px;
text-align: center;
}

#epg-navigation {
display: flex;
background-color: black;
margin-top: 30px;
border-bottom: 2px solid #fff;
}

.today-date {
flex: 1;
align-items: center;
line-height: 40px;
height: 40px;
padding: 0 20px;
}

#current-time-line {
stroke-width: 2px;
stroke: white;
}
Loading

0 comments on commit b4db751

Please sign in to comment.