MythTV master
mythmetadatalookup.cpp
Go to the documentation of this file.
1// C headers
2#include <unistd.h> // close
3
4// C++ headers
5#include <iostream>
6#include <memory>
7#include <thread>
8
9// Qt headers
10#include <QtGlobal>
11#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
12#include <QtEnvironmentVariables>
13#endif
14#include <QCoreApplication>
15#include <QEventLoop>
16#ifdef Q_OS_DARWIN
17#include <QProcessEnvironment>
18#endif
19
20// MythTV
21#include "libmyth/mythcontext.h"
24#include "libmythbase/mythconfig.h"
25#include "libmythbase/mythdb.h"
29#include "libmythbase/mythversion.h"
30#include "libmythtv/jobqueue.h"
31
32// MythMetadataLookup
33#include "lookup.h"
35
36int main(int argc, char *argv[])
37{
39 if (!cmdline.Parse(argc, argv))
40 {
43 }
44
45 if (cmdline.toBool("showhelp"))
46 {
48 return GENERIC_EXIT_OK;
49 }
50
51 if (cmdline.toBool("showversion"))
52 {
54 return GENERIC_EXIT_OK;
55 }
56
57 QCoreApplication a(argc, argv);
58 QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHMETADATALOOKUP);
59
60#ifdef Q_OS_DARWIN
61 QString path = QCoreApplication::applicationDirPath();
62 qputenv("PYTHONPATH",
63 QString("%1/../Resources/lib/%2:%1/../Resources/lib/%2/site-packages:%1/../Resources/lib/%2/lib-dynload:%3")
64 .arg(path)
65 .arg(QFileInfo(PYTHON_EXE).fileName())
66 .arg(QProcessEnvironment::systemEnvironment().value("PYTHONPATH"))
67 .toUtf8().constData());
68#endif
69
70 int retval = cmdline.ConfigureLogging();
71 if (retval != GENERIC_EXIT_OK)
72 return retval;
73
75 // Don't listen to console input
76 close(0);
77
78 MythContext context {MYTH_BINARY_VERSION};
79 if (!context.Init(false))
80 {
81 LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
83 }
84
85 myth_nice(19);
86
87 MythTranslation::load("mythfrontend");
88
89 std::unique_ptr<LookerUpper> lookup = std::make_unique<LookerUpper>();
90
91 LOG(VB_GENERAL, LOG_INFO,
92 "Testing grabbers and metadata sites for functionality...");
93 if (!LookerUpper::AllOK())
95 LOG(VB_GENERAL, LOG_INFO,
96 "All grabbers tested and working. Continuing...");
97
98 if (cmdline.toBool("jobid"))
99 {
100 uint chanid = 0;
101 QDateTime starttime;
102 int jobType = JOB_METADATA;
103
104 if (!JobQueue::GetJobInfoFromID(cmdline.toInt("jobid"), jobType,
105 chanid, starttime))
106 {
107 LOG(VB_GENERAL, LOG_INFO,
108 QString("No valid job found for jobid: %1")
109 .arg(cmdline.toInt("jobid")));
110 return GENERIC_EXIT_NOT_OK;
111 }
112
113 lookup->HandleSingleRecording(chanid, starttime,
114 cmdline.toBool("refresh-rules"));
115 }
116 else if (cmdline.toBool("chanid") && cmdline.toBool("starttime"))
117 {
118 lookup->HandleSingleRecording(cmdline.toUInt("chanid"),
119 cmdline.toDateTime("starttime"),
120 cmdline.toBool("refresh-rules"));
121 }
122 else if (cmdline.toBool("refresh-all-rules"))
123 {
124 lookup->HandleAllRecordingRules();
126 }
127 else if (cmdline.toBool("refresh-all-artwork"))
128 {
129 lookup->HandleAllArtwork(false);
130 }
131 else if (cmdline.toBool("refresh-all-artwork-dangerously"))
132 {
133 lookup->HandleAllArtwork(true);
134 }
135 else
136 {
137 // refresh-all is default behavior if no other arguments given
139 lookup->HandleAllRecordings(cmdline.toBool("refresh-rules"));
140 }
141
142 while (lookup->StillWorking())
143 {
144 std::this_thread::sleep_for(1s);
145 qApp->processEvents();
146 }
147
148 LOG(VB_GENERAL, LOG_NOTICE, "MythMetadataLookup run complete.");
149
150 return GENERIC_EXIT_OK;
151}
static bool GetJobInfoFromID(int jobID, int &jobType, uint &chanid, QDateTime &recstartts)
Definition: jobqueue.cpp:680
static bool AllOK()
Definition: lookup.h:16
static void CopyRuleInetrefsToRecordings()
Definition: lookup.cpp:199
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
int toInt(const QString &key) const
Returns stored QVariant as an integer, falling to default if not provided.
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
static void PrintVersion(void)
Print application version information.
QDateTime toDateTime(const QString &key) const
Returns stored QVariant as a QDateTime, falling to default if not provided.
uint toUInt(const QString &key) const
Returns stored QVariant as an unsigned integer, falling to default if not provided.
void PrintHelp(void) const
Print command line option help.
Startup context for MythTV.
Definition: mythcontext.h:20
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
unsigned int uint
Definition: compat.h:60
#define close
Definition: compat.h:28
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:16
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
@ GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:14
@ JOB_METADATA
Definition: jobqueue.h:80
static constexpr const char * MYTH_APPNAME_MYTHMETADATALOOKUP
Definition: mythappname.h:18
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
int main(int argc, char *argv[])
bool myth_nice(int val)
MythCommFlagCommandLineParser cmdline