Updated favicon, added progress bar functionality

pull/11/head
Isaac Grynsztein 8 years ago
parent 917235189a
commit 2a80ea92cc

@ -54,24 +54,109 @@ app.post('/tomp3', function(req, res) {
var date = Date.now(); var date = Date.now();
var path = audioPath; var path = audioPath;
var audiopath = Date.now(); var audiopath = Date.now();
youtubedl.exec(url, ['-o', path + audiopath + ".mp3", '-x', '--audio-format', 'mp3'], {}, function(err, output) { youtubedl.exec(url, ['-o', path + audiopath + ".mp3", '-x', '--audio-format', 'mp3', '--write-info-json'], {}, function(err, output) {
if (err) { if (err) {
audiopath = "-1"; audiopath = "-1";
throw err; throw err;
} }
}); });
// write file info
youtubedl.getInfo(url, function(err, info) {
if (err) throw err;
var size = info.size;
fs.writeFile("data/"+audiopath, size, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
});
var completeString = "done"; var completeString = "done";
var audiopathEncoded = encodeURIComponent(audiopath); var audiopathEncoded = encodeURIComponent(audiopath);
res.send(audiopathEncoded); res.send(audiopathEncoded);
res.end("yes"); res.end("yes");
}); });
function getFileSizeMp3(name)
{
var jsonPath = audioPath+name+".mp3.info.json";
if (fs.existsSync(jsonPath))
var obj = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
else
var obj = 0;
return obj.filesize;
}
function getAmountDownloadedMp3(name)
{
var partPath = audioPath+name+".mp3.part";
if (fs.existsSync(partPath))
{
const stats = fs.statSync(partPath);
const fileSizeInBytes = stats.size;
return fileSizeInBytes;
}
else
return 0;
}
function getFileSizeMp4(name)
{
var jsonPath = videoPath+name+".info.json";
var filesize = 0;
if (fs.existsSync(jsonPath))
{
var obj = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
var format = obj.format.substring(0,3);
for (i = 0; i < obj.formats.length; i++)
{
if (obj.formats[i].format_id == format)
{
filesize = obj.formats[i].filesize;
}
}
}
return filesize;
}
function getAmountDownloadedMp4(name)
{
var format = getVideoFormatID(name);
var partPath = videoPath+name+".f"+format+".mp4.part";
if (fs.existsSync(partPath))
{
const stats = fs.statSync(partPath);
const fileSizeInBytes = stats.size;
return fileSizeInBytes;
}
else
return 0;
}
function getVideoFormatID(name)
{
var jsonPath = videoPath+name+".info.json";
if (fs.existsSync(jsonPath))
{
var obj = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
var format = obj.format.substring(0,3);
return format;
}
}
app.post('/tomp4', function(req, res) { app.post('/tomp4', function(req, res) {
var url = req.body.url; var url = req.body.url;
var date = Date.now(); var date = Date.now();
var path = videoPath; var path = videoPath;
var videopath = Date.now(); var videopath = Date.now();
youtubedl.exec(url, ['-o', path + videopath + ".mp4", '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4'], {}, function(err, output) { youtubedl.exec(url, ['-o', path + videopath + ".mp4", '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4', '--write-info-json'], {}, function(err, output) {
if (err) { if (err) {
videopath = "-1"; videopath = "-1";
throw err; throw err;
@ -88,14 +173,19 @@ app.post('/mp3fileexists', function(req, res) {
var exists = ""; var exists = "";
var fullpath = audioPath + name + ".mp3"; var fullpath = audioPath + name + ".mp3";
if (fs.existsSync(fullpath)) { if (fs.existsSync(fullpath)) {
exists = basePath + audioPath + name; exists = [basePath + audioPath + name, getFileSizeMp3(name)];
} }
else else
{ {
exists = "failed"; var percent = 0;
var size = getFileSizeMp3(name);
var downloaded = getAmountDownloadedMp3(name);
if (size > 0)
percent = downloaded/size;
exists = ["failed", getFileSizeMp3(name), percent];
} }
//console.log(exists + " " + name); //console.log(exists + " " + name);
res.send(JSON.stringify(exists)); res.send(exists);
res.end("yes"); res.end("yes");
}); });
@ -104,14 +194,19 @@ app.post('/mp4fileexists', function(req, res) {
var exists = ""; var exists = "";
var fullpath = videoPath + name + ".mp4"; var fullpath = videoPath + name + ".mp4";
if (fs.existsSync(fullpath)) { if (fs.existsSync(fullpath)) {
exists = basePath + videoPath + name; exists = [basePath + videoPath + name, getFileSizeMp4(name)];
} }
else else
{ {
exists = "failed"; var percent = 0;
var size = getFileSizeMp4(name);
var downloaded = getAmountDownloadedMp4(name);
if (size > 0)
percent = downloaded/size;
exists = ["failed", getFileSizeMp4(name), percent];
} }
//console.log(exists + " " + name); //console.log(exists + " " + name);
res.send(JSON.stringify(exists)); res.send(exists);
res.end("yes"); res.end("yes");
}); });

@ -7,13 +7,15 @@
"Encryption": { "Encryption": {
"use-encryption": false, "use-encryption": false,
"cert-file-path": "cert.pem", "cert-file-path": "cert.pem",
"key-file-path": "privkey.pem", "key-file-path": "privkey.pem"
"chain-file-path": "chain.pem"
}, },
"Downloader": { "Downloader": {
"path-base": "http://localhost:8088/", "path-base": "http://localhost:8088/",
"path-audio": "audio/", "path-audio": "audio/",
"path-video": "video/" "path-video": "video/"
},
"Extra": {
"title_top": "Youtube Downloader"
} }
} }
} }

@ -33,7 +33,12 @@
</mat-card> </mat-card>
<br/> <br/>
<div class="centered big" id="bar_div" *ngIf="downloadingfile;else nofile"> <div class="centered big" id="bar_div" *ngIf="downloadingfile;else nofile">
<mat-progress-bar mode="indeterminate"></mat-progress-bar> <div *ngIf="determinateProgress;else indeterminateprogress">
<mat-progress-bar mode="determinate" value="{{percentDownloaded}}"></mat-progress-bar>
</div>
<ng-template #indeterminateprogress>
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</ng-template>
</div> </div>
<ng-template #nofile> <ng-template #nofile>

@ -3,6 +3,7 @@ import {PostsService} from './posts.services';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import {FormControl, Validators} from '@angular/forms'; import {FormControl, Validators} from '@angular/forms';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MatSnackBar} from '@angular/material';
import 'rxjs/add/observable/of'; import 'rxjs/add/observable/of';
import 'rxjs/add/operator/mapTo'; import 'rxjs/add/operator/mapTo';
import 'rxjs/add/operator/toPromise'; import 'rxjs/add/operator/toPromise';
@ -13,6 +14,7 @@ import 'rxjs/add/operator/toPromise';
styleUrls: ['./app.component.css'] styleUrls: ['./app.component.css']
}) })
export class AppComponent { export class AppComponent {
determinateProgress: boolean = false;
downloadingfile: boolean = false; downloadingfile: boolean = false;
audioOnly: boolean; audioOnly: boolean;
urlError: boolean = false; urlError: boolean = false;
@ -20,13 +22,15 @@ export class AppComponent {
url: string = ''; url: string = '';
exists: string = ""; exists: string = "";
topBarTitle: string = "Youtube Downloader"; topBarTitle: string = "Youtube Downloader";
constructor(private postsService: PostsService) { percentDownloaded: number;
constructor(private postsService: PostsService, public snackBar: MatSnackBar) {
this.audioOnly = true; this.audioOnly = true;
this.postsService.loadNavItems().subscribe(result => { this.postsService.loadNavItems().subscribe(result => { // loads settings
var backendUrl = result.YoutubeDLMaterial.Host.backendurl; var backendUrl = result.YoutubeDLMaterial.Host.backendurl;
this.topBarTitle = result.YoutubeDLMaterial.Extra.title_top;
this.postsService.path = backendUrl; this.postsService.path = backendUrl;
this.postsService.startPath = backendUrl; this.postsService.startPath = backendUrl;
@ -66,9 +70,17 @@ export class AppComponent {
downloadHelperMp3(name: string) downloadHelperMp3(name: string)
{ {
this.postsService.getFileStatusMp3(name).subscribe(fileExists => { this.postsService.getFileStatusMp3(name).subscribe(fileExists => {
this.exists = fileExists; var exists = fileExists;
if (this.exists == "failed") this.exists = exists[0];
if (exists[0] == "failed")
{ {
var percent = exists[2];
console.log(percent);
if (percent > 0.30)
{
this.determinateProgress = true;
this.percentDownloaded = percent*100;
}
setTimeout(() => this.downloadHelperMp3(name), 500); setTimeout(() => this.downloadHelperMp3(name), 500);
} }
else else
@ -82,9 +94,16 @@ export class AppComponent {
downloadHelperMp4(name: string) downloadHelperMp4(name: string)
{ {
this.postsService.getFileStatusMp4(name).subscribe(fileExists => { this.postsService.getFileStatusMp4(name).subscribe(fileExists => {
this.exists = fileExists; var exists = fileExists;
if (this.exists == "failed") this.exists = exists[0];
if (exists[0] == "failed")
{ {
var percent = exists[2];
if (percent > 0.30)
{
this.determinateProgress = true;
this.percentDownloaded = percent*100;
}
setTimeout(() => this.downloadHelperMp4(name), 500); setTimeout(() => this.downloadHelperMp4(name), 500);
} }
else else
@ -111,8 +130,11 @@ export class AppComponent {
{ {
this.downloadHelperMp3(this.path); this.downloadHelperMp3(this.path);
} }
},
error => { // can't access server
this.downloadingfile = false;
this.openSnackBar("Download failed!", "OK.");
}); });
} }
else else
{ {
@ -123,7 +145,11 @@ export class AppComponent {
{ {
this.downloadHelperMp4(this.path); this.downloadHelperMp4(this.path);
} }
}); },
error => { // can't access server
this.downloadingfile = false;
this.openSnackBar("Download failed!", "OK.");
});
} }
} }
else else
@ -137,5 +163,11 @@ export class AppComponent {
var re=new RegExp(strRegex); var re=new RegExp(strRegex);
return re.test(str); return re.test(str);
} }
openSnackBar(message: string, action: string) {
this.snackBar.open(message, action, {
duration: 2000,
});
}
} }

@ -55,12 +55,12 @@ export class PostsService {
.map(res => res.json()); .map(res => res.json());
} }
getFileStatusMp3(name: string): Observable<string> { getFileStatusMp3(name: string): Observable<any> {
return this.http.post(this.path + "mp3fileexists",{name: name}) return this.http.post(this.path + "mp3fileexists",{name: name})
.map(res => res.json()); .map(res => res.json());
} }
getFileStatusMp4(name: string): Observable<string> { getFileStatusMp4(name: string): Observable<any> {
return this.http.post(this.path + "mp4fileexists",{name: name}) return this.http.post(this.path + "mp4fileexists",{name: name})
.map(res => res.json()); .map(res => res.json());
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Loading…
Cancel
Save