Skip to content

Commit

Permalink
Release 2.0.5
Browse files Browse the repository at this point in the history
Youtube downloader automatically pulls description data
  • Loading branch information
dmf444 committed May 21, 2021
1 parent fd8b947 commit cdc9d36
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "archives_manager",
"version": "2.0.4",
"version": "2.0.5",
"description": "The file & metadata management app for archives.",
"main": "./dist/main.bundle.js",
"scripts": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"installerIcon": "./dist/public/archivesLogo.ico",
"uninstallerIcon": "./dist/public/archivesLogo.ico"
},
"buildVersion": "2.0.4"
"buildVersion": "2.0.5"
},
"author": "David Fernandes @dmf444",
"license": "GPLv3",
Expand Down
4 changes: 4 additions & 0 deletions src/main/downloader/DefaultDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ export class DefaultDownloader implements IDownloader {
};
}

createdFilePostback(file): void {

}

}
3 changes: 2 additions & 1 deletion src/main/downloader/FileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class FileManager {
}

FileUtils.queryForDuplicates(hashCheck).then((contains: boolean) => {
FileUtils.createNewFileEntry(filePath, fileName, url, contains, hashCheck, stage);
let file = FileUtils.createNewFileEntry(filePath, fileName, url, contains, hashCheck, stage);
downloader.createdFilePostback(file);
sendSuccess("Download Success!", `File ${fileName} was downloaded successfully!`);
});

Expand Down
5 changes: 5 additions & 0 deletions src/main/downloader/IDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ interface IDownloader {

downloadUrl(url: string, stage: boolean): Promise<downloadPromise>;

/**
*
* @param file FileModel the created file, for allowing changes to data.
*/
createdFilePostback(file): void;
}
73 changes: 61 additions & 12 deletions src/main/downloader/YouTubeDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as jetpack from "fs-jetpack";
import {FileUtils} from "@main/downloader/FileUtils";
import {YtdlBuilder} from "@main/youtubedl/YtdlBuilder";
import {InspectResult} from "fs-jetpack/types";
import {FileModel} from "@main/file/FileModel";
import {getFileDatabase} from "@main/main";
const path = require('path');
const log = require('electron-log');
const AdmZip = require('adm-zip');
Expand All @@ -27,20 +29,11 @@ export class YouTubeDownloader implements IDownloader {
let downloadPromise: downloadPromise;
if (responseCode == 0) {
let fileNames: string[] = jetpack.list(initalDirectory);
let videoFileName: string = this.getVideoFileName(fileNames);
let md5: string = this.getMd5FromFile(initalDirectory + path.sep + videoFileName);

let fileName: string = this.getVideoFileName(fileNames);
let md5: string = this.getMd5FromFile(initalDirectory + path.sep + fileName);
let [zipName, zipBasePath] = this.zipFiles(fileNames, videoFileName, initalDirectory, stage);

var zip = new AdmZip();
fileNames.forEach((dlFileName: string) => {
zip.addLocalFile(initalDirectory + path.sep + dlFileName);
});

let zipBasePath: string = FileUtils.getFilePath(stage);
let lastDot: number = fileName.lastIndexOf(".");
let zipName: string = fileName.substring(0, lastDot) + ".zip";
let zipSavePath: string = zipBasePath + path.sep + zipName;
zip.writeZip(zipSavePath);

log.info("Video Downloaded!");
downloadPromise = {state: "completed", fileName: zipName, filePathDir: zipBasePath, md5: md5};
Expand Down Expand Up @@ -78,4 +71,60 @@ export class YouTubeDownloader implements IDownloader {
return initalDirectory;
}

private zipFiles(fileNames: string[], videoFileName: string, initalDirectory: string, stage: boolean) {
var zip = new AdmZip();
fileNames.forEach((dlFileName: string) => {
zip.addLocalFile(initalDirectory + path.sep + dlFileName);
});

let zipBasePath: string = FileUtils.getFilePath(stage);
let lastDot: number = videoFileName.lastIndexOf(".");
let zipName: string = videoFileName.substring(0, lastDot) + ".zip";
let zipSavePath: string = zipBasePath + path.sep + zipName;
zip.writeZip(zipSavePath);
return [zipName, zipBasePath];
}

private getJsonFileFromZip(fileLocation: string): boolean {
let zip = new AdmZip(fileLocation);
let entries = zip.getEntries();
let searchEntry = null;
entries.forEach(zipEntry => {
if(zipEntry.name.endsWith(".json")) {
searchEntry = zipEntry;
}
});
if(searchEntry !== null) {
zip.extractEntryTo(searchEntry.entryName, FileUtils.getFilePath(true), false, true);
return searchEntry.name;
}
return false;
}

public createdFilePostback(file: FileModel): void {
let zipName = this.getJsonFileFromZip(file.savedLocation);
log.info(zipName);
if(zipName !== false){
let jsonFilePath = FileUtils.getFilePath(true) + zipName;
let videoJson = jetpack.read(jsonFilePath, 'json');

let archivesJson = {
"original_url": videoJson['webpage_url'],
"description": "",
"copyright": "",
"upload_date": videoJson['upload_date'],
"video_description": videoJson['description'],
"channel_name": videoJson['channel'],
"channel_url": videoJson['uploader_url'],
"original_tags": videoJson['tags']
};
let description = JSON.stringify(archivesJson);
file.fileMetadata.descriptionVersion = "2.1.0";
file.fileMetadata.description = description;
getFileDatabase().updateFile(file);

jetpack.remove(jsonFilePath);
}
}

}
5 changes: 5 additions & 0 deletions src/main/youtubedl/YtdlBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export class YtdlBuilder {
return this;
}

public rencodeToMp4(): YtdlBuilder {
this.executeArgs.push('--recode-video mp4');
return this;
}


//Authentication options. No intent to use them, but they're here; just in case!
public authenticated(username: string, password: string): YtdlBuilder {
Expand Down

0 comments on commit cdc9d36

Please sign in to comment.