mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
refactor(xtream-tauri): implement player service to manage external player interactions
This commit is contained in:
3 files changed
+85
-87
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { OPEN_MPV_PLAYER, OPEN_VLC_PLAYER } from '../../../shared/ipc-commands';
|
||||
import { VideoPlayer } from '../settings/settings.interface';
|
||||
import { ExternalPlayerInfoDialogComponent } from '../shared/components/external-player-info-dialog/external-player-info-dialog.component';
|
||||
import {
|
||||
PlayerDialogComponent,
|
||||
PlayerDialogData,
|
||||
} from '../xtream-tauri/player-dialog/player-dialog.component';
|
||||
import { DataService } from './data.service';
|
||||
import { SettingsStore } from './settings-store.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PlayerService {
|
||||
private dialog = inject(MatDialog);
|
||||
private dataService = inject(DataService);
|
||||
private settingsStore = inject(SettingsStore);
|
||||
private settings = this.settingsStore.getSettings();
|
||||
|
||||
openPlayer(
|
||||
streamUrl: string,
|
||||
title: string,
|
||||
thumbnail?: string,
|
||||
hideExternalInfoDialog = false,
|
||||
isLiveContent = false
|
||||
) {
|
||||
const player = this.settings()?.player ?? VideoPlayer.VideoJs;
|
||||
|
||||
if (player === VideoPlayer.MPV) {
|
||||
if (!hideExternalInfoDialog) {
|
||||
this.dialog.open(ExternalPlayerInfoDialogComponent);
|
||||
}
|
||||
this.dataService.sendIpcEvent(OPEN_MPV_PLAYER, {
|
||||
url: streamUrl,
|
||||
mpvPlayerPath: this.settings()?.mpvPlayerPath,
|
||||
title,
|
||||
thumbnail,
|
||||
});
|
||||
} else if (player === VideoPlayer.VLC) {
|
||||
if (!hideExternalInfoDialog) {
|
||||
this.dialog.open(ExternalPlayerInfoDialogComponent);
|
||||
}
|
||||
this.dataService.sendIpcEvent(OPEN_VLC_PLAYER, {
|
||||
url: streamUrl,
|
||||
vlcPlayerPath: this.settings()?.vlcPlayerPath,
|
||||
});
|
||||
} else if (!isLiveContent) {
|
||||
this.dialog.open<PlayerDialogComponent, PlayerDialogData>(
|
||||
PlayerDialogComponent,
|
||||
{
|
||||
data: { streamUrl, title },
|
||||
width: '80%',
|
||||
maxWidth: '1200px',
|
||||
maxHeight: '90vh',
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,23 +6,14 @@ import { MatIcon } from '@angular/material/icon';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import {
|
||||
OPEN_MPV_PLAYER,
|
||||
OPEN_VLC_PLAYER,
|
||||
} from '../../../../shared/ipc-commands';
|
||||
import { XtreamSerieEpisode } from '../../../../shared/xtream-serie-details.interface';
|
||||
import { DataService } from '../../services/data.service';
|
||||
import { PlayerService } from '../../services/player.service';
|
||||
import { SettingsStore } from '../../services/settings-store.service';
|
||||
import { VideoPlayer } from '../../settings/settings.interface';
|
||||
import { ExternalPlayerInfoDialogComponent } from '../../shared/components/external-player-info-dialog/external-player-info-dialog.component';
|
||||
import {
|
||||
selectActivePlaylist,
|
||||
selectCurrentPlaylist,
|
||||
} from '../../state/selectors';
|
||||
import {
|
||||
PlayerDialogComponent,
|
||||
PlayerDialogData,
|
||||
} from '../player-dialog/player-dialog.component';
|
||||
import { SeasonContainerComponent } from '../season-container/season-container.component';
|
||||
import { XtreamStore } from '../xtream.store';
|
||||
|
||||
@@ -47,6 +38,7 @@ export class SerialDetailsComponent {
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly xtreamStore = inject(XtreamStore);
|
||||
private readonly settingsStore = inject(SettingsStore);
|
||||
private playerService = inject(PlayerService);
|
||||
|
||||
readonly selectedItem = this.xtreamStore.selectedItem;
|
||||
readonly settings = this.settingsStore.getSettings();
|
||||
@@ -78,36 +70,13 @@ export class SerialDetailsComponent {
|
||||
}
|
||||
|
||||
openPlayer(streamUrl: string, title: string) {
|
||||
const player = this.settings()?.player ?? VideoPlayer.VideoJs;
|
||||
if (player === VideoPlayer.MPV) {
|
||||
if (!this.hideExternalInfoDialog())
|
||||
this.dialog.open(ExternalPlayerInfoDialogComponent);
|
||||
this.dataService.sendIpcEvent(OPEN_MPV_PLAYER, {
|
||||
url: streamUrl,
|
||||
mpvPlayerPath: this.settings()?.mpvPlayerPath,
|
||||
title: this.xtreamStore.selectedItem().info.name,
|
||||
thumbnail: this.xtreamStore.selectedItem().info.cover,
|
||||
});
|
||||
} else if (player === VideoPlayer.VLC) {
|
||||
if (!this.hideExternalInfoDialog())
|
||||
this.dialog.open(ExternalPlayerInfoDialogComponent);
|
||||
this.dataService.sendIpcEvent(OPEN_VLC_PLAYER, {
|
||||
url: streamUrl,
|
||||
vlcPlayerPath: this.settings()?.vlcPlayerPath,
|
||||
});
|
||||
} else {
|
||||
if (this.selectedContentType() !== 'live') {
|
||||
this.dialog.open<PlayerDialogComponent, PlayerDialogData>(
|
||||
PlayerDialogComponent,
|
||||
{
|
||||
data: { streamUrl, title },
|
||||
width: '80%',
|
||||
maxWidth: '1200px',
|
||||
maxHeight: '90vh',
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
this.playerService.openPlayer(
|
||||
streamUrl,
|
||||
title,
|
||||
this.xtreamStore.selectedItem().info.cover,
|
||||
this.hideExternalInfoDialog(),
|
||||
this.selectedContentType() === 'live'
|
||||
);
|
||||
}
|
||||
|
||||
private addToRecentlyViewed(xtreamId: number) {
|
||||
|
||||
@@ -6,20 +6,11 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import {
|
||||
OPEN_MPV_PLAYER,
|
||||
OPEN_VLC_PLAYER,
|
||||
} from '../../../../shared/ipc-commands';
|
||||
import { XtreamVodDetails } from '../../../../shared/xtream-vod-details.interface';
|
||||
import { DataService } from '../../services/data.service';
|
||||
import { PlayerService } from '../../services/player.service';
|
||||
import { SettingsStore } from '../../services/settings-store.service';
|
||||
import { VideoPlayer } from '../../settings/settings.interface';
|
||||
import { ExternalPlayerInfoDialogComponent } from '../../shared/components/external-player-info-dialog/external-player-info-dialog.component';
|
||||
import { selectActivePlaylist } from '../../state/selectors';
|
||||
import {
|
||||
PlayerDialogComponent,
|
||||
PlayerDialogData,
|
||||
} from '../player-dialog/player-dialog.component';
|
||||
import { XtreamStore } from '../xtream.store';
|
||||
import { SafePipe } from './safe.pipe';
|
||||
|
||||
@@ -42,10 +33,12 @@ export class VodDetailsComponent implements OnInit, OnDestroy {
|
||||
private route = inject(ActivatedRoute);
|
||||
private store = inject(Store);
|
||||
private readonly xtreamStore = inject(XtreamStore);
|
||||
private playerService = inject(PlayerService);
|
||||
|
||||
readonly settings = this.settingsStore.getSettings();
|
||||
readonly selectedContentType = this.xtreamStore.selectedContentType();
|
||||
readonly hideExternalInfoDialog = this.xtreamStore.hideExternalInfoDialog;
|
||||
private readonly selectedContentType = this.xtreamStore.selectedContentType;
|
||||
private readonly hideExternalInfoDialog =
|
||||
this.xtreamStore.hideExternalInfoDialog;
|
||||
|
||||
readonly isFavorite = this.xtreamStore.isFavorite;
|
||||
readonly selectedItem = this.xtreamStore.selectedItem;
|
||||
@@ -64,7 +57,7 @@ export class VodDetailsComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
playVod(vodItem: XtreamVodDetails) {
|
||||
this.addToRecentlyViewed(vodItem);
|
||||
this.addToRecentlyViewed();
|
||||
const currentPlaylist = this.store.selectSignal(selectActivePlaylist);
|
||||
const { serverUrl, username, password } = currentPlaylist();
|
||||
const streamUrl = `${serverUrl}/movie/${username}/${password}/${vodItem.movie_data.stream_id}.${vodItem.movie_data.container_extension}`;
|
||||
@@ -77,47 +70,22 @@ export class VodDetailsComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
openPlayer(streamUrl: string, title: string, thumbnail: string) {
|
||||
const player = this.settings()?.player ?? VideoPlayer.VideoJs;
|
||||
if (player === VideoPlayer.MPV) {
|
||||
if (!this.hideExternalInfoDialog())
|
||||
this.dialog.open(ExternalPlayerInfoDialogComponent);
|
||||
this.dataService.sendIpcEvent(OPEN_MPV_PLAYER, {
|
||||
url: streamUrl,
|
||||
mpvPlayerPath: this.settings()?.mpvPlayerPath,
|
||||
title,
|
||||
thumbnail,
|
||||
});
|
||||
} else if (player === VideoPlayer.VLC) {
|
||||
if (!this.hideExternalInfoDialog())
|
||||
this.dialog.open(ExternalPlayerInfoDialogComponent);
|
||||
this.dataService.sendIpcEvent(OPEN_VLC_PLAYER, {
|
||||
url: streamUrl,
|
||||
vlcPlayerPath: this.settings()?.vlcPlayerPath,
|
||||
});
|
||||
} else {
|
||||
if (this.selectedContentType !== 'live') {
|
||||
this.dialog.open<PlayerDialogComponent, PlayerDialogData>(
|
||||
PlayerDialogComponent,
|
||||
{
|
||||
data: { streamUrl, title },
|
||||
width: '80%',
|
||||
maxWidth: '1200px',
|
||||
maxHeight: '90vh',
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
this.playerService.openPlayer(
|
||||
streamUrl,
|
||||
title,
|
||||
thumbnail,
|
||||
this.hideExternalInfoDialog(),
|
||||
this.selectedContentType() === 'live'
|
||||
);
|
||||
}
|
||||
|
||||
toggleFavorite() {
|
||||
this.xtreamStore.toggleFavorite();
|
||||
}
|
||||
|
||||
private addToRecentlyViewed(vodItem: any) {
|
||||
private addToRecentlyViewed() {
|
||||
this.xtreamStore.addRecentItem({
|
||||
contentId:
|
||||
this.route.snapshot.params
|
||||
.vodId /* vodItem.movie_data.stream_id */,
|
||||
contentId: this.route.snapshot.params.vodId,
|
||||
playlist: this.xtreamStore.currentPlaylist,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user