Any now shows all avaliable formats
This commit is contained in:
parent
85140fd4ca
commit
26798a4930
|
|
@ -29,7 +29,7 @@
|
||||||
<span class="input-group-text">Quality</span>
|
<span class="input-group-text">Quality</span>
|
||||||
</div>
|
</div>
|
||||||
<select class="custom-select" name="quality" [(ngModel)]="quality" (change)="qualityChanged()" [disabled]="addInProgress || downloads.loading">
|
<select class="custom-select" name="quality" [(ngModel)]="quality" (change)="qualityChanged()" [disabled]="addInProgress || downloads.loading">
|
||||||
<option *ngFor="let q of qualities" [ngValue]="q.id">{{ q.text }}</option>
|
<option *ngFor="let q of qualities" [ngValue]="q">{{ q.text }}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { CookieService } from 'ngx-cookie-service';
|
||||||
|
|
||||||
import { DownloadsService, Status } from './downloads.service';
|
import { DownloadsService, Status } from './downloads.service';
|
||||||
import { MasterCheckboxComponent } from './master-checkbox.component';
|
import { MasterCheckboxComponent } from './master-checkbox.component';
|
||||||
import { Formats, Format, Quality } from './formats';
|
import { Formats, Format, Quality, fillQualities, getQualityById } from './formats';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
|
|
@ -14,9 +14,9 @@ import { Formats, Format, Quality } from './formats';
|
||||||
})
|
})
|
||||||
export class AppComponent implements AfterViewInit {
|
export class AppComponent implements AfterViewInit {
|
||||||
addUrl: string;
|
addUrl: string;
|
||||||
formats: Format[] = Formats;
|
formats: Format[] = fillQualities(Formats);
|
||||||
qualities: Quality[];
|
qualities: Quality[];
|
||||||
quality: string;
|
quality: Quality;
|
||||||
format: string;
|
format: string;
|
||||||
addInProgress = false;
|
addInProgress = false;
|
||||||
|
|
||||||
|
|
@ -33,10 +33,11 @@ export class AppComponent implements AfterViewInit {
|
||||||
faRedoAlt = faRedoAlt;
|
faRedoAlt = faRedoAlt;
|
||||||
|
|
||||||
constructor(public downloads: DownloadsService, private cookieService: CookieService) {
|
constructor(public downloads: DownloadsService, private cookieService: CookieService) {
|
||||||
this.quality = cookieService.get('metube_quality') || 'best';
|
|
||||||
this.format = cookieService.get('metube_format') || 'any';
|
this.format = cookieService.get('metube_format') || 'any';
|
||||||
// Needs to be set or qualities won't automatically be set
|
// Needs to be set or qualities won't automatically be set
|
||||||
this.setQualities()
|
this.setQualities()
|
||||||
|
let qualityId = cookieService.get('metube_quality') || this.qualities[0].id
|
||||||
|
this.quality = getQualityById(this.formats, qualityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
|
|
@ -64,7 +65,7 @@ export class AppComponent implements AfterViewInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
qualityChanged() {
|
qualityChanged() {
|
||||||
this.cookieService.set('metube_quality', this.quality, { expires: 3650 });
|
this.cookieService.set('metube_quality', this.quality.id, { expires: 3650 });
|
||||||
}
|
}
|
||||||
|
|
||||||
formatChanged() {
|
formatChanged() {
|
||||||
|
|
@ -84,13 +85,13 @@ export class AppComponent implements AfterViewInit {
|
||||||
setQualities() {
|
setQualities() {
|
||||||
// qualities for specific format
|
// qualities for specific format
|
||||||
this.qualities = this.formats.find(el => el.id == this.format).qualities
|
this.qualities = this.formats.find(el => el.id == this.format).qualities
|
||||||
this.quality = "best"
|
this.quality = this.qualities.find(el => el.value === "best")
|
||||||
}
|
}
|
||||||
|
|
||||||
addDownload(url?: string, quality?: string, format?: string) {
|
addDownload(url?: string, quality?: string, format?: string) {
|
||||||
url = url ?? this.addUrl
|
url = url ?? this.addUrl
|
||||||
quality = quality ?? this.quality
|
quality = quality ?? this.quality.value
|
||||||
format = format ?? this.format
|
format = format ?? this.quality.fmt
|
||||||
|
|
||||||
this.addInProgress = true;
|
this.addInProgress = true;
|
||||||
this.downloads.add(url, quality, format).subscribe((status: Status) => {
|
this.downloads.add(url, quality, format).subscribe((status: Status) => {
|
||||||
|
|
|
||||||
|
|
@ -7,33 +7,52 @@ export interface Format {
|
||||||
export interface Quality {
|
export interface Quality {
|
||||||
id: string;
|
id: string;
|
||||||
text: string;
|
text: string;
|
||||||
|
value: string;
|
||||||
|
fmt?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Formats: Format[] = [
|
export const Formats: Format[] = [
|
||||||
{
|
{
|
||||||
id: 'any',
|
id: 'any',
|
||||||
text: 'Any',
|
text: 'Any',
|
||||||
qualities: [{ id: 'best', text: 'Best' }],
|
qualities: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'mp4',
|
id: 'mp4',
|
||||||
text: 'MP4',
|
text: 'MP4',
|
||||||
qualities: [
|
qualities: [
|
||||||
{ id: 'best', text: 'Best' },
|
{ id: "1", value: 'best', text: 'Best MP4' },
|
||||||
{ id: '1440', text: '1440p' },
|
{ id: "2", value: '1440', text: '1440p' },
|
||||||
{ id: '1080', text: '1080p' },
|
{ id: "3", value: '1080', text: '1080p' },
|
||||||
{ id: '720', text: '720p' },
|
{ id: "4", value: '720', text: '720p' },
|
||||||
{ id: '480', text: '480p' },
|
{ id: "5", value: '480', text: '480p' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'mp3',
|
id: 'mp3',
|
||||||
text: 'MP3',
|
text: 'MP3',
|
||||||
qualities: [
|
qualities: [
|
||||||
{ id: 'best', text: 'Best' },
|
{ id: "6", value: 'best', text: 'Best MP3' },
|
||||||
{ id: '128', text: '128 kbps' },
|
{ id: "7", value: '128', text: '128 kbps' },
|
||||||
{ id: '192', text: '192 kbps' },
|
{ id: "8", value: '192', text: '192 kbps' },
|
||||||
{ id: '320', text: '320 kbps' },
|
{ id: "9", value: '320', text: '320 kbps' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const fillQualities = (formats: Format[]): Format[] => {
|
||||||
|
let allQualities: Quality[] = [];
|
||||||
|
formats.forEach((fmt) => {
|
||||||
|
fmt.qualities = fmt.qualities.map((ql) => ({ ...ql, fmt: fmt.id }));
|
||||||
|
allQualities = allQualities.concat(fmt.qualities);
|
||||||
|
});
|
||||||
|
|
||||||
|
formats.find((format) => format.id === 'any').qualities = allQualities;
|
||||||
|
return formats;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getQualityById = (formats: Format[], id: string): Quality => {
|
||||||
|
return formats
|
||||||
|
.find(ql => ql.qualities.find(el => el.id === id)).qualities
|
||||||
|
.find(el => el.id === id)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue