Skip to content

Commit

Permalink
add global mpvParams
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredolx committed Nov 22, 2023
1 parent 1950241 commit 9f12c5f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 3 additions & 1 deletion electron-open-tv/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ async function fetchSettings() {
function applyDefaultSettings() {
if (settings.useStreamCaching === undefined)
settings.useStreamCaching = true;
if (settings.mpvParams === undefined)
settings.mpvParams = "--fs"
}

async function saveToCache(data) {
Expand Down Expand Up @@ -372,7 +374,7 @@ function clearMpvProcesses() {

async function playChannel(url, record) {
clearMpvProcesses();
let command = `${mpvPath} ${url} --fs`
let command = `${mpvPath} ${url} ${settings.mpvParams}`
if (URLIsNotLivestream(url))
command += " --save-position-on-quit";
else
Expand Down
1 change: 1 addition & 0 deletions ng-open-tv/src/app/models/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class Settings {
recordingPath?: string;
useStreamCaching?: boolean;
mpvParams?: string;
}
11 changes: 10 additions & 1 deletion ng-open-tv/src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h2 class="mt-4 mb-4 text-center">Settings</h2>
<div class="row align-items-center">
<div class="col-4">
<label>Recording path</label>
<label [ngbTooltip]="'Where recorded livestreams will be saved'">Recording path</label>
</div>
<div class="col">
<div class="d-flex align-items-center">
Expand All @@ -16,6 +16,15 @@ <h2 class="mt-4 mb-4 text-center">Settings</h2>
</div>
</div>

<div class="row mt-3 align-items-center">
<div class="col-4">
<span [ngbTooltip]="'Launch parameters applied to all channels. Leave as-is if you don\'t know what this is'">Global MPV Parameters</span>
</div>
<div class="col col-lg-6 col-md-8">
<textarea #mpvParams id="mpvParams" [(ngModel)]="this.memory.Settings.mpvParams" placeholder="mpv params like: --hwdec auto. Don't touch this unless you know what you're doing!" class="form-control"></textarea>
</div>
</div>

<div class="row mt-3 align-items-center">
<div class="col-4">
<span [ngbTooltip]="'Depending on your provider/internet connection, using no caching would give you a lower latency and a more stable experience'">Use stream caching</span>
Expand Down
29 changes: 26 additions & 3 deletions ng-open-tv/src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Component, OnInit } from '@angular/core';
import { AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { NgbActiveModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { ToastrService } from 'ngx-toastr';
import { MemoryService } from '../memory.service';
import { Settings } from '../models/settings';
import { Subscription, debounceTime, distinctUntilChanged, fromEvent, map } from 'rxjs';

@Component({
selector: 'app-settings',
templateUrl: './settings.component.html',
styleUrls: ['./settings.component.scss']
})
export class SettingsComponent {
export class SettingsComponent implements AfterViewInit, OnDestroy {
loading = false;
electron: any = (window as any).electronAPI;
subscriptions: Subscription[] = [];
@ViewChild('mpvParams') mpvParams!: ElementRef;

constructor(private router: Router, public memory: MemoryService, private toastr: ToastrService) { }

Expand All @@ -23,6 +26,19 @@ export class SettingsComponent {
});
}

ngAfterViewInit(): void {
this.subscriptions.push(
fromEvent(this.mpvParams.nativeElement, 'keyup').pipe(
map((event: any) => {
return event.target.value;
})
, debounceTime(500)
, distinctUntilChanged()
).subscribe(async () => {
await this.updateSettings();
}));
}

async refresh() {
this.loading = true;
let result = this.memory.Xtream?.url?.trim() ? (await this.memory.GetXtream()) : (await this.memory.DownloadM3U());
Expand Down Expand Up @@ -51,15 +67,22 @@ export class SettingsComponent {
await this.updateSettings();
}

goBack() {
async goBack() {
await this.updateSettings();
this.router.navigateByUrl("");
}

async updateSettings() {
if (this.memory.Settings.mpvParams)
this.memory.Settings.mpvParams = this.memory.Settings.mpvParams?.trim();
await this.electron.updateSettings(this.memory.Settings);
}

canRefresh(): boolean {
return this.memory.Url?.trim() || this.memory.Xtream?.url?.trim() ? true : false;
}

ngOnDestroy(): void {
this.subscriptions.forEach(x => x.unsubscribe());
}
}

0 comments on commit 9f12c5f

Please sign in to comment.