-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
149 lines (120 loc) · 4.33 KB
/
app.js
File metadata and controls
149 lines (120 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var fs = require('fs');
var express=require("express");
var bodyParser=require("body-parser");
const { spawn } = require('child_process');
var exec = require('child_process').execFile;
require('dotenv').config();
const { BlobServiceClient } = require("@azure/storage-blob");
const storageAccountConnectionString = process.env.AZURE_STORAGE_CONNECTION_STRING;
const blobServiceClient = BlobServiceClient.fromConnectionString(storageAccountConnectionString);
var app=express();
const port = process.env.PORT || 8080;
app.use(bodyParser.json());
app.use(express.static('public'));
app.use(bodyParser.urlencoded({
extended: true
}));
async function blobUpload() {
// Create a container (folder) if it does not exist
const containerName = 'videos';
const containerClient = blobServiceClient.getContainerClient(containerName);
const createContainerResponse = await containerClient.createIfNotExists();
console.log(`Create container ${containerName} successfully`, createContainerResponse.succeeded);
const linkfile = 'input_link.txt';
const linkBlobClient = containerClient.getBlockBlobClient(linkfile);
linkBlobClient.uploadFile(linkfile);
const langfile = 'language.txt';
const langBlobClient = containerClient.getBlockBlobClient(langfile);
langBlobClient.uploadFile(langfile);
}
async function blobDownload() {
// Create a container (folder) if it does not exist
const containerName = 'videos';
const containerClient = blobServiceClient.getContainerClient(containerName);
const createContainerResponse = await containerClient.createIfNotExists();
const vidtitle = 'write_title.txt';
const vidtitleBlobClient = containerClient.getBlockBlobClient(vidtitle);
vidtitleBlobClient.downloadToFile(vidtitle);
}
//Change Language Request From Home Page
app.post('/', function(req,res){
var linkurl = req.body.linkurl;
var lang =req.body.lang;
// Validating Youtube URL
if( (linkurl != undefined || linkurl != '') ){
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/;
match = linkurl.match(regExp);
i1 = (match && match[2].length == 11) ? true : false ;
}
else
{
i1 = false;
}
if(i1){
// Link is validated
// Write Linkurl and Language in File
fs.writeFile('input_link.txt', linkurl, err => {
if (err) {
console.error(err)
return
}
})
fs.writeFile('language.txt', lang, err => {
if (err) {
console.error(err);
return
}
})
//Upload Link and Language Files in Blob
blobUpload();
//Run Python Script
let largeDataSet = [];
var child = exec('decipherscript.exe');
child.stdout.on('data', function(data) {
console.log('Pipe data from python script ...')
largeDataSet.push(data)
});
child.on('close', function() {
console.log(`child process close all stdio`);
return res.redirect('pages/finalpage.html');
// return setTimeout(function () {res.redirect('pages/finalpage.html');}, 30000);
});
blobDownload();
}
else{
console.log("Link is not Validated. Empty/Incorrect URL");
}
})
//Change Language Request From Final Pages
app.post('/pages/finalpage', function(req,res){
var lang =req.body.lang;
fs.writeFile('language.txt', lang, err => {
if (err) {
console.error(err);
return
}
})
blobUpload();
//Run PythonScript
let largeDataSet = [];
var child = exec('./decipherscript.exe');
child.stdout.on('data', function(data) {
console.log('Pipe data from python script ...')
largeDataSet.push(data)
});
child.on('close', function() {
console.log(`child process close all stdio`);
return res.redirect('finalpage.html');
// return setTimeout(function () {res.redirect('pages/finalpage.html');}, 30000);
});
//Download title of Video from Blob
blobDownload();
})
app.get('/',function(req,res){
res.set({
'Access-control-Allow-Origin': '*'
});
return res.redirect('index.html');
}).listen(port)
console.log(`Server running at http://localhost:${port}`);
app.use(express.static(__dirname + '/public'));