Skip to content

Commit ecfc2ba

Browse files
author
Robert McNamara
committed
MythMetadataLookup: add --refresh-rules and --refresh-all-rules options.
These very, very lightly tested options do the following: --refresh-rules: When an inetref is found for a recording, and the corresponding rule has no inetref, push the inetref back up to that rule. --refresh-all-rules: Iterate through all recording rules. If there are any without inetref, perform a lookup and attempt to update the inetref for the rule. This is a shortcut for legacy users to blast-update their rules... but it *is* a double edged sword. This provides no opportunity to verify against a list and there does exist some chance of false positives beyond doing so in a controlled way in the UI. In the UI, the user can force which lookup type will occur with the season and episode values. This option doesn't exist here. So, any use of this option is purely best-effort and completely non-guaranteed.
1 parent e717a49 commit ecfc2ba

File tree

3 files changed

+84
-19
lines changed

3 files changed

+84
-19
lines changed

mythtv/programs/mythmetadatalookup/lookup.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
#include <QList>
44

55
#include "programinfo.h"
6+
#include "recordingrule.h"
67
#include "mythlogging.h"
78
#include "jobqueue.h"
9+
#include "remoteutil.h"
810

911
#include "lookup.h"
1012

1113
LookerUpper::LookerUpper() :
12-
m_busyRecList(QList<ProgramInfo*>())
14+
m_busyRecList(QList<ProgramInfo*>()),
15+
m_updaterules(false)
1316
{
1417
m_metadataFactory = new MetadataFactory(this);
1518
}
@@ -30,7 +33,8 @@ bool LookerUpper::StillWorking()
3033
}
3134

3235
void LookerUpper::HandleSingleRecording(const uint chanid,
33-
const QDateTime starttime)
36+
const QDateTime starttime,
37+
bool updaterules)
3438
{
3539
ProgramInfo *pginfo = new ProgramInfo(chanid, starttime);
3640

@@ -41,16 +45,20 @@ void LookerUpper::HandleSingleRecording(const uint chanid,
4145
return;
4246
}
4347

48+
m_updaterules = updaterules;
49+
4450
m_busyRecList.append(pginfo);
4551
m_metadataFactory->Lookup(pginfo, false, false);
4652
}
4753

48-
void LookerUpper::HandleAllRecordings()
54+
void LookerUpper::HandleAllRecordings(bool updaterules)
4955
{
5056
QMap< QString, ProgramInfo* > recMap;
5157
QMap< QString, uint32_t > inUseMap = ProgramInfo::QueryInUseMap();
5258
QMap< QString, bool > isJobRunning = ProgramInfo::QueryJobsRunning(JOB_COMMFLAG);
5359

60+
m_updaterules = updaterules;
61+
5462
ProgramList progList;
5563

5664
LoadFromRecorded( progList, false, inUseMap, isJobRunning, recMap, -1 );
@@ -73,6 +81,29 @@ void LookerUpper::HandleAllRecordings()
7381
}
7482
}
7583

84+
void LookerUpper::HandleAllRecordingRules()
85+
{
86+
m_updaterules = true;
87+
88+
vector<ProgramInfo *> recordingList;
89+
90+
RemoteGetAllScheduledRecordings(recordingList);
91+
92+
for( int n = 0; n < (int)recordingList.size(); n++)
93+
{
94+
ProgramInfo *pginfo = new ProgramInfo(*(recordingList[n]));
95+
if (pginfo->GetInetRef().isEmpty())
96+
{
97+
QString msg = QString("Looking up: %1 %2").arg(pginfo->GetTitle())
98+
.arg(pginfo->GetSubtitle());
99+
LOG(VB_GENERAL, LOG_INFO, msg);
100+
101+
m_busyRecList.append(pginfo);
102+
m_metadataFactory->Lookup(pginfo, false, false);
103+
}
104+
}
105+
}
106+
76107
void LookerUpper::customEvent(QEvent *levent)
77108
{
78109
if (levent->type() == MetadataFactoryMultiResult::kEventType)
@@ -137,6 +168,16 @@ void LookerUpper::customEvent(QEvent *levent)
137168
pginfo->SaveSeasonEpisode(lookup->GetSeason(), lookup->GetEpisode());
138169
pginfo->SaveInetRef(lookup->GetInetref());
139170

171+
if (m_updaterules)
172+
{
173+
RecordingRule *rule = new RecordingRule();
174+
rule->LoadByProgram(pginfo);
175+
rule->m_inetref = lookup->GetInetref();
176+
rule->Save();
177+
178+
delete rule;
179+
}
180+
140181
m_busyRecList.removeAll(pginfo);
141182
}
142183
else if (levent->type() == MetadataFactoryNoResult::kEventType)

mythtv/programs/mythmetadatalookup/lookup.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ class LookerUpper : public QObject
1616
bool StillWorking();
1717

1818
void HandleSingleRecording(const uint chanid,
19-
const QDateTime starttime);
20-
void HandleAllRecordings();
19+
const QDateTime starttime,
20+
bool updaterules = false);
21+
void HandleAllRecordings(bool updaterules = false);
22+
void HandleAllRecordingRules(void);
2123

2224
private:
2325
void customEvent(QEvent *event);
2426

2527
MetadataFactory *m_metadataFactory;
2628

2729
QList<ProgramInfo*> m_busyRecList;
30+
bool m_updaterules;
2831
};
2932

3033
#endif //LOOKUP_H_

mythtv/programs/mythmetadatalookup/main.cpp

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ void MythMetadataLookupCommandLineParser::LoadArguments(void)
4545
addLogging();
4646

4747
add("--refresh-all", "refresh-all", false,
48-
"Refresh all recorded programs and recording rules metadata", "");
48+
"Batch update recorded program metadata.", "");
49+
add("--refresh-rules", "refresh-rules", false,
50+
"Also update inetref for recording rules when metadata is "
51+
"found for a recording (Best effort only, imperfect)", "");
52+
add("--refresh-all-rules", "refresh-all-rules", false,
53+
"Batch update metadata for recording rules. This will "
54+
"set inetrefs for your recording rules based on an automated "
55+
"lookup. This is a best effort, and not guaranteed!", "");
4956
}
5057

5158
int main(int argc, char *argv[])
@@ -88,35 +95,47 @@ int main(int argc, char *argv[])
8895
return GENERIC_EXIT_NO_MYTHCONTEXT;
8996
}
9097

91-
bool refreshall = cmdline.toBool("refresh-all");
92-
bool usedchanid = cmdline.toBool("chanid");
93-
bool usedstarttime = cmdline.toBool("starttime");
94-
bool addjob = cmdline.toBool("jobid");
98+
bool refreshall = cmdline.toBool("refresh-all");
99+
bool refreshrules = cmdline.toBool("refresh-rules");
100+
bool refreshallrules = cmdline.toBool("refresh-all-rules");
101+
bool usedchanid = cmdline.toBool("chanid");
102+
bool usedstarttime = cmdline.toBool("starttime");
103+
bool addjob = cmdline.toBool("jobid");
95104

96-
int jobid = cmdline.toInt("jobid");
97-
uint chanid = cmdline.toUInt("chanid");
98-
QDateTime starttime = cmdline.toDateTime("starttime");
105+
int jobid = cmdline.toInt("jobid");
106+
uint chanid = cmdline.toUInt("chanid");
107+
QDateTime starttime = cmdline.toDateTime("starttime");
108+
109+
if (refreshallrules && (refreshall || usedchanid || usedstarttime))
110+
{
111+
LOG(VB_GENERAL, LOG_ERR,
112+
"--refresh-all-rules must not be accompanied by any other argument.");
113+
return GENERIC_EXIT_INVALID_CMDLINE;
114+
}
99115

100116
if (refreshall && (usedchanid || usedstarttime))
101117
{
102118
LOG(VB_GENERAL, LOG_ERR,
103-
"--refresh-all must not be accompanied by --chanid or --starttime");
119+
"--refresh-all must not be accompanied by any other argument.");
104120
return GENERIC_EXIT_INVALID_CMDLINE;
105121
}
106122

107-
if (!addjob && !refreshall && !usedchanid && !usedstarttime)
123+
if (!addjob && !refreshall && !refreshallrules &&
124+
!usedchanid && !usedstarttime)
108125
{
109126
refreshall = true;
110127
}
111128

112-
if (addjob && (refreshall || usedchanid || usedstarttime))
129+
if (addjob && (refreshall || refreshallrules || usedchanid ||
130+
usedstarttime))
113131
{
114132
LOG(VB_GENERAL, LOG_ERR,
115133
"The jobqueue (-j) command cannot be used with other options.");
116134
return GENERIC_EXIT_INVALID_CMDLINE;
117135
}
118136

119-
if (!refreshall && !addjob && !(usedchanid && usedstarttime))
137+
if (!refreshall && !refreshallrules && !addjob &&
138+
!(usedchanid && usedstarttime))
120139
{
121140
LOG(VB_GENERAL, LOG_ERR,
122141
"--chanid and --starttime must be used together.");
@@ -136,9 +155,11 @@ int main(int argc, char *argv[])
136155
}
137156

138157
if (refreshall)
139-
lookup->HandleAllRecordings();
158+
lookup->HandleAllRecordings(refreshrules);
159+
else if (refreshallrules)
160+
lookup->HandleAllRecordingRules();
140161
else
141-
lookup->HandleSingleRecording(chanid, starttime);
162+
lookup->HandleSingleRecording(chanid, starttime, refreshrules);
142163

143164
while (lookup->StillWorking())
144165
{

0 commit comments

Comments
 (0)