-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
129 lines (112 loc) · 3.36 KB
/
main.cpp
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
#include "basewindow.h"
#include "filedownload.h"
#include "json.hpp"
#include <QtCore>
#include <QtWidgets>
#include <QApplication>
#include <Windows.h>
QString getYoutubeID(QString Url)
{
QRegularExpressionMatch IDMatch = idReg.match(Url);
return IDMatch.captured(0);
}
QString getPlaylistID(QString Url)
{
QRegularExpressionMatch IDMatch = playlistIDReg.match(Url);
return IDMatch.captured(0);
}
QString getLength(std::string ISOString)
{
//Get the QString in format "(m):(s)" from ISO 8601 duration string. Does not accept hours
QString ISOQString = QString::fromStdString(ISOString);
ISOQString.remove("PT").remove("S");
QStringList Times = ISOQString.split("M");
QString Minutes = Times.value(0);
QString Seconds = Times.value(1);
if (Seconds.toInt() < 10){
Seconds = "0"+Seconds;
}
QString formatTime = Minutes + ":" + Seconds;
return formatTime;
}
void execCmd(const char* command)
{
//Command to open up cmd without causing a window pop up
//Used to run youtube-dl and pass arguments
wchar_t *path = (wchar_t*) malloc(sizeof(wchar_t) * 500);
for (int i = 0; i < strlen(command) + 1; i++)
{
path[i] = command[i];
}
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (!CreateProcess(NULL,
path,
NULL,
NULL,
FALSE,
CREATE_NO_WINDOW,
NULL,
NULL,
&si,
&pi))
{
qDebug() << "Could not start command "<< QString::fromLocal8Bit(command) << GetLastError();
return;
}
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
void createErrorMessage(QString Error)
{
QMessageBox* errorBox = new QMessageBox();
errorBox->setIcon(QMessageBox::Warning);
errorBox->setWindowTitle("ERROR");
errorBox->setText("The program has encountered an error:");
errorBox->setInformativeText(Error);
errorBox->setStandardButtons(QMessageBox::Abort);
QObject::connect(errorBox, &QMessageBox::buttonClicked, errorBox, &QMessageBox::close);
errorBox->exec();
}
QFont scaleFont(QFont Font, QString text, int width, int height)
{
//Iterate through to find appropriate font to represent the text in the label
QLabel Label;
Label.setFont(Font);
Label.resize(width, height);
QRect bound = QFontMetrics(Font).boundingRect(
0, 0, 320, 180, Qt::AlignCenter, text);
bool fit = (bound.width() <= Label.width() &&
bound.height() <= Label.height());
while (!fit) {
Font.setPointSize(Font.pointSize() - 1);
QRect bound = QFontMetrics(Font).boundingRect(
0, 0, 320, 180, Qt::AlignCenter, text);
if ((bound.width() <= Label.width() &&
bound.height() <= Label.height())) {
return Font;
}
}
return Font;
}
void SetSize(QWidget *window, int x,int y)
{
//Force QWidget size
window->resize(x,y);
window->setMaximumSize(x,y);
window->setMinimumSize(x,y);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QApplication::setApplicationName("Youtube2MP3");
qDebug() << "Version 0.3.2";
BaseWindow MainWindow;
MainWindow.show();
MainWindow.setAttribute(Qt::WA_QuitOnClose);
return app.exec();
}