mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-19 02:21:28 +03:00
Working with encryption!
This commit is contained in:
@@ -12,7 +12,8 @@
|
|||||||
"favicon.ico",
|
"favicon.ico",
|
||||||
"backend/audio",
|
"backend/audio",
|
||||||
"backend/video",
|
"backend/video",
|
||||||
"backend"
|
"backend",
|
||||||
|
{ "glob": "default.json", "input": "./", "output": "../backend/config/", "allowOutsideOutDir": true }
|
||||||
],
|
],
|
||||||
"index": "index.html",
|
"index": "index.html",
|
||||||
"main": "main.ts",
|
"main": "main.ts",
|
||||||
|
|||||||
@@ -3,26 +3,29 @@ var fs = require('fs');
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
var youtubedl = require('youtube-dl');
|
var youtubedl = require('youtube-dl');
|
||||||
var config = require('config');
|
var config = require('config');
|
||||||
const 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 appAnchor = express();
|
|
||||||
|
|
||||||
var hostURL = config.get("YoutubeDL-Material.Host.frontend-url");
|
var frontendUrl = config.get("YoutubeDLMaterial.Host.frontendurl");
|
||||||
var hostPort = config.get("YoutubeDL-Material.Host.backend-port");
|
var backendUrl = config.get("YoutubeDLMaterial.Host.backendurl")
|
||||||
var usingEncryption = config.get("YoutubeDL-Material.Encryption.use-encryption");
|
var backendPort = 17442;
|
||||||
var basePath = config.get("YoutubeDL-Material.Downloader.path-base");
|
var usingEncryption = config.get("YoutubeDLMaterial.Encryption.use-encryption");
|
||||||
var audioPath = config.get("YoutubeDL-Material.Downloader.path-audio");
|
var basePath = config.get("YoutubeDLMaterial.Downloader.path-base");
|
||||||
var videoPath = config.get("YoutubeDL-Material.Downloader.path-video");
|
var audioPath = config.get("YoutubeDLMaterial.Downloader.path-audio");
|
||||||
|
var videoPath = config.get("YoutubeDLMaterial.Downloader.path-video");
|
||||||
|
|
||||||
if (usingEncryption)
|
if (usingEncryption)
|
||||||
{
|
{
|
||||||
var certFilePath = path.resolve(config.get("YoutubeDL-Material.Encryption.cert-file-path"));
|
|
||||||
var keyFilePath = path.resolve(config.get("YoutubeDL-Material.Encryption.key-file-path"));
|
var certFilePath = path.resolve(config.get("YoutubeDLMaterial.Encryption.cert-file-path"));
|
||||||
|
var keyFilePath = path.resolve(config.get("YoutubeDLMaterial.Encryption.key-file-path"));
|
||||||
|
|
||||||
|
var certKeyFile = fs.readFileSync(keyFilePath);
|
||||||
|
var certFile = fs.readFileSync(certFilePath);
|
||||||
|
|
||||||
var certKeyFile = fs.readFileSync(certFilePath);
|
|
||||||
var certFile = fs.readFileSync(keyFilePath);
|
|
||||||
var options = {
|
var options = {
|
||||||
key: certKeyFile,
|
key: certKeyFile,
|
||||||
cert: certFile
|
cert: certFile
|
||||||
@@ -34,37 +37,24 @@ if (usingEncryption)
|
|||||||
app.use(bodyParser.urlencoded({ extended: false }));
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
appAnchor.use(bodyParser.urlencoded({ extended: false }));
|
|
||||||
appAnchor.use(bodyParser.json());
|
|
||||||
|
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
res.header("Access-Control-Allow-Origin", hostURL);
|
res.header("Access-Control-Allow-Origin", frontendUrl);
|
||||||
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();
|
||||||
});
|
});
|
||||||
|
|
||||||
appAnchor.use(function(req, res, next) {
|
app.get('/using-encryption', function(req, res) {
|
||||||
res.header("Access-Control-Allow-Origin", hostURL);
|
|
||||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
appAnchor.get('/url', function(req, res) {
|
|
||||||
res.send(JSON.stringify(("localhost" + ":" + hostPort + "/")));
|
|
||||||
res.end("yes");
|
|
||||||
});
|
|
||||||
|
|
||||||
appAnchor.get('/using-encryption', function(req, res) {
|
|
||||||
res.send(usingEncryption);
|
res.send(usingEncryption);
|
||||||
res.end("yes");
|
res.end("yes");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.post('/tomp3', function(req, res) {
|
app.post('/tomp3', function(req, res) {
|
||||||
var url = req.body.url;
|
var url = req.body.url;
|
||||||
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, ['--no-check-certificate','-o', path + audiopath + ".mp3", '-x', '--audio-format', 'mp3'], {}, function(err, output) {
|
youtubedl.exec(url, ['-o', path + audiopath + ".mp3", '-x', '--audio-format', 'mp3'], {}, function(err, output) {
|
||||||
if (err) {
|
if (err) {
|
||||||
audiopath = "-1";
|
audiopath = "-1";
|
||||||
throw err;
|
throw err;
|
||||||
@@ -81,7 +71,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, ['--no-check-certificate', '-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'], {}, function(err, output) {
|
||||||
if (err) {
|
if (err) {
|
||||||
videopath = "-1";
|
videopath = "-1";
|
||||||
throw err;
|
throw err;
|
||||||
@@ -188,19 +178,17 @@ app.get('/audio/:id', function(req , res){
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
appAnchor.listen(17442,function(){
|
|
||||||
console.log("Anchor set on 17442");
|
|
||||||
});
|
|
||||||
|
|
||||||
if (usingEncryption)
|
if (usingEncryption)
|
||||||
{
|
{
|
||||||
https.createServer(options, app).listen(hostPort, function() {
|
https.createServer(options, app).listen(backendPort, function() {
|
||||||
console.log('HTTPS: Started on PORT ' + hostPort);
|
console.log('HTTPS: Anchor set on 17442');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
app.listen(hostPort,function(){
|
app.listen(backendPort,function(){
|
||||||
console.log("HTTP: Started on PORT " + hostPort);
|
console.log("HTTP: Started on PORT " + backendPort);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
"YoutubeDL-Material": {
|
"YoutubeDL-Material": {
|
||||||
"Host": {
|
"Host": {
|
||||||
"frontend-url": "http://localhost:4200",
|
"frontend-url": "http://localhost:4200",
|
||||||
|
"backend-url": "youtubedl.grynsztein.com",
|
||||||
"backend-port": "8088"
|
"backend-port": "8088"
|
||||||
},
|
},
|
||||||
"Encryption": {
|
"Encryption": {
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"YoutubeDL-Material": {
|
"YoutubeDLMaterial": {
|
||||||
"Host": {
|
"Host": {
|
||||||
"frontend-url": "http://localhost:4200",
|
"frontendurl": "http://localhost:4200",
|
||||||
"backend-port": "8088"
|
"backendurl": "https://youtubedl.grynsztein.com/"
|
||||||
},
|
},
|
||||||
"Encryption": {
|
"Encryption": {
|
||||||
"use-encryption": false,
|
"use-encryption": false,
|
||||||
"cert-file-path": "fullchain.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/",
|
||||||
|
|||||||
@@ -23,20 +23,39 @@ export class AppComponent {
|
|||||||
constructor(private postsService: PostsService) {
|
constructor(private postsService: PostsService) {
|
||||||
this.audioOnly = true;
|
this.audioOnly = true;
|
||||||
|
|
||||||
// starts handshake
|
|
||||||
this.doHandshake();
|
|
||||||
|
this.postsService.loadNavItems().subscribe(result => {
|
||||||
|
var backendUrl = result.YoutubeDLMaterial.Host.backendurl;
|
||||||
|
|
||||||
|
this.postsService.path = backendUrl;
|
||||||
|
this.postsService.startPath = backendUrl;
|
||||||
|
this.postsService.startPathSSL = backendUrl;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
urlForm = new FormControl('', [Validators.required]);
|
urlForm = new FormControl('', [Validators.required]);
|
||||||
|
|
||||||
doHandshake() {
|
doHandshake(url: string) {
|
||||||
this.postsService.startHandshake().subscribe(url => {
|
this.postsService.startHandshake(url).subscribe(theurl => {
|
||||||
this.postsService.path = "http://" + url;
|
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, make sure port 17442 is open!");
|
console.log("Initial handshake failed on http.");
|
||||||
|
this.doHandshakeSSL(url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
doHandshakeSSL(url: string) {
|
||||||
|
this.postsService.startHandshakeSSL(url).subscribe(theurl => {
|
||||||
|
this.postsService.path = theurl;
|
||||||
|
this.postsService.handShakeComplete = true;
|
||||||
|
console.log("Handshake complete!");
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.log("Initial handshake failed on https too! Make sure port 17442 is open.");
|
||||||
this.postsService.handShakeComplete = false;
|
this.postsService.handShakeComplete = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -119,3 +138,4 @@ export class AppComponent {
|
|||||||
return re.test(str);
|
return re.test(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ 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,
|
MatSnackBarModule, MatCardModule, MatSelectModule, MatToolbarModule, MatCheckboxModule,
|
||||||
MatProgressBarModule } from '@angular/material';
|
MatProgressBarModule } from '@angular/material';
|
||||||
import { NgConfigureModule, ConfigureOptions } from 'ng4-configure/ng4-configure';
|
|
||||||
import { MyOptions } from './configuration_options.component';
|
|
||||||
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';
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
import { ConfigureOptions } from 'ng4-configure/ng4-configure';
|
|
||||||
|
|
||||||
export class MyOptions extends ConfigureOptions {
|
|
||||||
ConfigurationURL: string = 'assets/config.json';
|
|
||||||
AppVersion: string = '0.0.0';
|
|
||||||
BustCache: boolean = false
|
|
||||||
}
|
|
||||||
@@ -12,15 +12,22 @@ export class PostsService {
|
|||||||
audioFolder: string = "";
|
audioFolder: string = "";
|
||||||
videoFolder: string = "";
|
videoFolder: string = "";
|
||||||
startPath: string = "http://localhost:17442/";
|
startPath: string = "http://localhost:17442/";
|
||||||
|
startPathSSL: string = "https://localhost:17442/"
|
||||||
handShakeComplete: boolean = false;
|
handShakeComplete: boolean = false;
|
||||||
|
|
||||||
constructor(private http: Http){
|
constructor(private http: Http){
|
||||||
console.log('PostsService Initialized...');
|
console.log('PostsService Initialized...');
|
||||||
}
|
}
|
||||||
|
|
||||||
startHandshake(): Observable<string>
|
startHandshake(url: string): Observable<string>
|
||||||
{
|
{
|
||||||
return this.http.get(this.startPath + "url")
|
return this.http.get(url + "geturl")
|
||||||
|
.map(res => res.json());
|
||||||
|
}
|
||||||
|
|
||||||
|
startHandshakeSSL(url: string): Observable<string>
|
||||||
|
{
|
||||||
|
return this.http.get(url + "geturl")
|
||||||
.map(res => res.json());
|
.map(res => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +64,14 @@ export class PostsService {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadNavItems() {
|
||||||
|
return this.http.get("../../backend/config/default.json")
|
||||||
|
.map(res => res.json());
|
||||||
|
//This is optional, you can remove the last line
|
||||||
|
// if you don't want to log loaded json in
|
||||||
|
// console.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user