forked from detain/skyscraper
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathabstractscraper.h
More file actions
204 lines (178 loc) · 7.11 KB
/
abstractscraper.h
File metadata and controls
204 lines (178 loc) · 7.11 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
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
/***************************************************************************
* abstractscraper.h
*
* Wed Jun 18 12:00:00 CEST 2017
* Copyright 2017 Lars Muldjord
* muldjordlars@gmail.com
****************************************************************************/
/*
* This file is part of skyscraper.
*
* skyscraper is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* skyscraper 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with skyscraper; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#ifndef ABSTRACTSCRAPER_H
#define ABSTRACTSCRAPER_H
#include "gameentry.h"
#include "netcomm.h"
#include "netmanager.h"
#include "settings.h"
#include <QEventLoop>
#include <QFileInfo>
#include <QImage>
#include <QList>
#include <QSettings>
#include <QVariantMap>
class AbstractScraper : public QObject {
Q_OBJECT
public:
enum MatchType { ABSTRACT, MATCH_ONE, MATCH_MANY };
AbstractScraper(Settings *config, QSharedPointer<NetManager> manager,
MatchType type = ABSTRACT, int timeout = 30 /* secs */);
virtual ~AbstractScraper();
virtual void getGameData(GameEntry &game);
virtual QList<QString> getSearchNames(const QFileInfo &info,
QString &debug);
virtual QString getCompareTitle(const QFileInfo &info);
virtual void runPasses(QList<GameEntry> &gameEntries, const QFileInfo &info,
QString &output, QString &debug);
QString lookupAliasMap(const QString &baseName, QString &debug);
MatchType getType() const { return type; };
int reqRemaining = -1;
#ifdef TESTING
QList<QString> getRegionPrios() { return regionPrios; }
void detectRegionFromFilename(const QFileInfo &info);
#endif
signals:
void die(const int &, const QString &, const QString &);
public slots:
void bury(const int &, const QString &, const QString &);
protected:
Settings *config;
virtual void getSearchResults(QList<GameEntry> &gameEntries,
QString searchName, QString platform);
virtual void populateGameEntry(GameEntry &game);
virtual void getDescription(GameEntry &game);
virtual void getDeveloper(GameEntry &game);
virtual void getPublisher(GameEntry &game);
virtual void getPlayers(GameEntry &game);
virtual void getAges(GameEntry &game);
virtual void getTags(GameEntry &game);
virtual void getRating(GameEntry &game);
virtual void getReleaseDate(GameEntry &game);
virtual void getCover(GameEntry &game);
virtual void getScreenshot(GameEntry &game);
virtual void getWheel(GameEntry &game);
virtual void getMarquee(GameEntry &game);
virtual void getTexture(GameEntry &game);
virtual void getTitle(GameEntry &);
virtual void getVideo(GameEntry &game);
// sparse scraper support
virtual void getManual(GameEntry &game) { (void)game; };
virtual void getFanart(GameEntry &game) { (void)game; };
virtual void getBackcover(GameEntry &game) { (void)game; };
virtual void nomNom(const QString nom, bool including = true);
bool checkNom(const QString nom);
virtual bool platformMatch(QString found, QString platform);
virtual QVector<int> getPlatformId(const QString);
virtual QString applyQuerySearchName(QString query) { return query; };
virtual QString removeStopwords(QString &searchName) { return searchName; };
QString lookupSearchName(const QFileInfo &info, const QString &baseName,
QString &debug);
QByteArray downloadMedia(const QString &url, bool isImage = true);
QVariantMap readJson(const QString &filename);
MatchType type = ABSTRACT;
QList<int> fetchOrder;
QByteArray data;
QString baseUrl;
QString searchUrlPre;
QString searchUrlPost;
QString searchResultPre;
QList<QString> urlPre;
QString urlPost;
QList<QString> titlePre;
QString titlePost;
QList<QString> platformPre;
QString platformPost;
QList<QString> descriptionPre;
QString descriptionPost;
QList<QString> developerPre;
QString developerPost;
QList<QString> publisherPre;
QString publisherPost;
QList<QString> playersPre;
QString playersPost;
QList<QString> agesPre;
QString agesPost;
QList<QString> tagsPre;
QString tagsPost;
QList<QString> ratingPre;
QString ratingPost;
QList<QString> releaseDatePre;
QString releaseDatePost;
QList<QString> coverPre;
QString coverPost;
QList<QString> screenshotPre;
QString screenshotPost;
QString screenshotCounter;
QList<QString> wheelPre;
QString wheelPost;
QList<QString> marqueePre;
QString marqueePost;
QList<QString> texturePre;
QString texturePost;
QList<QString> videoPre;
QString videoPost;
// This is used when file names have a region in them. The original
// regionPrios is in Settings
QList<QString> regionPrios;
NetComm *netComm;
QEventLoop q; // Event loop for use when waiting for data from NetComm.
private:
QString lookupArcadeTitle(const QString &baseName);
#ifndef TESTING
void detectRegionFromFilename(const QFileInfo &info);
#endif
const inline QList<QPair<QString, QString>> regionMap() {
// use list of pairs to maintain order
return QList<QPair<QString, QString>>{
QPair<QString, QString>("europe", "eu"),
QPair<QString, QString>("(e)", "eu"),
QPair<QString, QString>("eu", "eu"),
QPair<QString, QString>("usa", "us"),
QPair<QString, QString>("(u)", "us"),
QPair<QString, QString>("us", "us"),
QPair<QString, QString>("world", "wor"),
QPair<QString, QString>("wor", "wor"),
QPair<QString, QString>("japan", "jp"),
QPair<QString, QString>("(j)", "jp"),
QPair<QString, QString>("jp", "jp"),
QPair<QString, QString>("brazil", "br"),
QPair<QString, QString>("korea", "kr"),
QPair<QString, QString>("taiwan", "tw"),
QPair<QString, QString>("france", "fr"),
QPair<QString, QString>("germany", "de"),
QPair<QString, QString>("italy", "it"),
QPair<QString, QString>("spain", "sp"),
QPair<QString, QString>("china", "cn"),
QPair<QString, QString>("australia", "au"),
QPair<QString, QString>("aus", "au"),
QPair<QString, QString>("sweden", "se"),
QPair<QString, QString>("canada", "ca"),
QPair<QString, QString>("netherlands", "nl"),
QPair<QString, QString>("denmark", "dk"),
QPair<QString, QString>("asia", "asi")};
}
};
#endif // ABSTRACTSCRAPER_H