mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-16 21:31:28 +03:00
cleaned up some code
youtube-dl commands are now simulated and displayed in the advanced panel
This commit is contained in:
@@ -69,6 +69,7 @@
|
|||||||
Advanced
|
Advanced
|
||||||
</mat-panel-title>
|
</mat-panel-title>
|
||||||
</mat-expansion-panel-header>
|
</mat-expansion-panel-header>
|
||||||
|
<p *ngIf="this.simulatedOutput">Simulated command: <i>{{this.simulatedOutput}}</i></p>
|
||||||
<div class="container" style="padding-bottom: 20px;">
|
<div class="container" style="padding-bottom: 20px;">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 col-sm-6">
|
<div class="col-12 col-sm-6">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit, ElementRef, ViewChild, ViewChildren, QueryList, isDevMode } from '@angular/core';
|
import { Component, OnInit, ElementRef, ViewChild, ViewChildren, QueryList } from '@angular/core';
|
||||||
import {PostsService} from '../posts.services';
|
import {PostsService} from '../posts.services';
|
||||||
import {FileCardComponent} from '../file-card/file-card.component';
|
import {FileCardComponent} from '../file-card/file-card.component';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
@@ -45,6 +45,7 @@ export class MainComponent implements OnInit {
|
|||||||
|
|
||||||
iOS = false;
|
iOS = false;
|
||||||
|
|
||||||
|
// local settings
|
||||||
determinateProgress = false;
|
determinateProgress = false;
|
||||||
downloadingfile = false;
|
downloadingfile = false;
|
||||||
audioOnly: boolean;
|
audioOnly: boolean;
|
||||||
@@ -63,15 +64,19 @@ export class MainComponent implements OnInit {
|
|||||||
percentDownloaded: number;
|
percentDownloaded: number;
|
||||||
autoStartDownload = false;
|
autoStartDownload = false;
|
||||||
|
|
||||||
// settings
|
// global settings
|
||||||
fileManagerEnabled = false;
|
fileManagerEnabled = false;
|
||||||
allowQualitySelect = false;
|
allowQualitySelect = false;
|
||||||
downloadOnlyMode = false;
|
downloadOnlyMode = false;
|
||||||
allowMultiDownloadMode = false;
|
allowMultiDownloadMode = false;
|
||||||
audioFolderPath;
|
audioFolderPath;
|
||||||
videoFolderPath;
|
videoFolderPath;
|
||||||
|
globalCustomArgs = null;
|
||||||
allowAdvancedDownload = false;
|
allowAdvancedDownload = false;
|
||||||
|
useDefaultDownloadingAgent = true;
|
||||||
|
customDownloadingAgent = null;
|
||||||
|
|
||||||
|
// formats cache
|
||||||
cachedAvailableFormats = {};
|
cachedAvailableFormats = {};
|
||||||
|
|
||||||
// youtube api
|
// youtube api
|
||||||
@@ -202,6 +207,8 @@ export class MainComponent implements OnInit {
|
|||||||
is_playlist: false
|
is_playlist: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
simulatedOutput = '';
|
||||||
|
|
||||||
constructor(private postsService: PostsService, private youtubeSearch: YoutubeSearchService, public snackBar: MatSnackBar,
|
constructor(private postsService: PostsService, private youtubeSearch: YoutubeSearchService, public snackBar: MatSnackBar,
|
||||||
private router: Router, public dialog: MatDialog, private platform: Platform, private route: ActivatedRoute) {
|
private router: Router, public dialog: MatDialog, private platform: Platform, private route: ActivatedRoute) {
|
||||||
this.audioOnly = false;
|
this.audioOnly = false;
|
||||||
@@ -214,11 +221,15 @@ export class MainComponent implements OnInit {
|
|||||||
this.allowMultiDownloadMode = result['YoutubeDLMaterial']['Extra']['allow_multi_download_mode'];
|
this.allowMultiDownloadMode = result['YoutubeDLMaterial']['Extra']['allow_multi_download_mode'];
|
||||||
this.audioFolderPath = result['YoutubeDLMaterial']['Downloader']['path-audio'];
|
this.audioFolderPath = result['YoutubeDLMaterial']['Downloader']['path-audio'];
|
||||||
this.videoFolderPath = result['YoutubeDLMaterial']['Downloader']['path-video'];
|
this.videoFolderPath = result['YoutubeDLMaterial']['Downloader']['path-video'];
|
||||||
|
this.globalCustomArgs = result['YoutubeDLMaterial']['Downloader']['custom_args'];
|
||||||
this.youtubeSearchEnabled = result['YoutubeDLMaterial']['API'] && result['YoutubeDLMaterial']['API']['use_youtube_API'] &&
|
this.youtubeSearchEnabled = result['YoutubeDLMaterial']['API'] && result['YoutubeDLMaterial']['API']['use_youtube_API'] &&
|
||||||
result['YoutubeDLMaterial']['API']['youtube_API_key'];
|
result['YoutubeDLMaterial']['API']['youtube_API_key'];
|
||||||
this.youtubeAPIKey = this.youtubeSearchEnabled ? result['YoutubeDLMaterial']['API']['youtube_API_key'] : null;
|
this.youtubeAPIKey = this.youtubeSearchEnabled ? result['YoutubeDLMaterial']['API']['youtube_API_key'] : null;
|
||||||
this.allowQualitySelect = result['YoutubeDLMaterial']['Extra']['allow_quality_select'];
|
this.allowQualitySelect = result['YoutubeDLMaterial']['Extra']['allow_quality_select'];
|
||||||
this.allowAdvancedDownload = result['YoutubeDLMaterial']['Advanced']['allow_advanced_download'];
|
this.allowAdvancedDownload = result['YoutubeDLMaterial']['Advanced']['allow_advanced_download'];
|
||||||
|
this.useDefaultDownloadingAgent = result['YoutubeDLMaterial']['Advanced']['use_default_downloading_agent'];
|
||||||
|
this.customDownloadingAgent = result['YoutubeDLMaterial']['Advanced']['custom_downloading_agent'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (this.fileManagerEnabled) {
|
if (this.fileManagerEnabled) {
|
||||||
@@ -259,6 +270,8 @@ export class MainComponent implements OnInit {
|
|||||||
this.downloadClicked();
|
this.downloadClicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setInterval(() => this.getSimulatedOutput(), 1000);
|
||||||
|
|
||||||
}, error => {
|
}, error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
@@ -547,11 +560,7 @@ export class MainComponent implements OnInit {
|
|||||||
|
|
||||||
let customQualityConfiguration = null;
|
let customQualityConfiguration = null;
|
||||||
if (this.selectedQuality !== '') {
|
if (this.selectedQuality !== '') {
|
||||||
const cachedFormatsExists = this.cachedAvailableFormats[this.url] && this.cachedAvailableFormats[this.url]['formats'];
|
customQualityConfiguration = this.getSelectedAudioFormat();
|
||||||
if (cachedFormatsExists) {
|
|
||||||
const audio_formats = this.cachedAvailableFormats[this.url]['formats']['audio'];
|
|
||||||
customQualityConfiguration = audio_formats[this.selectedQuality]['format_id'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.postsService.makeMP3(this.url, (this.selectedQuality === '' ? null : this.selectedQuality),
|
this.postsService.makeMP3(this.url, (this.selectedQuality === '' ? null : this.selectedQuality),
|
||||||
@@ -584,14 +593,7 @@ export class MainComponent implements OnInit {
|
|||||||
if (!this.current_download && !this.multiDownloadMode) { this.current_download = new_download };
|
if (!this.current_download && !this.multiDownloadMode) { this.current_download = new_download };
|
||||||
this.downloadingfile = true;
|
this.downloadingfile = true;
|
||||||
|
|
||||||
let customQualityConfiguration = null;
|
const customQualityConfiguration = this.getSelectedVideoFormat();
|
||||||
const cachedFormatsExists = this.cachedAvailableFormats[this.url] && this.cachedAvailableFormats[this.url]['formats'];
|
|
||||||
if (cachedFormatsExists) {
|
|
||||||
const video_formats = this.cachedAvailableFormats[this.url]['formats']['video'];
|
|
||||||
if (video_formats['best_audio_format'] && this.selectedQuality !== '') {
|
|
||||||
customQualityConfiguration = video_formats[this.selectedQuality]['format_id'] + '+' + video_formats['best_audio_format'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.postsService.makeMP4(this.url, (this.selectedQuality === '' ? null : this.selectedQuality),
|
this.postsService.makeMP4(this.url, (this.selectedQuality === '' ? null : this.selectedQuality),
|
||||||
customQualityConfiguration, customArgs, customOutput, youtubeUsername, youtubePassword).subscribe(posts => {
|
customQualityConfiguration, customArgs, customOutput, youtubeUsername, youtubePassword).subscribe(posts => {
|
||||||
@@ -632,6 +634,29 @@ export class MainComponent implements OnInit {
|
|||||||
this.current_download = null;
|
this.current_download = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSelectedAudioFormat() {
|
||||||
|
if (this.selectedQuality === '') { return null };
|
||||||
|
const cachedFormatsExists = this.cachedAvailableFormats[this.url] && this.cachedAvailableFormats[this.url]['formats'];
|
||||||
|
if (cachedFormatsExists) {
|
||||||
|
const audio_formats = this.cachedAvailableFormats[this.url]['formats']['audio'];
|
||||||
|
return audio_formats[this.selectedQuality]['format_id'];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getSelectedVideoFormat() {
|
||||||
|
if (this.selectedQuality === '') { return null };
|
||||||
|
const cachedFormatsExists = this.cachedAvailableFormats[this.url] && this.cachedAvailableFormats[this.url]['formats'];
|
||||||
|
if (cachedFormatsExists) {
|
||||||
|
const video_formats = this.cachedAvailableFormats[this.url]['formats']['video'];
|
||||||
|
if (video_formats['best_audio_format'] && this.selectedQuality !== '') {
|
||||||
|
return video_formats[this.selectedQuality]['format_id'] + '+' + video_formats['best_audio_format'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
getDownloadByUID(uid) {
|
getDownloadByUID(uid) {
|
||||||
const index = this.downloads.findIndex(download => download.uid === uid);
|
const index = this.downloads.findIndex(download => download.uid === uid);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
@@ -774,6 +799,72 @@ export class MainComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSimulatedOutput() {
|
||||||
|
const customArgsExists = this.customArgsEnabled && this.customArgs;
|
||||||
|
|
||||||
|
const full_string_array: string[] = [];
|
||||||
|
const base_string_array = ['youtube-dl', this.url];
|
||||||
|
|
||||||
|
if (customArgsExists) {
|
||||||
|
this.simulatedOutput = base_string_array.join(' ') + ' ' + this.customArgs;
|
||||||
|
return this.simulatedOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
full_string_array.push(...base_string_array);
|
||||||
|
|
||||||
|
const base_path = this.audioOnly ? this.audioFolderPath : this.videoFolderPath;
|
||||||
|
const ext = this.audioOnly ? '.mp3' : '.mp4';
|
||||||
|
// gets output
|
||||||
|
let output_string_array = ['-o', base_path + '%(title)s' + ext];
|
||||||
|
if (this.customOutputEnabled && this.customOutput) {
|
||||||
|
output_string_array = ['-o', this.customOutput + ext];
|
||||||
|
}
|
||||||
|
// before pushing output, should check if using an external downloader
|
||||||
|
if (!this.useDefaultDownloadingAgent && this.customDownloadingAgent === 'aria2c') {
|
||||||
|
full_string_array.push('--external-downloader', 'aria2c');
|
||||||
|
}
|
||||||
|
// pushes output
|
||||||
|
full_string_array.push(...output_string_array);
|
||||||
|
|
||||||
|
// logic splits into audio and video modes
|
||||||
|
if (this.audioOnly) {
|
||||||
|
// adds base audio string
|
||||||
|
const format_array = [];
|
||||||
|
const audio_format = this.getSelectedAudioFormat();
|
||||||
|
if (audio_format) {
|
||||||
|
format_array.push('-f', audio_format);
|
||||||
|
} else if (this.selectedQuality) {
|
||||||
|
format_array.push('--audio-quality', this.selectedQuality);
|
||||||
|
}
|
||||||
|
|
||||||
|
// pushes formats
|
||||||
|
full_string_array.splice(2, 0, ...format_array);
|
||||||
|
|
||||||
|
const additional_params = ['-x', '--audio-format', 'mp3', '--write-info-json', '--print-json'];
|
||||||
|
|
||||||
|
full_string_array.push(...additional_params);
|
||||||
|
} else {
|
||||||
|
// adds base video string
|
||||||
|
let format_array = ['-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4'];
|
||||||
|
const video_format = this.getSelectedVideoFormat();
|
||||||
|
if (video_format) {
|
||||||
|
format_array = ['-f', video_format];
|
||||||
|
} else if (this.selectedQuality) {
|
||||||
|
format_array = [`bestvideo[height=${this.selectedQuality}]+bestaudio/best[height=${this.selectedQuality}]`];
|
||||||
|
}
|
||||||
|
|
||||||
|
// pushes formats
|
||||||
|
full_string_array.splice(2, 0, ...format_array);
|
||||||
|
|
||||||
|
const additional_params = ['--write-info-json', '--print-json'];
|
||||||
|
|
||||||
|
full_string_array.push(...additional_params);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.simulatedOutput = full_string_array.join(' ');
|
||||||
|
return this.simulatedOutput;
|
||||||
|
}
|
||||||
|
|
||||||
errorFormats(url) {
|
errorFormats(url) {
|
||||||
this.cachedAvailableFormats[url]['formats_loading'] = false;
|
this.cachedAvailableFormats[url]['formats_loading'] = false;
|
||||||
console.error('Could not load formats for url ' + url);
|
console.error('Could not load formats for url ' + url);
|
||||||
|
|||||||
Reference in New Issue
Block a user