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
pull/49/head
Isaac Grynsztein 5 years ago
parent 1d9595d056
commit 7ef6c78612

@ -710,11 +710,21 @@ async function deleteAudioFile(name, blacklistMode = false) {
return new Promise(resolve => { return new Promise(resolve => {
// TODO: split descriptors into audio and video descriptors, as deleting an audio file will close all video file streams // 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 jsonPath = path.join(audioFolderPath,name+'.mp3.info.json');
var altJSONPath = path.join(audioFolderPath,name+'.info.json');
var audioFilePath = path.join(audioFolderPath,name+'.mp3'); var audioFilePath = path.join(audioFolderPath,name+'.mp3');
jsonPath = path.join(__dirname, jsonPath); jsonPath = path.join(__dirname, jsonPath);
altJSONPath = path.join(__dirname, altJSONPath);
audioFilePath = path.join(__dirname, audioFilePath); audioFilePath = path.join(__dirname, audioFilePath);
let jsonExists = fs.existsSync(jsonPath); let jsonExists = fs.existsSync(jsonPath);
if (!jsonExists) {
if (fs.existsSync(altJSONPath)) {
jsonExists = true;
jsonPath = altJSONPath;
}
}
let audioFileExists = fs.existsSync(audioFilePath); let audioFileExists = fs.existsSync(audioFilePath);
if (descriptors[name]) { 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 // https://stackoverflow.com/a/32197381/8088021
const deleteFolderRecursive = function(folder_to_delete) { const deleteFolderRecursive = function(folder_to_delete) {
if (fs.existsSync(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 // if invalid, continue onto the next
continue; 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)) { if (fs.existsSync(full_file_path)) {
let tags = { let tags = {
title: output_json['title'], title: output_json['title'],
@ -1179,7 +1197,7 @@ app.post('/api/tomp3', async function(req, res) {
logger.info('Output mp3 does not exist'); 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); if (file_path) file_names.push(file_path);
} }

@ -210,6 +210,7 @@
<div class="col-12"> <div class="col-12">
<h6>Bookmarklet</h6> <h6>Bookmarklet</h6>
<p><ng-container i18n="Bookmarklet instructions">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.</ng-container></p> <p><ng-container i18n="Bookmarklet instructions">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.</ng-container></p>
<mat-checkbox (change)="bookmarkletAudioOnlyChanged($event)"><ng-container i18n="Generate audio only bookmarklet checkbox">Generate 'audio only' bookmarklet</ng-container></mat-checkbox>
<!--<button style="margin-bottom: 5px;" mat-stroked-button color="accent" (click)="generateBookmarklet()">Generate bookmarklet</button>--> <!--<button style="margin-bottom: 5px;" mat-stroked-button color="accent" (click)="generateBookmarklet()">Generate bookmarklet</button>-->
<p><a [href]="generated_bookmarklet_code" target="_blank">YTDL-Bookmarklet</a></p> <p><a [href]="generated_bookmarklet_code" target="_blank">YTDL-Bookmarklet</a></p>
</div> </div>

@ -7,6 +7,7 @@ import {DomSanitizer} from '@angular/platform-browser';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { ArgModifierDialogComponent } from 'app/dialogs/arg-modifier-dialog/arg-modifier-dialog.component'; import { ArgModifierDialogComponent } from 'app/dialogs/arg-modifier-dialog/arg-modifier-dialog.component';
import { CURRENT_VERSION } from 'app/consts'; import { CURRENT_VERSION } from 'app/consts';
import { MatCheckboxChange } from '@angular/material/checkbox';
@Component({ @Component({
selector: 'app-settings', selector: 'app-settings',
@ -22,6 +23,7 @@ export class SettingsComponent implements OnInit {
new_config = null new_config = null
loading_config = false; loading_config = false;
generated_bookmarklet_code = null; generated_bookmarklet_code = null;
bookmarkletAudioOnly = false;
_settingsSame = true; _settingsSame = true;
@ -96,11 +98,17 @@ export class SettingsComponent implements OnInit {
generateBookmarkletCode() { generateBookmarkletCode() {
const currentURL = window.location.href.split('#')[0]; const currentURL = window.location.href.split('#')[0];
const homePageWithArgsURL = currentURL + '#/home;url='; const homePageWithArgsURL = currentURL + '#/home;url=';
const bookmarkletCodeInside = `'${homePageWithArgsURL}' + window.location` const audioOnly = this.bookmarkletAudioOnly;
const bookmarkletCode = `javascript:(function()%7Bwindow.open('${homePageWithArgsURL}' + encodeURIComponent(window.location))%7D)()`; // tslint:disable-next-line: max-line-length
const bookmarkletCode = `javascript:(function()%7Bwindow.open('${homePageWithArgsURL}' + encodeURIComponent(window.location) + ';audioOnly=${audioOnly}')%7D)()`;
return bookmarkletCode; 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 // not currently functioning on most platforms. hence not in use
bookmarksite(title, url) { bookmarksite(title, url) {
// Internet Explorer // Internet Explorer

@ -4,11 +4,11 @@
</div> </div>
<div *ngIf="availableVersions" style="display: inline-block; margin-left: 15px;"> <div *ngIf="availableVersions" style="display: inline-block; margin-left: 15px;">
<mat-form-field> <mat-form-field>
<mat-select [(ngModel)]="selectedVersion"> <mat-select [(ngModel)]="selectedVersion">
<mat-option *ngFor="let version of availableVersionsFiltered" [value]="version['tag_name']"> <mat-option *ngFor="let version of availableVersionsFiltered" [value]="version['tag_name']">
{{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' : '')}}
</mat-option> </mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
</div> </div>
<div *ngIf="selectedVersion && selectedVersion !== CURRENT_VERSION" style="display: inline-block; margin-left: 15px;"> <div *ngIf="selectedVersion && selectedVersion !== CURRENT_VERSION" style="display: inline-block; margin-left: 15px;">

Loading…
Cancel
Save