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