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#include <QCoreApplication>
12#include <QEventLoop>
13#ifdef Q_OS_DARWIN
14#include <QProcessEnvironment>
15#endif
16
17// MythTV
18#include "libmyth/mythcontext.h"
21#include "libmythbase/mythconfig.h"
22#include "libmythbase/mythdb.h"
26#include "libmythbase/mythversion.h"
27#include "libmythtv/jobqueue.h"
28
29// MythMetadataLookup
30#include "lookup.h"
32
33int main(int argc, char *argv[])
34{
36 if (!cmdline.Parse(argc, argv))
37 {
40 }
41
42 if (cmdline.toBool("showhelp"))
43 {
45 return GENERIC_EXIT_OK;
46 }
47
48 if (cmdline.toBool("showversion"))
49 {
51 return GENERIC_EXIT_OK;
52 }
53
54 QCoreApplication a(argc, argv);
55 QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHMETADATALOOKUP);
56
57#ifdef Q_OS_DARWIN
58 QString path = QCoreApplication::applicationDirPath();
59 setenv("PYTHONPATH",
60 QString("%1/../Resources/lib/%2:/../Resources/lib/%2/site-packages:/../Resources/lib/%2/lib-dynload:%3")
61 .arg(path)
62 .arg(QFileInfo(PYTHON_EXE).fileName())
63 .arg(QProcessEnvironment::systemEnvironment().value("PYTHONPATH"))
64 .toUtf8().constData(), 1);
65#endif
66
67 int retval = cmdline.ConfigureLogging();
68 if (retval != GENERIC_EXIT_OK)
69 return retval;
70
72 // Don't listen to console input
73 close(0);
74
75 MythContext context {MYTH_BINARY_VERSION};
76 if (!context.Init(false))
77 {
78 LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
80 }
81
82 myth_nice(19);
83
84 MythTranslation::load("mythfrontend");
85
86 std::unique_ptr<LookerUpper> lookup = std::make_unique<LookerUpper>();
87
88 LOG(VB_GENERAL, LOG_INFO,
89 "Testing grabbers and metadata sites for functionality...");
90 if (!LookerUpper::AllOK())
92 LOG(VB_GENERAL, LOG_INFO,
93 "All grabbers tested and working. Continuing...");
94
95 if (cmdline.toBool("jobid"))
96 {
97 uint chanid = 0;
98 QDateTime starttime;
99 int jobType = JOB_METADATA;
100
101 if (!JobQueue::GetJobInfoFromID(cmdline.toInt("jobid"), jobType,
102 chanid, starttime))
103 {
104 LOG(VB_GENERAL, LOG_INFO,
105 QString("No valid job found for jobid: %1")
106 .arg(cmdline.toInt("jobid")));
107 return GENERIC_EXIT_NOT_OK;
108 }
109
110 lookup->HandleSingleRecording(chanid, starttime,
111 cmdline.toBool("refresh-rules"));
112 }
113 else if (cmdline.toBool("chanid") && cmdline.toBool("starttime"))
114 {
115 lookup->HandleSingleRecording(cmdline.toUInt("chanid"),
116 cmdline.toDateTime("starttime"),
117 cmdline.toBool("refresh-rules"));
118 }
119 else if (cmdline.toBool("refresh-all-rules"))
120 {
121 lookup->HandleAllRecordingRules();
123 }
124 else if (cmdline.toBool("refresh-all-artwork"))
125 {
126 lookup->HandleAllArtwork(false);
127 }
128 else if (cmdline.toBool("refresh-all-artwork-dangerously"))
129 {
130 lookup->HandleAllArtwork(true);
131 }
132 else
133 {
134 // refresh-all is default behavior if no other arguments given
136 lookup->HandleAllRecordings(cmdline.toBool("refresh-rules"));
137 }
138
139 while (lookup->StillWorking())
140 {
141 std::this_thread::sleep_for(1s);
142 qApp->processEvents();
143 }
144
145 LOG(VB_GENERAL, LOG_NOTICE, "MythMetadataLookup run complete.");
146
147 return GENERIC_EXIT_OK;
148}
static bool GetJobInfoFromID(int jobID, int &jobType, uint &chanid, QDateTime &recstartts)
Definition: jobqueue.cpp:677
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
#define setenv(x, y, z)
Definition: compat.h:62
@ 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