mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-17 10:11:29 +03:00
Settings are now more centralized in the frontend
This commit is contained in:
@@ -62,8 +62,7 @@ export class AppComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.loadConfig();
|
this.postsService.config_reloaded.subscribe(changed => {
|
||||||
this.postsService.settings_changed.subscribe(changed => {
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
this.loadConfig();
|
this.loadConfig();
|
||||||
}
|
}
|
||||||
@@ -77,22 +76,17 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
loadConfig() {
|
loadConfig() {
|
||||||
// loading config
|
// loading config
|
||||||
this.postsService.loadNavItems().subscribe(res => { // loads settings
|
this.topBarTitle = this.postsService.config['Extra']['title_top'];
|
||||||
const result = !this.postsService.debugMode ? res['config_file'] : res;
|
this.settingsPinRequired = this.postsService.config['Extra']['settings_pin_required'];
|
||||||
this.topBarTitle = result['YoutubeDLMaterial']['Extra']['title_top'];
|
const themingExists = this.postsService.config['Themes'];
|
||||||
this.settingsPinRequired = result['YoutubeDLMaterial']['Extra']['settings_pin_required'];
|
this.defaultTheme = themingExists ? this.postsService.config['Themes']['default_theme'] : 'default';
|
||||||
const themingExists = result['YoutubeDLMaterial']['Themes'];
|
this.allowThemeChange = themingExists ? this.postsService.config['Themes']['allow_theme_change'] : true;
|
||||||
this.defaultTheme = themingExists ? result['YoutubeDLMaterial']['Themes']['default_theme'] : 'default';
|
this.allowSubscriptions = this.postsService.config['Subscriptions']['allow_subscriptions'];
|
||||||
this.allowThemeChange = themingExists ? result['YoutubeDLMaterial']['Themes']['allow_theme_change'] : true;
|
|
||||||
this.allowSubscriptions = result['YoutubeDLMaterial']['Subscriptions']['allow_subscriptions'];
|
|
||||||
|
|
||||||
// sets theme to config default if it doesn't exist
|
// sets theme to config default if it doesn't exist
|
||||||
if (!localStorage.getItem('theme')) {
|
if (!localStorage.getItem('theme')) {
|
||||||
this.setTheme(themingExists ? this.defaultTheme : 'default');
|
this.setTheme(themingExists ? this.defaultTheme : 'default');
|
||||||
}
|
}
|
||||||
}, error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// theme stuff
|
// theme stuff
|
||||||
|
|||||||
@@ -231,80 +231,72 @@ export class MainComponent implements OnInit {
|
|||||||
|
|
||||||
async loadConfig() {
|
async loadConfig() {
|
||||||
// loading config
|
// loading config
|
||||||
this.postsService.loadNavItems().subscribe(res => { // loads settings
|
this.fileManagerEnabled = this.postsService.config['Extra']['file_manager_enabled'];
|
||||||
const result = !this.postsService.debugMode ? res['config_file'] : res;
|
this.downloadOnlyMode = this.postsService.config['Extra']['download_only_mode'];
|
||||||
this.fileManagerEnabled = result['YoutubeDLMaterial']['Extra']['file_manager_enabled'];
|
this.allowMultiDownloadMode = this.postsService.config['Extra']['allow_multi_download_mode'];
|
||||||
this.downloadOnlyMode = result['YoutubeDLMaterial']['Extra']['download_only_mode'];
|
this.audioFolderPath = this.postsService.config['Downloader']['path-audio'];
|
||||||
this.allowMultiDownloadMode = result['YoutubeDLMaterial']['Extra']['allow_multi_download_mode'];
|
this.videoFolderPath = this.postsService.config['Downloader']['path-video'];
|
||||||
this.audioFolderPath = result['YoutubeDLMaterial']['Downloader']['path-audio'];
|
this.use_youtubedl_archive = this.postsService.config['Downloader']['use_youtubedl_archive'];
|
||||||
this.videoFolderPath = result['YoutubeDLMaterial']['Downloader']['path-video'];
|
this.globalCustomArgs = this.postsService.config['Downloader']['custom_args'];
|
||||||
this.use_youtubedl_archive = result['YoutubeDLMaterial']['Downloader']['use_youtubedl_archive'];
|
this.youtubeSearchEnabled = this.postsService.config['API'] && this.postsService.config['API']['use_youtube_API'] &&
|
||||||
this.globalCustomArgs = result['YoutubeDLMaterial']['Downloader']['custom_args'];
|
this.postsService.config['API']['youtube_API_key'];
|
||||||
this.youtubeSearchEnabled = result['YoutubeDLMaterial']['API'] && result['YoutubeDLMaterial']['API']['use_youtube_API'] &&
|
this.youtubeAPIKey = this.youtubeSearchEnabled ? this.postsService.config['API']['youtube_API_key'] : null;
|
||||||
result['YoutubeDLMaterial']['API']['youtube_API_key'];
|
this.allowQualitySelect = this.postsService.config['Extra']['allow_quality_select'];
|
||||||
this.youtubeAPIKey = this.youtubeSearchEnabled ? result['YoutubeDLMaterial']['API']['youtube_API_key'] : null;
|
this.allowAdvancedDownload = this.postsService.config['Advanced']['allow_advanced_download'];
|
||||||
this.allowQualitySelect = result['YoutubeDLMaterial']['Extra']['allow_quality_select'];
|
this.useDefaultDownloadingAgent = this.postsService.config['Advanced']['use_default_downloading_agent'];
|
||||||
this.allowAdvancedDownload = result['YoutubeDLMaterial']['Advanced']['allow_advanced_download'];
|
this.customDownloadingAgent = this.postsService.config['Advanced']['custom_downloading_agent'];
|
||||||
this.useDefaultDownloadingAgent = result['YoutubeDLMaterial']['Advanced']['use_default_downloading_agent'];
|
|
||||||
this.customDownloadingAgent = result['YoutubeDLMaterial']['Advanced']['custom_downloading_agent'];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (this.fileManagerEnabled) {
|
if (this.fileManagerEnabled) {
|
||||||
this.getMp3s();
|
this.getMp3s();
|
||||||
this.getMp4s();
|
this.getMp4s();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.youtubeSearchEnabled && this.youtubeAPIKey) {
|
||||||
|
this.youtubeSearch.initializeAPI(this.youtubeAPIKey);
|
||||||
|
this.attachToInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
// set final cache items
|
||||||
|
if (this.allowAdvancedDownload) {
|
||||||
|
if (localStorage.getItem('customArgsEnabled') !== null) {
|
||||||
|
this.customArgsEnabled = localStorage.getItem('customArgsEnabled') === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.youtubeSearchEnabled && this.youtubeAPIKey) {
|
if (localStorage.getItem('customOutputEnabled') !== null) {
|
||||||
this.youtubeSearch.initializeAPI(this.youtubeAPIKey);
|
this.customOutputEnabled = localStorage.getItem('customOutputEnabled') === 'true';
|
||||||
this.attachToInput();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set final cache items
|
if (localStorage.getItem('youtubeAuthEnabled') !== null) {
|
||||||
if (this.allowAdvancedDownload) {
|
this.youtubeAuthEnabled = localStorage.getItem('youtubeAuthEnabled') === 'true';
|
||||||
if (localStorage.getItem('customArgsEnabled') !== null) {
|
|
||||||
this.customArgsEnabled = localStorage.getItem('customArgsEnabled') === 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (localStorage.getItem('customOutputEnabled') !== null) {
|
|
||||||
this.customOutputEnabled = localStorage.getItem('customOutputEnabled') === 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (localStorage.getItem('youtubeAuthEnabled') !== null) {
|
|
||||||
this.youtubeAuthEnabled = localStorage.getItem('youtubeAuthEnabled') === 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
// set advanced inputs
|
|
||||||
const customArgs = localStorage.getItem('customArgs');
|
|
||||||
const customOutput = localStorage.getItem('customOutput');
|
|
||||||
const youtubeUsername = localStorage.getItem('youtubeUsername');
|
|
||||||
|
|
||||||
if (customArgs && customArgs !== 'null') { this.customArgs = customArgs };
|
|
||||||
if (customOutput && customOutput !== 'null') { this.customOutput = customOutput };
|
|
||||||
if (youtubeUsername && youtubeUsername !== 'null') { this.youtubeUsername = youtubeUsername };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get downloads routine
|
// set advanced inputs
|
||||||
setInterval(() => {
|
const customArgs = localStorage.getItem('customArgs');
|
||||||
if (this.current_download) {
|
const customOutput = localStorage.getItem('customOutput');
|
||||||
this.getCurrentDownload();
|
const youtubeUsername = localStorage.getItem('youtubeUsername');
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
return true;
|
if (customArgs && customArgs !== 'null') { this.customArgs = customArgs };
|
||||||
|
if (customOutput && customOutput !== 'null') { this.customOutput = customOutput };
|
||||||
|
if (youtubeUsername && youtubeUsername !== 'null') { this.youtubeUsername = youtubeUsername };
|
||||||
|
}
|
||||||
|
|
||||||
}, error => {
|
// get downloads routine
|
||||||
console.log(error);
|
setInterval(() => {
|
||||||
|
if (this.current_download) {
|
||||||
|
this.getCurrentDownload();
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// app initialization.
|
// app initialization.
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.configLoad();
|
this.configLoad();
|
||||||
|
|
||||||
this.postsService.settings_changed.subscribe(changed => {
|
this.postsService.config_reloaded.subscribe(changed => {
|
||||||
if (changed) {
|
if (changed) {
|
||||||
this.loadConfig();
|
this.loadConfig();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ export class PostsService implements CanActivate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.reload_config.subscribe(yes_reload => {
|
||||||
|
if (yes_reload) { this.reloadConfig(); }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
canActivate(route, state): Promise<boolean> {
|
canActivate(route, state): Promise<boolean> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
@@ -103,6 +107,7 @@ export class PostsService implements CanActivate {
|
|||||||
const result = !this.debugMode ? res['config_file'] : res;
|
const result = !this.debugMode ? res['config_file'] : res;
|
||||||
if (result) {
|
if (result) {
|
||||||
this.config = result['YoutubeDLMaterial'];
|
this.config = result['YoutubeDLMaterial'];
|
||||||
|
this.config_reloaded = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,14 +51,8 @@ export class SettingsComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getConfig() {
|
getConfig() {
|
||||||
this.loading_config = true;
|
this.initial_config = this.postsService.config;
|
||||||
this.postsService.loadNavItems().subscribe(res => {
|
this.new_config = JSON.parse(JSON.stringify(this.initial_config));
|
||||||
this.loading_config = false;
|
|
||||||
// successfully loaded config
|
|
||||||
|
|
||||||
this.initial_config = !this.postsService.debugMode ? res['config_file']['YoutubeDLMaterial'] : res['YoutubeDLMaterial'];
|
|
||||||
this.new_config = JSON.parse(JSON.stringify(this.initial_config));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsSame() {
|
settingsSame() {
|
||||||
@@ -70,8 +64,8 @@ export class SettingsComponent implements OnInit {
|
|||||||
this.postsService.setConfig(settingsToSave).subscribe(res => {
|
this.postsService.setConfig(settingsToSave).subscribe(res => {
|
||||||
if (res['success']) {
|
if (res['success']) {
|
||||||
// sets new config as old config
|
// sets new config as old config
|
||||||
this.postsService.settings_changed.next(true);
|
|
||||||
this.initial_config = JSON.parse(JSON.stringify(this.new_config));
|
this.initial_config = JSON.parse(JSON.stringify(this.new_config));
|
||||||
|
this.postsService.reload_config.next(true);
|
||||||
}
|
}
|
||||||
}, err => {
|
}, err => {
|
||||||
console.error('Failed to save config!');
|
console.error('Failed to save config!');
|
||||||
|
|||||||
@@ -50,7 +50,11 @@ export class SubscriptionComponent implements OnInit {
|
|||||||
this.id = this.route.snapshot.paramMap.get('id');
|
this.id = this.route.snapshot.paramMap.get('id');
|
||||||
|
|
||||||
this.getSubscription();
|
this.getSubscription();
|
||||||
this.getConfig();
|
this.postsService.config_reloaded.subscribe(changed => {
|
||||||
|
if (changed) {
|
||||||
|
this.getConfig();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// set filter property to cached
|
// set filter property to cached
|
||||||
@@ -78,10 +82,7 @@ export class SubscriptionComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getConfig() {
|
getConfig() {
|
||||||
this.postsService.loadNavItems().subscribe(res => {
|
this.use_youtubedl_archive = this.postsService.config['Subscriptions']['subscriptions_use_youtubedl_archive'];
|
||||||
const result = !this.postsService.debugMode ? res['config_file'] : res;
|
|
||||||
this.use_youtubedl_archive = result['YoutubeDLMaterial']['Subscriptions']['subscriptions_use_youtubedl_archive'];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
goToFile(emit_obj) {
|
goToFile(emit_obj) {
|
||||||
|
|||||||
Reference in New Issue
Block a user