mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-09 01:16:15 -08:00
feat(pwa): load a m3u playlist as a URL parameter #176
This commit is contained in:
1 parent
b96df78611
commit
344bd75c87
4 files changed
+42
-12
No files matched your search
@@ -29,4 +29,5 @@ export interface Playlist {
|
||||
updateDate?: number;
|
||||
updateState?: PlaylistUpdateState;
|
||||
position?: number;
|
||||
isTemporary?: boolean;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { MatSidenavModule } from '@angular/material/sidenav';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { MockComponent, MockModule, MockPipe } from 'ng-mocks';
|
||||
@@ -47,6 +48,16 @@ describe('VideoPlayerComponent', () => {
|
||||
providers: [
|
||||
{ provide: MatSnackBar, useClass: MatSnackBarStub },
|
||||
{ provide: DataService, useClass: ElectronServiceStub },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
snapshot: {
|
||||
queryParams: {
|
||||
url: 'https://iptvnator/list.m3u',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
imports: [
|
||||
MockModule(MatSidenavModule),
|
||||
|
||||
@@ -11,12 +11,13 @@ import {
|
||||
} from '@angular/core';
|
||||
import { MatSidenav } from '@angular/material/sidenav';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { Router } from '@angular/router';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { StorageMap } from '@ngx-pwa/local-storage';
|
||||
import { filter, map, Observable, skipWhile } from 'rxjs';
|
||||
import { Channel } from '../../../../../shared/channel.interface';
|
||||
import {
|
||||
PLAYLIST_GET_ALL,
|
||||
PLAYLIST_PARSE_BY_URL,
|
||||
PLAYLIST_PARSE_RESPONSE,
|
||||
} from '../../../../../shared/ipc-commands';
|
||||
import { Playlist } from '../../../../../shared/playlist.interface';
|
||||
@@ -114,9 +115,10 @@ export class VideoPlayerComponent implements OnInit, OnDestroy {
|
||||
* Creates an instance of VideoPlayerComponent
|
||||
*/
|
||||
constructor(
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private channelQuery: ChannelQuery,
|
||||
private channelStore: ChannelStore,
|
||||
public dataService: DataService,
|
||||
private dataService: DataService,
|
||||
private ngZone: NgZone,
|
||||
private overlay: Overlay,
|
||||
private router: Router,
|
||||
@@ -132,6 +134,22 @@ export class VideoPlayerComponent implements OnInit, OnDestroy {
|
||||
ngOnInit(): void {
|
||||
this.applySettings();
|
||||
this.setRendererListeners();
|
||||
this.getPlaylistUrlAsParam();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a playlist provided as a url param
|
||||
*/
|
||||
getPlaylistUrlAsParam() {
|
||||
const URL_REGEX = /^(http|https|file):\/\/[^ "]+$/;
|
||||
const playlistUrl = this.activatedRoute.snapshot.queryParams.url;
|
||||
|
||||
if (playlistUrl && playlistUrl.match(URL_REGEX)) {
|
||||
this.dataService.sendIpcEvent(PLAYLIST_PARSE_BY_URL, {
|
||||
url: playlistUrl,
|
||||
isTemporary: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
first,
|
||||
interval,
|
||||
map,
|
||||
of,
|
||||
switchMap,
|
||||
throwError,
|
||||
} from 'rxjs';
|
||||
@@ -86,12 +87,12 @@ export class PwaService extends DataService {
|
||||
everySixHours$
|
||||
);
|
||||
|
||||
everySixHoursOnceAppIsStable$.subscribe(() =>
|
||||
this.swUpdate.checkForUpdate()
|
||||
);
|
||||
everySixHoursOnceAppIsStable$.subscribe(() => {
|
||||
this.swUpdate.checkForUpdate();
|
||||
});
|
||||
|
||||
this.swUpdate.versionUpdates.subscribe(() => {
|
||||
let snackBarRef = this.snackBar.open(
|
||||
const snackBarRef = this.snackBar.open(
|
||||
'Update available',
|
||||
'Refresh'
|
||||
);
|
||||
@@ -341,6 +342,11 @@ export class PwaService extends DataService {
|
||||
this.http
|
||||
.get(`${this.corsProxyUrl}${payload.url}`)
|
||||
.pipe(
|
||||
switchMap((response) =>
|
||||
payload.isTemporary
|
||||
? of(response)
|
||||
: this.dbService.add(DbStores.Playlists, response)
|
||||
),
|
||||
catchError((error) => {
|
||||
window.postMessage({
|
||||
type: ERROR,
|
||||
@@ -351,12 +357,6 @@ export class PwaService extends DataService {
|
||||
})
|
||||
)
|
||||
.subscribe((response: any) => {
|
||||
this.dbService
|
||||
.add(DbStores.Playlists, response)
|
||||
.subscribe(() => {
|
||||
console.log('playlist was added...');
|
||||
});
|
||||
|
||||
window.postMessage({
|
||||
type: PLAYLIST_PARSE_RESPONSE,
|
||||
payload: response,
|
||||
|
||||
Reference in new issue
Block a user