This repository was archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
100 lines (85 loc) · 2.68 KB
/
mainwindow.cpp
File metadata and controls
100 lines (85 loc) · 2.68 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "error.h"
#include <QProcess>
#include <QtWidgets>
using namespace std;
static QString destiny;
static QProcess *process(new QProcess);
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_downloadButton_clicked()
{
if(ui->urlBox->text().isEmpty() || ui->destinationBox->text().isEmpty()){
Error e;
e.show();
e.exec();
}
else {
string url, dUrl, format, query, queryName, name;
int indexFormat;
url = ui->urlBox->text().toStdString();
dUrl = ui->destinationBox->text().toStdString();
indexFormat = ui->formatBox->currentIndex();
switch (indexFormat) {
case 0:
format = "best";
break;
case 1:
format = "worse";
break;
case 2:
format = "bestvideo";
break;
case 3:
format = "worsevideo";
break;
case 4:
format = "bestaudio";
break;
case 5:
format = "worseaudio";
break;
}
/*queryName = "youtube-dl --get-filename "+url;
system(queryName.data());*/
query = "-o "+dUrl+"/%(title)s.%(ext)s -f "+format+" "+url;
QString Query = query.data();
process->setProgram("youtube-dl");
connect(process, &QProcess::readyReadStandardError, this, &MainWindow::onReadyReadStandardError);
connect(process, &QProcess::readyReadStandardOutput, this, &MainWindow::readyReadStandardOutput);
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &MainWindow::onFinished);
process->setArguments(Query.split(" "));
process->start();
ui->downloadButton->setEnabled(false);
ui->stopDownload->setEnabled(true);
}
}
void MainWindow::onReadyReadStandardError(){
ui->consoleBox->appendPlainText(process->readAllStandardError().constData());
}
void MainWindow::readyReadStandardOutput(){
ui->consoleBox->appendPlainText(process->readAllStandardOutput().constData());
}
void MainWindow::onFinished(){
ui->downloadButton->setEnabled(true);
ui->stopDownload->setEnabled(false);
}
void MainWindow::on_optionsButton_clicked()
{
destiny = QFileDialog::getExistingDirectoryUrl().toString();
ui->destinationBox->setText(destiny.remove(0,7)); //file:// = 7
}
void MainWindow::on_stopDownload_clicked()
{
process->kill();
ui->downloadButton->setEnabled(true);
}