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