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
#include "onlinetvshowdatabase.h"
#include <QDebug>
#include <utils.h>
#include "library.h"
namespace OnlineTvShowDatabase {
Client::Client(OnlineCredentials& credentials, OnlineCredentials::TimeLock& lock, QObject* parent) :
QObject(parent),
credentials(credentials),
lock(lock)
{
}
SearchResult* Client::findShow(TvShow& show) {
QString name = show.name();
SearchResult* result = this->search(name);
if (!result) {
// TODO try alternate name
}
return result;
}
SearchResult::SearchResult(QString searchedQuery) : searchedQuery(searchedQuery) {}
SearchResult::~SearchResult() {
foreach(Entry* entry, entries) {
delete entry;
}
}
Entry::Entry() {}
Entry::~Entry() {}
void Entry::updateShow(TvShow& show, const Library& library, const QString identifierKey, UpdateFilter filter) const {
if (filter & OnlineTvShowDatabase::ufSynopsis) {
updateSynopsis(show);
}
if (filter & OnlineTvShowDatabase::ufTitle) {
// TODO add title aliases and enable this,
// make sure new files will check synonyms list when adding to library
//updateTitle(show);
}
if (filter & OnlineTvShowDatabase::ufRelations) {
updateRelations(show);
}
if (filter & OnlineTvShowDatabase::ufAiringDates) {
updateAiringDates(show);
}
// never overwrite remoteId and synonyms when there is a conflicting entry
const TvShow* existingShow = library.filter().getShowForRemoteId(identifierKey, this->getRemoteId());
if (!existingShow || existingShow == &show) {
// check if there is already another show with the same synonym
if (filter & OnlineTvShowDatabase::ufSynonyms) {
QStringList synonyms = getSynonyms();
foreach (const QString& synonym, synonyms) {
if (!library.existingTvShow(synonym)) {
show.addSynonyms(QStringList() << synonym);
}
}
}
if (filter & OnlineTvShowDatabase::ufRemoteId) {
updateRemoteId(show);
}
}
if (filter & OnlineTvShowDatabase::ufImage) {
updateImage(show, library.getDirectory());
}
//qDebug() << "updated show from mal-api.com" << id << title;
}
}