-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
149 lines (125 loc) · 4.27 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <QApplication>
#include <QMessageBox>
#include <QtWebEngine>
#include <Core/ConfigManager.hpp>
#include <Core/StreamingProviderParser.hpp>
#include <Core/StreamingProviderStore.hpp>
#include <Widgets/MainWindow.hpp>
#include <Widgets/BrowserWindow.hpp>
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QByteArray>
void compress_plugin(const QString &in, int level = -1)
{
if (!QFileInfo::exists(in))
return;
QFile ifile(in);
if (ifile.open(QFile::ReadOnly | QFile::Text))
{
QByteArray out = qCompress(ifile.readAll(), level);
ifile.close();
QFile ofile(in+".qgz");
if (ofile.open(QFile::WriteOnly))
{
ofile.write(out);
ofile.close();
}
out.clear();
}
}
int main(int argc, char **argv)
{
QApplication::setDesktopSettingsAware(false);
QApplication a(argc, argv);
a.setApplicationName(QLatin1String("LightweightQtDRMStreamViewer"));
a.setApplicationDisplayName(QLatin1String("Qt DRM Stream Viewer"));
a.setApplicationVersion("0.5");
a.setWindowIcon(QIcon(":/app-icon.svgz"));
if (a.arguments().contains("-c"))
{
compress_plugin(a.arguments().at(2), 9);
return 0;
}
StreamingProviderParser parser;
parser.findAll();
if (parser.providers().isEmpty())
{
qDebug() << "Warning: No providers found.";
}
else
{
qDebug() << "Found providers:" << parser.providers();
}
qDebug() << "\n-------------------------\n";
for (auto&& i : parser.providers())
{
// parse provider file
StreamingProviderParser::StatusCode status = parser.parse(i);
switch (status)
{
case StreamingProviderParser::SUCCESS:
qDebug() << "Added" << i << "to the list of streaming providers.";
break;
case StreamingProviderParser::FILE_ERROR:
qDebug() << "File" << i << "is faulty and was skipped!";
break;
case StreamingProviderParser::SYNTAX_ERROR:
qDebug() << "The file for provider" << i << "has issues. Please check the template. File skipped!";
break;
case StreamingProviderParser::FILE_EMPTY:
qDebug() << "File" << i << "is empty and was skipped!";
break;
case StreamingProviderParser::ALREADY_IN_LIST:
qDebug() << "Provider" << QFileInfo(i).baseName() << "is already in the list from a higher priority target! Skipped.";
break;
}
StreamingProviderStore::instance()->sort();
qDebug() << "\n-------------------------\n";
}
qDebug() << "Initializing Qt Web Engine...";
QtWebEngine::initialize();
if (a.arguments().contains("--fullscreen", Qt::CaseInsensitive) ||
a.arguments().contains("-fs", Qt::CaseInsensitive))
{
qDebug() << "Full screen mode was activated.";
Config()->fullScreenMode() = true;
}
for (auto&& i : a.arguments())
{
if (i.startsWith("--provider=", Qt::CaseInsensitive))
{
Config()->startupProfile() = i.mid(11);
}
}
// Skip main interface and directly load the given provider
if (!Config()->startupProfile().isEmpty())
{
qDebug() << "Loading provider" << Config()->startupProfile();
const Provider pr = StreamingProviderStore::instance()->provider(Config()->startupProfile());
if (pr.id.isEmpty())
{
qDebug() << Config()->startupProfile() << "No such provider! Exiting...";
return 1;
}
qDebug() << "Loading browser window...";
BrowserWindow *w = BrowserWindow::getInstance();
w->setProfile(pr);
qDebug() << "Everything done. Enjoy your shows/movies :D";
Config()->fullScreenMode() ? w->showFullScreen() : w->show();
auto status_code = a.exec();
delete BrowserWindow::getInstance();
return status_code;
}
else
{
qDebug() << "Loading interface...";
MainWindow w;
qDebug() << "Everything done. Enjoy your shows/movies :D";
w.show();
auto status_code = a.exec();
//delete BrowserWindow::getInstance();
return status_code;
}
return 0;
}