Compare commits

...

10 Commits
v1.1 ... v2.0

Author SHA1 Message Date
Isaac Grynsztein
abaa799628 quick dependency fix 2019-10-21 02:51:13 -04:00
Isaac Grynsztein
9e148d1464 more stylistic improvements 2019-10-21 02:46:22 -04:00
Isaac Grynsztein
9fa646132d added stylistic spinner 2019-10-21 02:25:03 -04:00
Isaac Grynsztein
f98ba00551 fixed bug preventing app being used outside root url 2019-10-21 02:24:47 -04:00
Isaac Grynsztein
bc1e0ea542 minor change 2019-10-20 19:16:10 -04:00
Isaac Grynsztein
9ebb684d5c Updated backend to reflect frontend changes 2019-10-20 19:15:26 -04:00
Isaac Grynsztein
91713f1140 Migrated to angular 8
Created dev configuration
2019-10-20 19:15:13 -04:00
Isaac Grynsztein
377676cda4 Stylistic improvements and moved away from @angular/http 2019-10-20 19:14:01 -04:00
Isaac Grynsztein
8e445bb80d Made repository changes 2019-10-20 17:39:02 -04:00
Tzahi12345
f0bde1efc4 Update README.md 2018-01-23 00:38:20 -05:00
20 changed files with 425 additions and 317 deletions

View File

@@ -1,61 +0,0 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "youtube-dl-material"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico",
"backend/audio",
"backend/video",
"backend",
{ "glob": "default.json", "input": "./", "output": "../backend/config/", "allowOutsideOutDir": true }
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}

View File

@@ -10,6 +10,10 @@ Here's an image of what it'll look like once you're done:
![frontpage](https://i.imgur.com/m3xozES.png) ![frontpage](https://i.imgur.com/m3xozES.png)
With optional file management enabled (default):
![frontpage_with_files](https://i.imgur.com/z9vME2O.png)
### Prerequisites ### Prerequisites
You need to have a functioning web server for this to work. Also make sure you have these dependencies installed on your system: ffmpeg, nodejs, python. If you don't, run this command: You need to have a functioning web server for this to work. Also make sure you have these dependencies installed on your system: ffmpeg, nodejs, python. If you don't, run this command:

134
angular.json Normal file
View File

@@ -0,0 +1,134 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"youtube-dl-material": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": [
"src/assets",
"src/favicon.ico",
"src/backend/audio",
"src/backend/video",
"src/backend"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "youtube-dl-material:build"
},
"configurations": {
"production": {
"browserTarget": "youtube-dl-material:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "youtube-dl-material:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"karmaConfig": "./karma.conf.js",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"scripts": [],
"styles": [
"src/styles.css"
],
"assets": [
"src/assets",
"src/favicon.ico",
"src/backend/audio",
"src/backend/video",
"src/backend"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": []
}
}
}
},
"youtube-dl-material-e2e": {
"root": "e2e",
"sourceRoot": "e2e",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "./protractor.conf.js",
"devServerTarget": "youtube-dl-material:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"e2e/tsconfig.e2e.json"
],
"exclude": []
}
}
}
}
},
"defaultProject": "youtube-dl-material",
"schematics": {
"@schematics/angular:component": {
"prefix": "app",
"styleext": "css"
},
"@schematics/angular:directive": {
"prefix": "app"
}
}
}

View File

@@ -6,9 +6,10 @@ var config = require('config');
var https = require('https'); var https = require('https');
var express = require("express"); var express = require("express");
var bodyParser = require("body-parser"); var bodyParser = require("body-parser");
var pem = require('https-pem');
var app = express(); var app = express();
var URL = require('url').URL;
var frontendUrl = config.get("YoutubeDLMaterial.Host.frontendurl"); var frontendUrl = config.get("YoutubeDLMaterial.Host.frontendurl");
var backendUrl = config.get("YoutubeDLMaterial.Host.backendurl") var backendUrl = config.get("YoutubeDLMaterial.Host.backendurl")
var backendPort = 17442; var backendPort = 17442;
@@ -37,8 +38,10 @@ if (usingEncryption)
app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json()); app.use(bodyParser.json());
var url_domain = new URL(frontendUrl);
app.use(function(req, res, next) { app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", frontendUrl); res.header("Access-Control-Allow-Origin", url_domain.origin);
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next(); next();
}); });
@@ -173,7 +176,7 @@ 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', '--write-info-json'], {}, function(err, output) { youtubedl.exec(url, ['--external-downloader', 'aria2c', '-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;
@@ -182,6 +185,7 @@ app.post('/tomp3', function(req, res) {
// write file info // write file info
/*
youtubedl.getInfo(url, function(err, info) { youtubedl.getInfo(url, function(err, info) {
if (err) throw err; if (err) throw err;
@@ -194,9 +198,12 @@ app.post('/tomp3', function(req, res) {
console.log("The file was saved!"); 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: audiopathEncoded
});
res.end("yes"); res.end("yes");
}); });
@@ -205,7 +212,7 @@ app.post('/tomp4', function(req, res) {
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', '--write-info-json'], {}, function(err, output) { youtubedl.exec(url, ['--external-downloader', 'aria2c', '-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;
@@ -213,7 +220,9 @@ app.post('/tomp4', function(req, res) {
}); });
var completeString = "done"; var completeString = "done";
var videopathEncoded = encodeURIComponent(videopath); var videopathEncoded = encodeURIComponent(videopath);
res.send(videopathEncoded); res.send({
videopathEncoded: videopathEncoded
});
res.end("yes"); res.end("yes");
}); });
@@ -274,6 +283,7 @@ app.post('/getMp3s', function(req, res) {
if (ext == ".mp3") if (ext == ".mp3")
{ {
var jsonobj = getJSONMp3(path.basename(files[i]).substring(0, path.basename(files[i]).length-4)); var jsonobj = getJSONMp3(path.basename(files[i]).substring(0, path.basename(files[i]).length-4));
if (!jsonobj) continue;
var id = path.basename(files[i]).substring(0, path.basename(files[i]).length-4); var id = path.basename(files[i]).substring(0, path.basename(files[i]).length-4);
var title = jsonobj.title; var title = jsonobj.title;
@@ -290,7 +300,9 @@ app.post('/getMp3s', function(req, res) {
} }
} }
res.send(mp3s); res.send({
mp3s: mp3s
});
res.end("yes"); res.end("yes");
}); });
@@ -307,6 +319,7 @@ app.post('/getMp4s', function(req, res) {
if (ext == ".mp4") if (ext == ".mp4")
{ {
var jsonobj = getJSONMp4(path.basename(files[i]).substring(0, path.basename(files[i]).length-4)); var jsonobj = getJSONMp4(path.basename(files[i]).substring(0, path.basename(files[i]).length-4));
if (!jsonobj) continue;
var id = path.basename(files[i]).substring(0, path.basename(files[i]).length-4); var id = path.basename(files[i]).substring(0, path.basename(files[i]).length-4);
var title = jsonobj.title; var title = jsonobj.title;
@@ -323,7 +336,9 @@ app.post('/getMp4s', function(req, res) {
} }
} }
res.send(mp4s); res.send({
mp4s: mp4s
});
res.end("yes"); res.end("yes");
}); });
@@ -334,7 +349,9 @@ app.post('/deleteMp3', function(req, res) {
var wasDeleted = false; var wasDeleted = false;
if (fs.existsSync(fullpath)) if (fs.existsSync(fullpath))
{ {
fs.unlink(fullpath); fs.unlink(fullpath, call => {
});
wasDeleted = true; wasDeleted = true;
res.send(wasDeleted); res.send(wasDeleted);
res.end("yes"); res.end("yes");
@@ -354,7 +371,9 @@ app.post('/deleteMp4', function(req, res) {
var wasDeleted = false; var wasDeleted = false;
if (fs.existsSync(fullpath)) if (fs.existsSync(fullpath))
{ {
fs.unlink(fullpath); fs.unlink(fullpath, call => {
// console.log(call);
});
wasDeleted = true; wasDeleted = true;
res.send(wasDeleted); res.send(wasDeleted);
res.end("yes"); res.end("yes");

BIN
backend/aria2c.exe Normal file

Binary file not shown.

View File

@@ -17,7 +17,10 @@
}, },
"homepage": "https://github.com/Tzahi12345/hda-backend#readme", "homepage": "https://github.com/Tzahi12345/hda-backend#readme",
"dependencies": { "dependencies": {
"async": "^3.1.0",
"config": "^3.2.3",
"exe": "^1.0.2", "exe": "^1.0.2",
"youtube-dl": "1.11.1" "express": "^4.17.1",
"youtube-dl": "^2.0.1"
} }
} }

12
browserslist Normal file
View File

@@ -0,0 +1,12 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# You can see what browsers were selected by your queries by running:
# npx browserslist
> 0.5%
last 2 versions
Firefox ESR
not dead
not IE 9-11 # For IE 9-11 support, remove 'not'.

View File

@@ -4,24 +4,22 @@
module.exports = function (config) { module.exports = function (config) {
config.set({ config.set({
basePath: '', basePath: '',
frameworks: ['jasmine', '@angular/cli'], frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [ plugins: [
require('karma-jasmine'), require('karma-jasmine'),
require('karma-chrome-launcher'), require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'), require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'), require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma') require('@angular-devkit/build-angular/plugins/karma')
], ],
client:{ client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser clearContext: false // leave Jasmine Spec Runner output visible in browser
}, },
coverageIstanbulReporter: { coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ], dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true fixWebpackSourcePaths: true
}, },
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'], reporters: ['progress', 'kjhtml'],
port: 9876, port: 9876,
colors: true, colors: true,

View File

@@ -12,40 +12,44 @@
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
"@angular/animations": "^5.2.0", "@angular-devkit/core": "^8.3.12",
"@angular/cdk": "^5.0.4", "@angular/animations": "^8.2.11",
"@angular/common": "^5.2.0", "@angular/cdk": "^8.2.3",
"@angular/compiler": "^5.2.0", "@angular/common": "^8.2.11",
"@angular/core": "^5.2.0", "@angular/compiler": "^8.2.11",
"@angular/forms": "^5.0.0", "@angular/core": "^8.2.11",
"@angular/http": "^5.0.0", "@angular/forms": "^8.2.11",
"@angular/material": "^5.0.4", "@angular/http": "^7.2.15",
"@angular/platform-browser": "^5.0.0", "@angular/material": "^8.2.3",
"@angular/platform-browser-dynamic": "^5.0.0", "@angular/platform-browser": "^8.2.11",
"@angular/router": "^5.0.0", "@angular/platform-browser-dynamic": "^8.2.11",
"@angular/router": "^8.2.11",
"core-js": "^2.4.1", "core-js": "^2.4.1",
"ng4-configure": "^0.1.7", "ng4-configure": "^0.1.7",
"rxjs": "^5.5.3", "rxjs": "^6.5.3",
"zone.js": "^0.8.4" "rxjs-compat": "^6.0.0-rc.0",
"tslib": "^1.10.0",
"zone.js": "~0.9.1"
}, },
"devDependencies": { "devDependencies": {
"@angular/cli": "1.5.5", "@angular-devkit/build-angular": "~0.803.12",
"@angular/compiler-cli": "^5.0.0", "@angular/cli": "^8.3.12",
"@angular/language-service": "^4.0.0", "@angular/compiler-cli": "^8.2.11",
"@angular/language-service": "^8.2.11",
"@types/jasmine": "2.5.45", "@types/jasmine": "2.5.45",
"@types/node": "~6.0.60", "@types/node": "~6.0.60",
"codelyzer": "~3.0.1", "codelyzer": "^5.0.1",
"jasmine-core": "~2.6.2", "jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0", "jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0", "karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1", "karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1", "karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0", "karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2", "karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^1.2.1",
"protractor": "~5.1.2", "protractor": "~5.1.2",
"ts-node": "~3.0.4", "ts-node": "~3.0.4",
"tslint": "~5.3.2", "tslint": "~5.3.2",
"typescript": "~2.5.3" "typescript": "~3.5.3"
} }
} }

View File

@@ -22,7 +22,7 @@ mat-toolbar.top {
}*/ }*/
.big { .big {
width: 60%; max-width: 800px;
margin: 0 auto; margin: 0 auto;
} }
@@ -38,4 +38,19 @@ mat-toolbar.top {
mat-form-field.mat-form-field { mat-form-field.mat-form-field {
font-size: 24px; font-size: 24px;
} }
.spinner {
position: absolute;
display: inline-block;
margin-left: -28px;
margin-top: -10px;
}
.make-room-for-spinner {
padding-right: 40px;
}
.equal-sizes {
padding-right: 20px;
}

View File

@@ -13,29 +13,38 @@
<br/> <br/>
<mat-card id="card" class="big demo-basic"> <div class="big demo-basic">
<mat-card-title> <mat-card id="card" style="margin-right: 20px; margin-left: 20px;">
<mat-toolbar color="primary">Youtube Downloader</mat-toolbar> <mat-card-title>
</mat-card-title> Youtube Downloader
<div style="width: 100%; height: 100%; padding-left: 24px; padding-right: 24px; position: relative"> </mat-card-title>
<mat-card-content> <mat-card-content>
<form class="example-form"> <div style="position: relative;">
<mat-form-field class="example-full-width"> <form class="example-form">
<input matInput [(ngModel)]="url" placeholder="URL" type="url" name="url" [formControl]="urlForm" required> <mat-form-field class="example-full-width">
<mat-error *ngIf="urlError || urlForm.invalid">Please enter a valid URL!</mat-error> <input matInput [(ngModel)]="url" placeholder="URL" type="url" name="url" [formControl]="urlForm" required>
</mat-form-field> <mat-error *ngIf="urlError || urlForm.invalid">Please enter a valid URL!</mat-error>
</form> </mat-form-field>
<br/> </form>
<mat-checkbox [(ngModel)]="audioOnly" style="float: left; margin-top: -12px">Only Audio</mat-checkbox> <br/>
<button style="float: right; margin-top: -16px" (click)="downloadClicked()" [disabled]="downloadingfile" type="submit" mat-raised-button <mat-checkbox [(ngModel)]="audioOnly" style="float: left; margin-top: -12px">Only Audio</mat-checkbox>
color="primary">Download</button>
</div>
</mat-card-content> </mat-card-content>
</div> <mat-card-actions>
</mat-card> <button style="margin-left: 8px; margin-bottom: 8px" (click)="downloadClicked()" [disabled]="downloadingfile" type="submit" mat-stroked-button
color="primary">Download</button>
</mat-card-actions>
</mat-card>
</div>
<br/> <br/>
<div class="centered big" id="bar_div" *ngIf="downloadingfile;else nofile"> <div class="centered big" id="bar_div" *ngIf="downloadingfile;else nofile">
<div *ngIf="determinateProgress;else indeterminateprogress"> <div [ngClass]="(determinateProgress && percentDownloaded === 100)?'make-room-for-spinner':'equal-sizes'" style="display: inline-block; width: 100%; padding-left: 20px" *ngIf="determinateProgress;else indeterminateprogress">
<mat-progress-bar mode="determinate" value="{{percentDownloaded}}"></mat-progress-bar> <mat-progress-bar mode="determinate" value="{{percentDownloaded}}"></mat-progress-bar>
<br/>
</div>
<div *ngIf="determinateProgress && percentDownloaded === 100" class="spinner">
<mat-spinner [diameter]="25"></mat-spinner>
</div> </div>
<ng-template #indeterminateprogress> <ng-template #indeterminateprogress>
<mat-progress-bar mode="indeterminate"></mat-progress-bar> <mat-progress-bar mode="indeterminate"></mat-progress-bar>
@@ -45,7 +54,7 @@
<ng-template #nofile> <ng-template #nofile>
</ng-template> </ng-template>
<div *ngIf="fileManagerEnabled"> <div style="margin: 20px" *ngIf="fileManagerEnabled">
<mat-accordion> <mat-accordion>
<mat-expansion-panel class="big"> <mat-expansion-panel class="big">
<mat-expansion-panel-header> <mat-expansion-panel-header>

View File

@@ -15,56 +15,54 @@ import 'rxjs/add/operator/toPromise';
styleUrls: ['./app.component.css'] styleUrls: ['./app.component.css']
}) })
export class AppComponent { export class AppComponent {
determinateProgress: boolean = false; determinateProgress = false;
downloadingfile: boolean = false; downloadingfile = false;
audioOnly: boolean; audioOnly: boolean;
urlError: boolean = false; urlError = false;
path: string = ''; path = '';
url: string = ''; url = '';
exists: string = ""; exists = '';
topBarTitle: string = "Youtube Downloader"; topBarTitle = 'Youtube Downloader';
percentDownloaded: number; percentDownloaded: number;
fileManagerEnabled: boolean = false; fileManagerEnabled = false;
mp3s: any[] = []; mp3s: any[] = [];
mp4s: any[] = []; mp4s: any[] = [];
constructor(private postsService: PostsService, public snackBar: MatSnackBar) { urlForm = new FormControl('', [Validators.required]);
this.audioOnly = true;
constructor(private postsService: PostsService, public snackBar: MatSnackBar) {
this.audioOnly = false;
this.postsService.loadNavItems().subscribe(result => { // loads settings this.postsService.loadNavItems().subscribe(result => { // loads settings
var backendUrl = result.YoutubeDLMaterial.Host.backendurl; const backendUrl = result['YoutubeDLMaterial']['Host']['backendurl'];
this.topBarTitle = result.YoutubeDLMaterial.Extra.title_top; this.topBarTitle = result['YoutubeDLMaterial']['Extra']['title_top'];
this.fileManagerEnabled = result.YoutubeDLMaterial.Extra.file_manager_enabled; this.fileManagerEnabled = result['YoutubeDLMaterial']['Extra']['file_manager_enabled'];
this.postsService.path = backendUrl; this.postsService.path = backendUrl;
this.postsService.startPath = backendUrl; this.postsService.startPath = backendUrl;
this.postsService.startPathSSL = backendUrl; this.postsService.startPathSSL = backendUrl;
if (this.fileManagerEnabled) if (this.fileManagerEnabled) {
{
this.getMp3s(); this.getMp3s();
this.getMp4s(); this.getMp4s();
} }
}, }, error => {
error => {
console.log(error); console.log(error);
}); });
} }
/*
urlForm = new FormControl('', [Validators.required]);
doHandshake(url: string) { doHandshake(url: string) {
this.postsService.startHandshake(url).subscribe(theurl => { this.postsService.startHandshake(url).subscribe(theurl => {
this.postsService.path = theurl; this.postsService.path = theurl;
this.postsService.handShakeComplete = true; this.postsService.handShakeComplete = true;
console.log("Handshake complete!"); console.log('Handshake complete!');
}, }, error => {
error => { console.log('Initial handshake failed on http.');
console.log("Initial handshake failed on http.");
this.doHandshakeSSL(url); this.doHandshakeSSL(url);
}); });
} }
@@ -73,27 +71,26 @@ export class AppComponent {
this.postsService.startHandshakeSSL(url).subscribe(theurl => { this.postsService.startHandshakeSSL(url).subscribe(theurl => {
this.postsService.path = theurl; this.postsService.path = theurl;
this.postsService.handShakeComplete = true; this.postsService.handShakeComplete = true;
console.log("Handshake complete!"); console.log('Handshake complete!');
}, },
error => { error => {
console.log("Initial handshake failed on https too! Make sure port 17442 is open."); console.log('Initial handshake failed on https too! Make sure port 17442 is open.');
this.postsService.handShakeComplete = false; this.postsService.handShakeComplete = false;
}); });
} }*/
getMp3s() { getMp3s() {
this.postsService.getMp3s().subscribe(result => { this.postsService.getMp3s().subscribe(result => {
var mp3s = result; const mp3s = result['mp3s'];
this.mp3s = mp3s; this.mp3s = mp3s;
}, }, error => {
error => {
console.log(error); console.log(error);
}); });
} }
getMp4s() { getMp4s() {
this.postsService.getMp4s().subscribe(result => { this.postsService.getMp4s().subscribe(result => {
var mp4s = result; const mp4s = result['mp4s'];
this.mp4s = mp4s; this.mp4s = mp4s;
}, },
error => { error => {
@@ -101,38 +98,28 @@ export class AppComponent {
}); });
} }
public goToFile(name, isAudio) public goToFile(name, isAudio) {
{ if (isAudio) {
if (isAudio)
{
this.downloadHelperMp3(name); this.downloadHelperMp3(name);
} } else {
else
{
this.downloadHelperMp4(name); this.downloadHelperMp4(name);
} }
} }
public removeFromMp3(name: string) public removeFromMp3(name: string) {
{ for (let i = 0; i < this.mp3s.length; i++) {
for (var i = 0; i < this.mp3s.length; i++) if (this.mp3s[i].id === name) {
{ this.mp3s.splice(i, 1);
if (this.mp3s[i].id == name)
{
this.mp3s.splice(i,1);
} }
} }
} }
public removeFromMp4(name: string) public removeFromMp4(name: string) {
{
console.log(name); console.log(name);
console.log(this.mp4s); console.log(this.mp4s);
for (var i = 0; i < this.mp4s.length; i++) for (let i = 0; i < this.mp4s.length; i++) {
{ if (this.mp4s[i].id === name) {
if (this.mp4s[i].id == name) this.mp4s.splice(i, 1);
{
this.mp4s.splice(i,1);
} }
} }
} }
@@ -140,100 +127,80 @@ export class AppComponent {
ngOnInit() { ngOnInit() {
} }
downloadHelperMp3(name: string) downloadHelperMp3(name: string) {
{
this.postsService.getFileStatusMp3(name).subscribe(fileExists => { this.postsService.getFileStatusMp3(name).subscribe(fileExists => {
var exists = fileExists; const exists = fileExists;
this.exists = exists[0]; this.exists = exists[0];
if (exists[0] == "failed") if (exists[0] === 'failed') {
{ const percent = exists[2];
var percent = exists[2];
console.log(percent); console.log(percent);
if (percent > 0.30) if (percent > 0.30) {
{
this.determinateProgress = true; this.determinateProgress = true;
this.percentDownloaded = percent*100; this.percentDownloaded = percent * 100;
} }
setTimeout(() => this.downloadHelperMp3(name), 500); setTimeout(() => this.downloadHelperMp3(name), 500);
} } else {
else
{
window.location.href = this.exists; window.location.href = this.exists;
} }
}); });
} }
downloadHelperMp4(name: string) downloadHelperMp4(name: string) {
{
this.postsService.getFileStatusMp4(name).subscribe(fileExists => { this.postsService.getFileStatusMp4(name).subscribe(fileExists => {
var exists = fileExists; const exists = fileExists;
this.exists = exists[0]; this.exists = exists[0];
if (exists[0] == "failed") if (exists[0] === 'failed') {
{ const percent = exists[2];
var percent = exists[2]; if (percent > 0.30) {
if (percent > 0.30)
{
this.determinateProgress = true; this.determinateProgress = true;
this.percentDownloaded = percent*100; this.percentDownloaded = percent * 100;
} }
setTimeout(() => this.downloadHelperMp4(name), 500); setTimeout(() => this.downloadHelperMp4(name), 500);
} } else {
else
{
window.location.href = this.exists; window.location.href = this.exists;
} }
}); });
} }
downloadClicked() downloadClicked() {
{ if (this.ValidURL(this.url)) {
if (this.ValidURL(this.url))
{
this.urlError = false; this.urlError = false;
this.path = ""; this.path = '';
if (this.audioOnly) if (this.audioOnly) {
{
this.downloadingfile = true; this.downloadingfile = true;
this.postsService.makeMP3(this.url).subscribe(posts => { this.postsService.makeMP3(this.url).subscribe(posts => {
this.path = posts; this.path = posts['audiopathEncoded'];
if (this.path != "-1") if (this.path !== '-1') {
{
this.downloadHelperMp3(this.path); this.downloadHelperMp3(this.path);
} }
}, }, error => { // can't access server
error => { // can't access server
this.downloadingfile = false; this.downloadingfile = false;
this.openSnackBar("Download failed!", "OK."); this.openSnackBar('Download failed!', 'OK.');
}); });
} } else {
else
{
this.downloadingfile = true; this.downloadingfile = true;
this.postsService.makeMP4(this.url).subscribe(posts => { this.postsService.makeMP4(this.url).subscribe(posts => {
this.path = posts; this.path = posts['videopathEncoded'];
if (this.path != "-1") if (this.path !== '-1') {
{
this.downloadHelperMp4(this.path); this.downloadHelperMp4(this.path);
} }
}, }, error => { // can't access server
error => { // can't access server
this.downloadingfile = false; this.downloadingfile = false;
this.openSnackBar("Download failed!", "OK."); this.openSnackBar('Download failed!', 'OK.');
}); });
} }
} } else {
else
{
this.urlError = true; this.urlError = true;
} }
} }
ValidURL(str) { ValidURL(str) {
var strRegex = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/; // tslint:disable-next-line: max-line-length
var re=new RegExp(strRegex); const strRegex = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/;
const re = new RegExp(strRegex);
return re.test(str); return re.test(str);
} }

View File

@@ -3,7 +3,8 @@ import { NgModule } from '@angular/core';
import {MatNativeDateModule, MatRadioModule, MatInputModule, MatButtonModule, MatSidenavModule, MatIconModule, MatListModule, import {MatNativeDateModule, MatRadioModule, MatInputModule, MatButtonModule, MatSidenavModule, MatIconModule, MatListModule,
MatSnackBarModule, MatCardModule, MatSelectModule, MatToolbarModule, MatCheckboxModule, MatGridListModule, MatSnackBarModule, MatCardModule, MatSelectModule, MatToolbarModule, MatCheckboxModule, MatGridListModule,
MatProgressBarModule, MatExpansionModule, MatProgressBarModule, MatExpansionModule,
MatGridList} from '@angular/material'; MatGridList,
MatProgressSpinnerModule} from '@angular/material';
import {FormsModule, ReactiveFormsModule} from '@angular/forms'; import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
@@ -41,6 +42,7 @@ import {RouterModule} from '@angular/router';
MatGridListModule, MatGridListModule,
MatExpansionModule, MatExpansionModule,
MatProgressBarModule, MatProgressBarModule,
MatProgressSpinnerModule,
RouterModule RouterModule
], ],
providers: [PostsService], providers: [PostsService],

View File

@@ -1,5 +1,6 @@
import {Injectable} from '@angular/core'; import {Injectable, isDevMode} from '@angular/core';
import {Http} from '@angular/http'; import { HttpClient } from '@angular/common/http';
import config from '../assets/default.json';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
@@ -8,93 +9,71 @@ import 'rxjs/add/observable/throw';
@Injectable() @Injectable()
export class PostsService { export class PostsService {
path: string = ""; path = '';
audioFolder: string = ""; audioFolder = '';
videoFolder: string = ""; videoFolder = '';
startPath: string = "http://localhost:17442/"; startPath = 'http://localhost:17442/';
startPathSSL: string = "https://localhost:17442/" startPathSSL = 'https://localhost:17442/'
handShakeComplete: boolean = false; handShakeComplete = false;
constructor(private http: Http){ constructor(private http: HttpClient) {
console.log('PostsService Initialized...'); console.log('PostsService Initialized...');
} }
startHandshake(url: string): Observable<string> startHandshake(url: string) {
{ return this.http.get(url + 'geturl');
return this.http.get(url + "geturl")
.map(res => res.json());
} }
startHandshakeSSL(url: string): Observable<string> startHandshakeSSL(url: string) {
{ return this.http.get(url + 'geturl');
return this.http.get(url + "geturl")
.map(res => res.json());
} }
getVideoFolder(): Observable<string> getVideoFolder() {
{ return this.http.get(this.startPath + 'videofolder');
return this.http.get(this.startPath + "videofolder")
.map(res => res.json());
} }
getAudioFolder(): Observable<string> getAudioFolder() {
{ return this.http.get(this.startPath + 'audiofolder');
return this.http.get(this.startPath + "audiofolder")
.map(res => res.json());
} }
makeMP3(url: string): Observable<string> makeMP3(url: string) {
{ return this.http.post(this.path + 'tomp3', {url: url});
return this.http.post(this.path + "tomp3",{url: url})
.map(res => res.json());
} }
makeMP4(url: string): Observable<string> makeMP4(url: string) {
{ return this.http.post(this.path + 'tomp4', {url: url});
return this.http.post(this.path + "tomp4",{url: url})
.map(res => res.json());
} }
getFileStatusMp3(name: string): Observable<any> { getFileStatusMp3(name: string) {
return this.http.post(this.path + "fileStatusMp3",{name: name}) return this.http.post(this.path + 'fileStatusMp3', {name: name});
.map(res => res.json());
} }
getFileStatusMp4(name: string): Observable<any> { getFileStatusMp4(name: string) {
return this.http.post(this.path + "fileStatusMp4",{name: name}) return this.http.post(this.path + 'fileStatusMp4', {name: name});
.map(res => res.json());
} }
loadNavItems() { loadNavItems() {
console.log("Config location: " + window.location.href + "backend/config/default.json"); if (isDevMode()) {
return this.http.get(window.location.href + "backend/config/default.json") return this.http.get('./assets/default.json');
.map(res => res.json()); }
console.log('Config location: ' + window.location.href + 'backend/config/default.json');
return this.http.get(window.location.href + 'backend/config/default.json');
} }
deleteFile(name: string, isAudio: boolean) deleteFile(name: string, isAudio: boolean) {
{ if (isAudio) {
if (isAudio) return this.http.post(this.path + 'deleteMp3', {name: name});
{ } else {
return this.http.post(this.path + "deleteMp3",{name: name}) return this.http.post(this.path + 'deleteMp4', {name: name});
.map(res => res.json());
}
else
{
return this.http.post(this.path + "deleteMp4",{name: name})
.map(res => res.json());
} }
} }
getMp3s() getMp3s() {
{ return this.http.post(this.path + 'getMp3s', {});
return this.http.post(this.path + "getMp3s", {})
.map(res => res.json());
} }
getMp4s() getMp4s() {
{ return this.http.post(this.path + 'getMp4s', {});
return this.http.post(this.path + "getMp4s", {})
.map(res => res.json());
} }
} }

22
src/assets/default.json Normal file
View File

@@ -0,0 +1,22 @@
{
"YoutubeDLMaterial": {
"Host": {
"frontendurl": "http://localhost:4200",
"backendurl": "http://localhost:17442/"
},
"Encryption": {
"use-encryption": false,
"cert-file-path": "/etc/letsencrypt/live/example.com/fullchain.pem",
"key-file-path": "/etc/letsencrypt/live/example.com/privkey.pem"
},
"Downloader": {
"path-base": "http://localhost:17442/",
"path-audio": "audio/",
"path-video": "video/"
},
"Extra": {
"title_top": "Youtube Downloader",
"file_manager_enabled": true
}
}
}

View File

@@ -43,7 +43,6 @@
/** Evergreen browsers require these. **/ /** Evergreen browsers require these. **/
import 'core-js/es6/reflect'; import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
/** ALL Firefox browsers require the following to support `@angular/animation`. **/ /** ALL Firefox browsers require the following to support `@angular/animation`. **/

View File

@@ -2,7 +2,6 @@
"extends": "../tsconfig.json", "extends": "../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "../out-tsc/app", "outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "", "baseUrl": "",
"types": [] "types": []
}, },

View File

@@ -1,20 +1,19 @@
{ {
"extends": "../tsconfig.json", "extends": "../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "../out-tsc/spec", "outDir": "../out-tsc/spec",
"module": "commonjs", "baseUrl": "",
"target": "es5", "types": [
"baseUrl": "", "jasmine",
"types": [ "node"
"jasmine", ]
"node" },
] "files": [
}, "test.ts",
"files": [ "polyfills.ts"
"test.ts"
], ],
"include": [ "include": [
"**/*.spec.ts", "**/*.spec.ts",
"**/*.d.ts" "**/*.d.ts"
] ]
}

View File

@@ -1,6 +1,8 @@
{ {
"compileOnSave": false, "compileOnSave": false,
"compilerOptions": { "compilerOptions": {
"downlevelIteration": true,
"importHelpers": true,
"outDir": "./dist/out-tsc", "outDir": "./dist/out-tsc",
"baseUrl": "src", "baseUrl": "src",
"sourceMap": true, "sourceMap": true,
@@ -8,13 +10,16 @@
"moduleResolution": "node", "moduleResolution": "node",
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"target": "es5", "target": "es2015",
"resolveJsonModule": true,
"esModuleInterop": true,
"typeRoots": [ "typeRoots": [
"node_modules/@types" "node_modules/@types"
], ],
"lib": [ "lib": [
"es2016", "es2016",
"dom" "dom"
] ],
"module": "esnext"
} }
} }

View File

@@ -14,8 +14,7 @@
"eofline": true, "eofline": true,
"forin": true, "forin": true,
"import-blacklist": [ "import-blacklist": [
true, true
"rxjs"
], ],
"import-spacing": true, "import-spacing": true,
"indent": [ "indent": [
@@ -119,12 +118,12 @@
"app", "app",
"kebab-case" "kebab-case"
], ],
"use-input-property-decorator": true, "no-inputs-metadata-property": true,
"use-output-property-decorator": true, "no-outputs-metadata-property": true,
"use-host-property-decorator": true, "no-host-metadata-property": true,
"no-input-rename": true, "no-input-rename": true,
"no-output-rename": true, "no-output-rename": true,
"use-life-cycle-interface": true, "use-lifecycle-interface": true,
"use-pipe-transform-interface": true, "use-pipe-transform-interface": true,
"component-class-suffix": true, "component-class-suffix": true,
"directive-class-suffix": true, "directive-class-suffix": true,