From 7ef6c78612927b19238a5fa4bb16e2695c7934df Mon Sep 17 00:00:00 2001 From: Isaac Grynsztein Date: Sun, 5 Apr 2020 15:19:12 -0400 Subject: [PATCH] merged new checkbox for bookmarklet: enables ability to set bookmarklet to audio only fixed two bugs for audio only files: sometimes downloads failed as extensions were improperly removed and readded, removing a single character from the filename. Fixed another extension-related bug where metadata from deleted audio files persisted --- backend/app.js | 22 ++++++++++++++++++++-- src/app/settings/settings.component.html | 1 + src/app/settings/settings.component.ts | 12 ++++++++++-- src/app/updater/updater.component.html | 10 +++++----- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/backend/app.js b/backend/app.js index 46995ff..2c0a05d 100644 --- a/backend/app.js +++ b/backend/app.js @@ -710,11 +710,21 @@ async function deleteAudioFile(name, blacklistMode = false) { return new Promise(resolve => { // TODO: split descriptors into audio and video descriptors, as deleting an audio file will close all video file streams var jsonPath = path.join(audioFolderPath,name+'.mp3.info.json'); + var altJSONPath = path.join(audioFolderPath,name+'.info.json'); var audioFilePath = path.join(audioFolderPath,name+'.mp3'); jsonPath = path.join(__dirname, jsonPath); + altJSONPath = path.join(__dirname, altJSONPath); audioFilePath = path.join(__dirname, audioFilePath); let jsonExists = fs.existsSync(jsonPath); + + if (!jsonExists) { + if (fs.existsSync(altJSONPath)) { + jsonExists = true; + jsonPath = altJSONPath; + } + } + let audioFileExists = fs.existsSync(audioFilePath); if (descriptors[name]) { @@ -1012,6 +1022,12 @@ async function checkExistsWithTimeout(filePath, timeout) { }); } +function removeFileExtension(filename) { + const filename_parts = filename.split('.'); + filename_parts.splice(filename_parts.length - 1) + return filename_parts.join('.'); +} + // https://stackoverflow.com/a/32197381/8088021 const deleteFolderRecursive = function(folder_to_delete) { if (fs.existsSync(folder_to_delete)) { @@ -1165,8 +1181,10 @@ app.post('/api/tomp3', async function(req, res) { // if invalid, continue onto the next continue; } + + const filename_no_extension = removeFileExtension(output_json['_filename']); - var full_file_path = output_json['_filename'].substring(0, output_json['_filename'].length-5) + '.mp3'; + var full_file_path = filename_no_extension + '.mp3'; if (fs.existsSync(full_file_path)) { let tags = { title: output_json['title'], @@ -1179,7 +1197,7 @@ app.post('/api/tomp3', async function(req, res) { logger.info('Output mp3 does not exist'); } - var file_path = output_json['_filename'].substring(audioFolderPath.length, output_json['_filename'].length-5); + var file_path = filename_no_extension.substring(audioFolderPath.length, filename_no_extension.length); if (file_path) file_names.push(file_path); } diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index 576c874..98342ca 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -210,6 +210,7 @@
Bookmarklet

Drag the link below to your bookmarks, and you're good to go! Just navigate to the YouTube video you'd like to download, and click the bookmark.

+ Generate 'audio only' bookmarklet

YTDL-Bookmarklet

diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index c2b846f..3099317 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -7,6 +7,7 @@ import {DomSanitizer} from '@angular/platform-browser'; import { MatDialog } from '@angular/material/dialog'; import { ArgModifierDialogComponent } from 'app/dialogs/arg-modifier-dialog/arg-modifier-dialog.component'; import { CURRENT_VERSION } from 'app/consts'; +import { MatCheckboxChange } from '@angular/material/checkbox'; @Component({ selector: 'app-settings', @@ -22,6 +23,7 @@ export class SettingsComponent implements OnInit { new_config = null loading_config = false; generated_bookmarklet_code = null; + bookmarkletAudioOnly = false; _settingsSame = true; @@ -96,11 +98,17 @@ export class SettingsComponent implements OnInit { generateBookmarkletCode() { const currentURL = window.location.href.split('#')[0]; const homePageWithArgsURL = currentURL + '#/home;url='; - const bookmarkletCodeInside = `'${homePageWithArgsURL}' + window.location` - const bookmarkletCode = `javascript:(function()%7Bwindow.open('${homePageWithArgsURL}' + encodeURIComponent(window.location))%7D)()`; + const audioOnly = this.bookmarkletAudioOnly; + // tslint:disable-next-line: max-line-length + const bookmarkletCode = `javascript:(function()%7Bwindow.open('${homePageWithArgsURL}' + encodeURIComponent(window.location) + ';audioOnly=${audioOnly}')%7D)()`; return bookmarkletCode; } + bookmarkletAudioOnlyChanged(event: MatCheckboxChange): void { + this.bookmarkletAudioOnly = event.checked; + this.generated_bookmarklet_code = this.sanitizer.bypassSecurityTrustUrl(this.generateBookmarkletCode()); + } + // not currently functioning on most platforms. hence not in use bookmarksite(title, url) { // Internet Explorer diff --git a/src/app/updater/updater.component.html b/src/app/updater/updater.component.html index 80d02d2..507bc00 100644 --- a/src/app/updater/updater.component.html +++ b/src/app/updater/updater.component.html @@ -4,11 +4,11 @@
- - - {{version['tag_name'] + (version === latestStableRelease ? ' - Latest Stable' : '') + (version['tag_name'] === CURRENT_VERSION ? ' - Current Version' : '')}} - - + + + {{version['tag_name'] + (version === latestStableRelease ? ' - Latest Stable' : '') + (version['tag_name'] === CURRENT_VERSION ? ' - Current Version' : '')}} + +