Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/stalker portal #289

Merged
merged 27 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2a91237
feat: add experimental vlc player support
4gray Jul 29, 2023
ef80b6f
chore: update iptv-playlist-parser and prettier
4gray Aug 5, 2023
011204a
refactor: update interfaces according to updates
4gray Aug 5, 2023
1e2ab0b
feat(stalker): new interfaces and ipc commands
4gray Aug 6, 2023
a749bec
refactor(xtream): update navigation-bar component
4gray Aug 6, 2023
91568c0
feat(stalker): add stalker portal related translations
4gray Aug 6, 2023
e06e0d5
fix(xtream): reset search text after navigation
4gray Aug 6, 2023
86ad066
fix(xtream): update changes after saving
4gray Aug 6, 2023
204525f
refactor(xtream): remove unused import
4gray Aug 6, 2023
53c3b30
refactor(xtream): code style improvements
4gray Aug 6, 2023
fd001c2
feat(stalker): add import stalker portal component
4gray Aug 6, 2023
1ac733c
feat(stalker): add stalker related inputs to playlist-info dialog
4gray Aug 7, 2023
94decaf
refactor: support stalker portal in playlist-item cmp
4gray Aug 7, 2023
9e24b1f
feat: stalker portal support in the main process
4gray Aug 9, 2023
40f781c
feat: stalker portal support for the pwa
4gray Aug 9, 2023
ff90a66
refactor: fix navigation to stalker portal playlist
4gray Aug 9, 2023
9044fe4
refactor: some improvements in interfaces
4gray Aug 9, 2023
bb0e832
refactor(portals): some improvements in nav-bar
4gray Aug 12, 2023
adea3cf
refactor(stalker): extend portal related store
4gray Aug 14, 2023
01d1cc5
refactor: add store logic for navigation to adjacent channels
4gray Aug 17, 2023
3bec356
feat(portals): extend models and interfaces
4gray Aug 17, 2023
53d4f9b
style(portals): card style improvements
4gray Aug 17, 2023
c9f7735
chore: update material icons font
4gray Aug 17, 2023
811b329
feta: stalker portal support
4gray Aug 20, 2023
49f3359
refactor: add translation strings
4gray Aug 20, 2023
88362d2
refactor(portals): adapt favorites interface
4gray Aug 20, 2023
1772dac
refactor: code improvements in video player & channels list component
4gray Aug 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 92 additions & 8 deletions electron/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ import {
MIGRATE_PLAYLISTS_RESPONSE,
OPEN_FILE,
OPEN_MPV_PLAYER,
OPEN_VLC_PLAYER,
PLAYLIST_PARSE_BY_URL,
PLAYLIST_PARSE_RESPONSE,
PLAYLIST_UPDATE,
PLAYLIST_UPDATE_RESPONSE,
SET_MPV_PLAYER_PATH,
SET_VLC_PLAYER_PATH,
STALKER_REQUEST,
STALKER_RESPONSE,
XTREAM_REQUEST,
XTREAM_RESPONSE,
} from '../shared/ipc-commands';
Expand All @@ -39,6 +43,8 @@ import { ParsedPlaylist } from '../src/typings.d';

const fs = require('fs');
const https = require('https');
const child_process = require('child_process');
const path = require('path');

const mpvAPI = require('node-mpv');

Expand All @@ -63,6 +69,7 @@ const agent = new https.Agent({
});

const MPV_PLAYER_PATH = 'MPV_PLAYER_PATH';
const VLC_PLAYER_PATH = 'VLC_PLAYER_PATH';

export class Api {
/** Instance of the main application window */
Expand Down Expand Up @@ -254,6 +261,24 @@ export class Api {
// recreate mpv player instance with new binary path if it was changed
if (store.get(MPV_PLAYER_PATH, mpvPlayerPath) !== mpvPlayerPath)
this.mpv = this.createMpvInstance();
})
.on(OPEN_VLC_PLAYER, (event, { url }) => {
const proc = child_process.spawn(
this.getVlcPath(),
[`"${url as string}"`],
{
shell: true,
}
);

proc.on('exit', (code) => {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.log(`VLC exited with code ${code}`);
});
})
.on(SET_VLC_PLAYER_PATH, (_event, vlcPlayerPath) => {
console.log('... setting vlc player path', vlcPlayerPath);
store.set(VLC_PLAYER_PATH, vlcPlayerPath);
});

// listeners for EPG events
Expand Down Expand Up @@ -295,17 +320,52 @@ export class Api {
this.workerWindow.webContents.send(EPG_FORCE_FETCH, arg)
);

ipcMain.on(
XTREAM_REQUEST,
(event, arg: { url: string; params: Record<string, string> }) => {
const xtreamApiPath = '/player_api.php';
ipcMain
.on(
XTREAM_REQUEST,
(
event,
arg: { url: string; params: Record<string, string> }
) => {
const xtreamApiPath = '/player_api.php';

axios
.get(arg.url + xtreamApiPath, {
params: arg.params ?? {},
})
.then((result) => {
event.sender.send(XTREAM_RESPONSE, {
payload: result.data,
action: arg.params.action,
});
})
.catch((err) => {
event.sender.send(ERROR, {
message:
err.response?.statusText ??
'Error: not found',
status: err.response?.status ?? 404,
});
});
}
)
.on(STALKER_REQUEST, (event, arg: any) => {
axios
.get(arg.url + xtreamApiPath, {
.get(arg.url, {
params: arg.params ?? {},
headers: {
Cookie: `mac=${arg.macAddress as string}`,
...(arg.params.token
? {
Authorization: `Bearer ${
arg.params.token as string
}`,
}
: {}),
},
})
.then((result) => {
event.sender.send(XTREAM_RESPONSE, {
event.sender.send(STALKER_RESPONSE, {
payload: result.data,
action: arg.params.action,
});
Expand All @@ -317,8 +377,7 @@ export class Api {
status: err.response?.status ?? 404,
});
});
}
);
});
}

createMpvInstance() {
Expand Down Expand Up @@ -503,6 +562,31 @@ export class Api {
return parse(m3uString);
}

getDefaultVlcPath() {
if (process.platform === 'win32') {
return path.join(
'C:',
'Program Files (x86)',
'VideoLAN',
'VLC',
'vlc.exe'
);
} else if (process.platform === 'linux') {
return '/usr/bin/vlc';
} else if (process.platform === 'darwin') {
return '/Applications/VLC.app/Contents/MacOS/VLC';
}
}

getVlcPath() {
const customVlcPath = this.store.get(VLC_PLAYER_PATH);
if (customVlcPath) {
return customVlcPath;
} else {
return this.getDefaultVlcPath();
}
}

/** @deprecated - used only for migration */
getAllPlaylists() {
return db
Expand Down
128 changes: 110 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading