-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfomain.cpp
407 lines (341 loc) · 14.9 KB
/
nfomain.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
* GeeXboX NFO editor: GUI for media scanner application.
* Copyright (C) 2009 Fabien Brisset <[email protected]>
*
* This file is part of nfo-editor.
*
* nfo-editor is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* nfo-editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with libvalhalla; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "nfomain.h"
#define GRABBER_MAX 16
#define PRIORITY 15
NfoMain::NfoMain()
{
setupUi(this);
this->setWindowIcon(QIcon("icons/icon_enna_128.png"));
QObject::connect(actionAbout, SIGNAL(activated()), qApp, SLOT(aboutQt()));
}
void NfoMain::on_actionOpen_activated()
{
folder = QFileDialog::getExistingDirectory(this);
this->listOfFiles->addItems(NfoMain::grabFiles(folder));
}
void NfoMain::fillProgressBar()
{
//TO BE COMPLETED
}
void
eventgl_cb (valhalla_event_gl_t e, void *data)
{
//TO BE COMPLETED/CHANGED
(void) data;
if (e == VALHALLA_EVENTGL_SCANNER_EXIT)
printf ("Scanner finished: %u\n", e);
}
void
eventmd_cb (valhalla_event_md_t e, const char *id,
const valhalla_file_t *file,
const valhalla_metadata_t *md, void *data)
{
const char *group;
//TO BE COMPLETED/CHANGED
(void) data;
printf ("Metadata event\n");
printf (" File : %s (%u)\n",
file->path, file->type);
switch (e)
{
case VALHALLA_EVENTMD_PARSER:
printf (" Parser\n");
break;
case VALHALLA_EVENTMD_GRABBER:
printf (" Grabber : %s\n", id);
break;
}
group = valhalla_metadata_group_str (md->group);
printf (" Name : %s\n Value : %s\n Group : %u \"%s\"\n",
md->name, md->value, md->group, group);
//NfoMain::fillProgressBar();
}
void NfoMain::on_launchScan_clicked()
{
int rc;
const char *database = "./valhalla.db";
valhalla_t *handle;
valhalla_init_param_t param;
valhalla_verb_t verbosity = VALHALLA_MSG_VERBOSE;
valhalla_verbosity (verbosity);
memset (¶m, 0, sizeof (param));
param.parser_nb = 2;
param.grabber_nb = 16;
param.commit_int = 128;
param.decrapifier = 1;
param.gl_cb = eventgl_cb;
param.md_cb = eventmd_cb;
handle = valhalla_init (database, ¶m);
if (!handle)
return ;
// TO BE CHANGED TO TAKE THE LIST OF THE APPLICATION
const char *const *it;
const char *const suf[] = {
"avi", "mkv", "mov", "mpg", "wmv",
NULL
};
for (it = suf; *it; it++)
{
valhalla_config_set(handle, SCANNER_SUFFIX, *it);
printf (" %s", *it);
}
valhalla_config_set(handle, SCANNER_PATH, this->folder.toAscii().data(), 1);
rc = valhalla_run (handle, 1, 0, PRIORITY);
if (rc)
{
valhalla_uninit (handle);
return;
}
//valhalla_uninit (handle);
this->fileInfo->setPlainText(folder);
}
void NfoMain::on_actionClose_activated()
{
if (!this->filePathes.empty())
this->filePathes.clear();
if (!this->nfoFiles.empty())
this->nfoFiles.clear();
this->thumbList->clear();
this->fanArtList->clear();
this->fanartDisplayed->clear();
this->thumbDisplayed->clear();
this->listOfFiles->clear();
this->fileInfo->clear();
this->nfoInfo->clear();
}
void NfoMain::on_listOfFiles_currentItemChanged(QListWidgetItem * current)
{
if (current)
{
this->thumbList->clear();
this->fanArtList->clear();
this->fanartDisplayed->clear();
this->thumbDisplayed->clear();
fillFileInformationPanel(current->text());
fillMediaInformationPanel(current->text());
}
}
void NfoMain::on_thumbList_currentItemChanged(QListWidgetItem * current)
{
if (current)
{
if (QFile::exists(current->text()))
{
m_fanArt.load(current->text());
}
else
{
//web file
QUrl imageUrl(current->text());
getImage(imageUrl);
}
this->thumbDisplayed->setPixmap(QPixmap::fromImage(m_fanArt).scaled(this->thumbDisplayed->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
}
void NfoMain::on_fanArtList_currentItemChanged(QListWidgetItem * current)
{
if (current)
{
if (QFile::exists(current->text()))
{
m_fanArt.load(current->text());
}
else
{
//web file
QUrl imageUrl(current->text());
getImage(imageUrl);
}
this->fanartDisplayed->setPixmap(QPixmap::fromImage(m_fanArt).scaled(this->fanartDisplayed->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
}
void NfoMain::getImage(const QUrl &p_url) {
// on indique à l'objet http le nom du serveur et le port
QHttp http(p_url.host(), p_url.port(80));
// Qt utilise un concept basé sur les évenements.
// Nous allons donc utiliser QEventLoop pour attendre le signal done(bool) de http
QEventLoop loop;
QObject::connect(&http, SIGNAL(done(bool)), &loop, SLOT(quit()));
// la requète HTTP
http.get(p_url.path());
// on attend le résultat du serveur
loop.exec();
// quand le serveur à finit,
// on lit le résultat à partir de l'objet http pour créer notre pixmap
m_fanArt.loadFromData(http.readAll());
}
QStringList NfoMain::grabFiles(QString folderSelected){
QStringList fileNames;
this->listFilter << "*.avi";
this->listFilter << "*.mkv";
QDirIterator dirIterator(folderSelected, listFilter ,QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
while(dirIterator.hasNext())
{
dirIterator.next();
fileNames << dirIterator.fileName();
this->filePathes << dirIterator.filePath();
}
this->listFilter.clear();
NfoMain::grabNfoFiles(folderSelected);
return fileNames;
}
void NfoMain::grabNfoFiles(QString folderSelected){
this->listFilter << "*.nfo";
QDirIterator dirIterator(folderSelected, listFilter ,QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
while(dirIterator.hasNext())
{
this->nfoFiles << dirIterator.next();
}
this->listFilter.clear();
}
void NfoMain::fillFileInformationPanel(QString fileName)
{
QString defaultFileInformation("No file information available before scan by libvalhalla");
if(!fileName.isNull())
defaultFileInformation.append(" for ").append(fileName);
this->fileInfo->setPlainText(defaultFileInformation);
}
void NfoMain::fillMediaInformationPanel(QString fileName)
{
QString preReg(".*");
QString postReg(".nfo");
fileName.chop(fileName.size()-fileName.lastIndexOf("."));
fileName.prepend(preReg);
fileName.append(postReg);
QRegExp rx(fileName, Qt::CaseInsensitive);
if (this->nfoFiles.indexOf(rx) != -1)
{
this->nfoInfo->setPlainText("Nfo found");
NfoMain::parseNfoFile(this->nfoFiles.value(this->nfoFiles.indexOf(rx)));
}
else
this->nfoInfo->setPlainText("No NFO file present. Launch libvalhalla to have information !");
}
void NfoMain::parseNfoFile(QString nfoFile)
{
nfo_t *nfo_file = nfo_init(nfoFile.toAscii().data());
switch (nfo_get_type(nfo_file))
{
case NFO_MOVIE:
NfoMain::fillNfoMovie(nfo_get_movie(nfo_file));
break;
case NFO_TVSHOW:
NfoMain::fillNfoTvShow(nfo_get_tvshow_episode(nfo_file));
break;
default:
this->nfoInfo->setPlainText("This nfo si not valid.");
}
}
void NfoMain::fillNfoMovie(nfo_movie_t *nfoMovie)
{
QString contentNfo("");
int i = 0;
contentNfo.append("<b>Title :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_TITLE));
contentNfo.append("<br><b>Original title :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_ORIGINAL_TITLE));
contentNfo.append("<br><b>Plot :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_PLOT));
contentNfo.append("<br><b>Year :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_YEAR));
contentNfo.append("<br><b>Top 250 :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_TOP250));
contentNfo.append("<br><b>Outline :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_OUTLINE));
contentNfo.append("<br><b>Tagline :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_TAGLINE));
contentNfo.append("<br><b>Runtime :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_RUNTIME));
contentNfo.append("<br><b>Votes :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_VOTES));
contentNfo.append("<br><b>Rating :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_RATING));
contentNfo.append("<br><b>Genre :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_GENRE));
contentNfo.append("<br><b>Credits :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_CREDITS));
contentNfo.append("<br><b>Director :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_DIRECTOR));
contentNfo.append("<br><b>Studio :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_STUDIO));
contentNfo.append("<br><b>Trailer :</b> ").append(nfo_movie_get(nfoMovie, NFO_MOVIE_TRAILER));
for (i = 0; i < nfo_movie_get_actors_count(nfoMovie); i++)
{
if (i == 0)
contentNfo.append("<br><b>Actor : </b> ");
else
contentNfo.append(",<br> ");
contentNfo.append(nfo_actor_get(nfo_movie_get_actor(nfoMovie, i), NFO_ACTOR_NAME));
if (nfo_actor_get(nfo_movie_get_actor(nfoMovie, i), NFO_ACTOR_ROLE))
contentNfo.append(" as <i> ").append(nfo_actor_get(nfo_movie_get_actor(nfoMovie, i), NFO_ACTOR_ROLE)).append("</i>");
}
if (nfo_movie_get(nfoMovie, NFO_MOVIE_FAN_ART))
{
this->fanArtList->addItem(nfo_movie_get(nfoMovie, NFO_MOVIE_FAN_ART));
QImage fanArt(nfo_movie_get(nfoMovie, NFO_MOVIE_FAN_ART));
this->fanartDisplayed->setPixmap(QPixmap::fromImage(fanArt).scaled(this->fanartDisplayed->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
if (nfo_movie_get(nfoMovie, NFO_MOVIE_THUMB))
{
this->thumbList->addItem(nfo_movie_get(nfoMovie, NFO_MOVIE_THUMB));
QImage thumb(nfo_movie_get(nfoMovie, NFO_MOVIE_THUMB));
this->thumbDisplayed->setPixmap(QPixmap::fromImage(thumb).scaled(this->thumbDisplayed->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
this->nfoInfo->setText(contentNfo);
}
void NfoMain::fillNfoTvShow(nfo_tvshow_episode_t *nfoTvShow)
{
QString contentNfo("");
int i = 0;
nfo_tvshow_t *nfoShow = nfo_tvshow_episode_get_show(nfoTvShow);
if (nfoShow)
{
contentNfo.append("<b>Show Title :</b> ").append(nfo_tvshow_get(nfoShow, NFO_TVSHOW_TITLE));
contentNfo.append("<br><b>Show Rating :</b> ").append(nfo_tvshow_get(nfoShow, NFO_TVSHOW_RATING));
contentNfo.append("<br><b>Show Premiered :</b> ").append(nfo_tvshow_get(nfoShow, NFO_TVSHOW_PREMIERED));
contentNfo.append("<br><b>Show Plot :</b> ").append(nfo_tvshow_get(nfoShow, NFO_TVSHOW_PLOT));
contentNfo.append("<br><b>Show Episode Guide URL :</b> ").append(nfo_tvshow_get(nfoShow, NFO_TVSHOW_EPISODE_GUIDE_URL));
contentNfo.append("<br><b>Show Total seasons :</b> ").append(nfo_tvshow_get(nfoShow, NFO_TVSHOW_SEASON));
contentNfo.append("<br><b>Show Total episodes :</b> ").append(nfo_tvshow_get(nfoShow, NFO_TVSHOW_EPISODE));
contentNfo.append("<br><b>Show Genre :</b> ").append(nfo_tvshow_get(nfoShow, NFO_TVSHOW_GENRE));
contentNfo.append("<br><b>Show Studio :</b> ").append(nfo_tvshow_get(nfoShow, NFO_TVSHOW_STUDIO));
}
contentNfo.append("<br><b>Ep Title :</b> ").append(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_TITLE));
contentNfo.append("<br><b>Ep Season :</b> ").append(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_SEASON));
contentNfo.append("<br><b>Episode :</b> ").append(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_EPISODE));
contentNfo.append("<br><b>Ep Plot :</b> ").append(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_PLOT));
contentNfo.append("<br><b>Ep Rating :</b> ").append(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_RATING));
contentNfo.append("<br><b>Ep Credits :</b> ").append(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_CREDITS));
contentNfo.append("<br><b>Ep Director :</b> ").append(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_DIRECTOR));
contentNfo.append("<br><b>Ep Aired :</b> ").append(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_AIRED));
contentNfo.append("<br><b>Ep Votes :</b> ").append(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_VOTES));
for (i = 0; i < nfo_tvshow_episode_get_actors_count(nfoTvShow); i++)
{
if (i == 0)
contentNfo.append("<br><b>Actor : </b> ");
else
contentNfo.append(",<br> ");
contentNfo.append(nfo_actor_get(nfo_tvshow_episode_get_actor(nfoTvShow, i), NFO_ACTOR_NAME));
if ((nfo_actor_get(nfo_tvshow_episode_get_actor(nfoTvShow, i), NFO_ACTOR_ROLE))
&& (strlen(nfo_actor_get(nfo_tvshow_episode_get_actor(nfoTvShow, i), NFO_ACTOR_ROLE)) > 0))
contentNfo.append(" as <i> ").append(nfo_actor_get(nfo_tvshow_episode_get_actor(nfoTvShow, i), NFO_ACTOR_ROLE)).append("</i>");
}
if (nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_FANART_SEASON))
{
this->fanArtList->addItem(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_FANART_SEASON));
QImage fanArt(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_FANART_SEASON));
this->fanartDisplayed->setPixmap(QPixmap::fromImage(fanArt).scaled(this->fanartDisplayed->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
if (nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_FANART))
{
this->thumbList->addItem(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_FANART));
QImage thumb(nfo_tvshow_episode_get(nfoTvShow, NFO_TVSHOW_EPISODE_FANART));
this->thumbDisplayed->setPixmap(QPixmap::fromImage(thumb).scaled(this->thumbDisplayed->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
this->nfoInfo->setText(contentNfo);
}