Go to the documentation of this file.
24 #ifndef RECORDING_EXTENDER_H_
25 #define RECORDING_EXTENDER_H_
30 #include <QJsonDocument>
91 bool teamsMatch(
const QStringList& names,
const QStringList& abbrevs)
const;
117 const QString& a1,
const QString& a2,
118 int p,
bool finished) :
141 bool match(
const QString& team1,
const QString& team2)
166 {
return qobject_cast<RecExtDataSource*>(parent()); }
169 virtual bool timeIsClose(
const QDateTime& eventStart);
172 static QJsonObject
walkJsonPath(QJsonObject&
object,
const QStringList& path);
176 static bool getJsonInt (
const QJsonObject&
object, QStringList& path,
int& value);
177 static bool getJsonInt (
const QJsonObject&
object,
const QString& key,
int& value);
178 static bool getJsonString(
const QJsonObject&
object, QStringList& path, QString& value);
179 static bool getJsonString(
const QJsonObject&
object,
const QString& key, QString& value);
180 static bool getJsonObject(
const QJsonObject&
object, QStringList& path, QJsonObject& value);
181 static bool getJsonObject(
const QJsonObject&
object,
const QString& key, QJsonObject& value);
182 static bool getJsonArray (
const QJsonObject&
object,
const QString& key, QJsonArray& value);
187 QObject(parent),
m_doc(std::move(doc)) {};
265 {
return qobject_cast<RecordingExtender*>(parent()); }
314 void run(
void)
override;
331 static bool parseProgramInfo(
const QString& subtitle,
const QString& description,
332 QString& team1, QString& team2);
369 #endif // RECORDING_EXTENDER_H_
static void clearDownloadedInfo()
Clear all downloaded info.
QString m_team1Normalized
void setTeamsNorm(QString team1, QString team2)
bool findGameInfo(ActiveGame &game) override
Parse a previously downloaded data page for a given sport.
void setAbbrevs(QStringList abbrevs)
static void clearCache()
Clear the downloaded document cache.
bool parseGameObject(const QJsonObject &gameObject, ActiveGame &game)
MLB ///.
RecordingExtender * getExtender()
void addNewRecording(int recordedID)
Add an item to the list of new recordings.
RecExtDataPage * newPage(const QJsonDocument &doc) override
void setTeams(QString team1, QString team2)
QUrl makeGameUrl(const ActiveGame &game, const QString &str) override
Create a URL for one specific game in the MLB API that is built from the various known bits of data a...
bool match(const QString &team1, const QString &team2)
SportInfo getInfo() const
bool teamsMatch(const QStringList &names, const QStringList &abbrevs) const
Do the supplied team names/abbrevs match this game.
Holds information on a TV Program one might wish to record.
static QMutex s_createLock
Interlock the scheduler thread crating this process, and this process determining whether it should c...
uint m_forcedYearforTesting
Testing data.
bool findGameInfo(ActiveGame &game) override
Parse a previously downloaded data page for a given sport.
RecExtDataSource(QObject *parent)
Internal representation of a recording rule, mirrors the record table.
void setTextState(QString text)
void processActiveRecordings()
Process the currently active sports recordings.
void setGameUrl(QUrl url)
Set the game status information URL.
void setStartTime(const QDateTime &time)
static QJsonObject walkJsonPath(QJsonObject &object, const QStringList &path)
Iterate through a json object and return the specified object.
@ FINAL_SCORE_AFTER_PENALTIES
void processNewRecordings()
Process the list of newly started sports recordings.
QString getAbbrev2() const
RecExtMlbDataPage(QObject *parent, QJsonDocument doc)
void setInfoUrl(QUrl url)
Set the game scheduling information URL.
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
ActiveGame(int recordedid, QString title)
RecExtMlbDataSource(QObject *parent)
QList< ActiveGame > m_activeGames
Currently ongoing games to track.
virtual QUrl findInfoUrl(ActiveGame &game, SportInfo &info)=0
virtual QUrl makeGameUrl(const ActiveGame &game, const QString &str)=0
bool findKnownSport(const QString &_title, AutoExtendType type, SportInfoList &info) const
Retrieve the db record for a sporting event on a specific provider.
void run(void) override
The main execution loop for the Recording Extender.
QUrl findInfoUrl(ActiveGame &game, SportInfo &info) override
Find the right URL for a specific recording.
void setInfo(const SportInfo &info)
RecExtEspnDataPage(QObject *parent, QJsonDocument doc)
bool matchName(const QString &a, const QString &b)
static bool getJsonString(const QJsonObject &object, QStringList &path, QString &value)
Retrieve the specified string from a json object.
QList< SportInfo > SportInfoList
bool m_running
Whether the RecordingExtender process is running.
QString getStartTimeAsString() const
static QString ruleIdAsString(const RecordingRule *rr)
Quick helper function for printing recording rule numbers.
static bool getJsonInt(const QJsonObject &object, QStringList &path, int &value)
Retrieve the specified integer from a json object.
QUrl findInfoUrl(ActiveGame &game, SportInfo &info) override
Find the right URL for a specific recording.
AutoExtendType dataProvider
virtual RecExtDataSource * createDataSource(AutoExtendType type)
Create a RecExtDataSource object for the specified service.
virtual bool findGameInfo(ActiveGame &game)=0
QList< int > m_newRecordings
Newly started recordings to process.
virtual GameState findGameScore(ActiveGame &game)=0
@ OFFICIAL_EVENT_SHORTENED
static bool getJsonArray(const QJsonObject &object, const QString &key, QJsonArray &value)
Retrieve the specified array from a json object.
QString m_team2Normalized
static bool parseProgramInfo(const QString &subtitle, const QString &description, QString &team1, QString &team2)
Parse a RecordingInfo to find the team names.
virtual RecExtDataPage * newPage(const QJsonDocument &doc)=0
RecExtDataPage * newPage(const QJsonDocument &doc) override
void setAbbrev1(const QString &abbrev)
QMutex m_newRecordingsLock
New recordings are added by the scheduler process and removed by this process.
RecExtDataSource * getSource()
void checkDone()
Is there any remaining work? Check for both newly created recording and for active recordings.
ActiveGame(int recordedid, QString title, SportInfo info)
static const QList< GameStatus > kFinalStatuses
A list of the ESPN status that mean the game is over.
RecExtDataPage * loadPage(const ActiveGame &game, const QUrl &_url) override
Download the data page for a game, and do some minimal validation.
static QHash< QString, QJsonDocument > s_downloadedJson
A cache of downloaded documents.
RecExtDataPage(QObject *parent, QJsonDocument doc)
Create a new RecExtDataPage object.
@ FINAL_SCORE_AFTER_GOLDEN_GOAL
QUrl makeGameUrl(const ActiveGame &game, const QString &str) override
Create a URL for one specific game in the ESPN API that is built from the various known bits of data ...
GameState(const QString &n1, const QString &n2, const QString &a1, const QString &a2, int p, bool finished)
Scheduler * m_scheduler
Pointer to the scheduler.
virtual QUrl makeInfoUrl(const SportInfo &info, const QDateTime &dt)=0
static void create(Scheduler *scheduler, RecordingInfo &ri)
Create an instance of the RecordingExtender if necessary, and add this recording to the list of new r...
RecExtEspnDataSource(QObject *parent)
QDateTime getStartTime() const
QString getTeam2Norm() const
QString getAbbrev1() const
static void nameCleanup(const SportInfo &info, QString &name1, QString &name2)
Clean up two team names for comparison against the ESPN API.
This is a wrapper around QThread that does several additional things.
GameState(const ActiveGame &game, int p, bool finished)
@ FIXTURE_NO_LIVE_COVERAGE
friend class TestRecordingExtender
@ FINAL_SCORE_AFTER_EXTRA_TIME
QString getTeam1Norm() const
virtual RecExtDataPage * loadPage(const ActiveGame &game, const QUrl &_url)=0
virtual bool timeIsClose(const QDateTime &eventStart)
Base Classes ///.
int getRecordedId() const
GameState findGameScore(ActiveGame &game) override
Parse the previously downloaded data page for a given game.
static bool getJsonObject(const QJsonObject &object, QStringList &path, QJsonObject &value)
Retrieve a specific object from another json object.
virtual QDateTime getNow()
Get the current time. Overridden by the testing code.
static RecordingExtender * s_singleton
The single instance of a RecordingExtender.
static void finishRecording(const RecordingInfo *ri, RecordingRule *rr, const ActiveGame &game)
Stop the current recording early.
QUrl makeInfoUrl(const SportInfo &info, const QDateTime &dt) override
Create a URL for the MLB API that is built from the various known bits of data accumulated so far.
void expireOverrides()
Delete the list of the override rules that have been created by this instance of RecordingExtender.
QList< int > m_overrideRules
Recordings that have had an override rule creates.
QUrl makeInfoUrl(const SportInfo &info, const QDateTime &dt) override
Create a URL for the ESPN API that is built from the various known bits of data accumulated so far.
void extendRecording(const RecordingInfo *ri, RecordingRule *rr, const ActiveGame &game)
Extend the current recording by XX minutes.
GameState findGameScore(ActiveGame &game) override
Parse the previously downloaded data page for a given game.
~RecordingExtender() override
bool matchAbbrev(const QString &a, const QString &b)
RecExtDataPage * loadPage(const ActiveGame &game, const QUrl &_url) override
Download the data page for a game, and do some minimal validation.
void setAbbrev2(const QString &abbrev)
QJsonDocument getDoc()
Get the JSON document associated with this object.
static void unchangedRecording(const RecordingInfo *ri, RecordingRule *rr, const ActiveGame &game)
Log that this recording hasn't changed.