Skip to content
Browse files

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.
  • Loading branch information...
1 parent e717a49 commit ecfc2bab99cb2459a0fa817dd6f586c69055a641 Robert McNamara committed Jul 10, 2011
View
47 mythtv/programs/mythmetadatalookup/lookup.cpp
@@ -3,13 +3,16 @@
#include <QList>
#include "programinfo.h"
+#include "recordingrule.h"
#include "mythlogging.h"
#include "jobqueue.h"
+#include "remoteutil.h"
#include "lookup.h"
LookerUpper::LookerUpper() :
- m_busyRecList(QList<ProgramInfo*>())
+ m_busyRecList(QList<ProgramInfo*>()),
+ m_updaterules(false)
{
m_metadataFactory = new MetadataFactory(this);
}
@@ -30,7 +33,8 @@ bool LookerUpper::StillWorking()
}
void LookerUpper::HandleSingleRecording(const uint chanid,
- const QDateTime starttime)
+ const QDateTime starttime,
+ bool updaterules)
{
ProgramInfo *pginfo = new ProgramInfo(chanid, starttime);
@@ -41,16 +45,20 @@ void LookerUpper::HandleSingleRecording(const uint chanid,
return;
}
+ m_updaterules = updaterules;
+
m_busyRecList.append(pginfo);
m_metadataFactory->Lookup(pginfo, false, false);
}
-void LookerUpper::HandleAllRecordings()
+void LookerUpper::HandleAllRecordings(bool updaterules)
{
QMap< QString, ProgramInfo* > recMap;
QMap< QString, uint32_t > inUseMap = ProgramInfo::QueryInUseMap();
QMap< QString, bool > isJobRunning = ProgramInfo::QueryJobsRunning(JOB_COMMFLAG);
+ m_updaterules = updaterules;
+
ProgramList progList;
LoadFromRecorded( progList, false, inUseMap, isJobRunning, recMap, -1 );
@@ -73,6 +81,29 @@ void LookerUpper::HandleAllRecordings()
}
}
+void LookerUpper::HandleAllRecordingRules()
+{
+ m_updaterules = true;
+
+ vector<ProgramInfo *> recordingList;
+
+ RemoteGetAllScheduledRecordings(recordingList);
+
+ for( int n = 0; n < (int)recordingList.size(); n++)
+ {
+ ProgramInfo *pginfo = new ProgramInfo(*(recordingList[n]));
+ if (pginfo->GetInetRef().isEmpty())
+ {
+ QString msg = QString("Looking up: %1 %2").arg(pginfo->GetTitle())
+ .arg(pginfo->GetSubtitle());
+ LOG(VB_GENERAL, LOG_INFO, msg);
+
+ m_busyRecList.append(pginfo);
+ m_metadataFactory->Lookup(pginfo, false, false);
+ }
+ }
+}
+
void LookerUpper::customEvent(QEvent *levent)
{
if (levent->type() == MetadataFactoryMultiResult::kEventType)
@@ -137,6 +168,16 @@ void LookerUpper::customEvent(QEvent *levent)
pginfo->SaveSeasonEpisode(lookup->GetSeason(), lookup->GetEpisode());
pginfo->SaveInetRef(lookup->GetInetref());
+ if (m_updaterules)
+ {
+ RecordingRule *rule = new RecordingRule();
+ rule->LoadByProgram(pginfo);
+ rule->m_inetref = lookup->GetInetref();
+ rule->Save();
+
+ delete rule;
+ }
+
m_busyRecList.removeAll(pginfo);
}
else if (levent->type() == MetadataFactoryNoResult::kEventType)
View
7 mythtv/programs/mythmetadatalookup/lookup.h
@@ -16,15 +16,18 @@ class LookerUpper : public QObject
bool StillWorking();
void HandleSingleRecording(const uint chanid,
- const QDateTime starttime);
- void HandleAllRecordings();
+ const QDateTime starttime,
+ bool updaterules = false);
+ void HandleAllRecordings(bool updaterules = false);
+ void HandleAllRecordingRules(void);
private:
void customEvent(QEvent *event);
MetadataFactory *m_metadataFactory;
QList<ProgramInfo*> m_busyRecList;
+ bool m_updaterules;
};
#endif //LOOKUP_H_
View
49 mythtv/programs/mythmetadatalookup/main.cpp
@@ -45,7 +45,14 @@ void MythMetadataLookupCommandLineParser::LoadArguments(void)
addLogging();
add("--refresh-all", "refresh-all", false,
- "Refresh all recorded programs and recording rules metadata", "");
+ "Batch update recorded program metadata.", "");
+ add("--refresh-rules", "refresh-rules", false,
+ "Also update inetref for recording rules when metadata is "
+ "found for a recording (Best effort only, imperfect)", "");
+ add("--refresh-all-rules", "refresh-all-rules", false,
+ "Batch update metadata for recording rules. This will "
+ "set inetrefs for your recording rules based on an automated "
+ "lookup. This is a best effort, and not guaranteed!", "");
}
int main(int argc, char *argv[])
@@ -88,35 +95,47 @@ int main(int argc, char *argv[])
return GENERIC_EXIT_NO_MYTHCONTEXT;
}
- bool refreshall = cmdline.toBool("refresh-all");
- bool usedchanid = cmdline.toBool("chanid");
- bool usedstarttime = cmdline.toBool("starttime");
- bool addjob = cmdline.toBool("jobid");
+ bool refreshall = cmdline.toBool("refresh-all");
+ bool refreshrules = cmdline.toBool("refresh-rules");
+ bool refreshallrules = cmdline.toBool("refresh-all-rules");
+ bool usedchanid = cmdline.toBool("chanid");
+ bool usedstarttime = cmdline.toBool("starttime");
+ bool addjob = cmdline.toBool("jobid");
- int jobid = cmdline.toInt("jobid");
- uint chanid = cmdline.toUInt("chanid");
- QDateTime starttime = cmdline.toDateTime("starttime");
+ int jobid = cmdline.toInt("jobid");
+ uint chanid = cmdline.toUInt("chanid");
+ QDateTime starttime = cmdline.toDateTime("starttime");
+
+ if (refreshallrules && (refreshall || usedchanid || usedstarttime))
+ {
+ LOG(VB_GENERAL, LOG_ERR,
+ "--refresh-all-rules must not be accompanied by any other argument.");
+ return GENERIC_EXIT_INVALID_CMDLINE;
+ }
if (refreshall && (usedchanid || usedstarttime))
{
LOG(VB_GENERAL, LOG_ERR,
- "--refresh-all must not be accompanied by --chanid or --starttime");
+ "--refresh-all must not be accompanied by any other argument.");
return GENERIC_EXIT_INVALID_CMDLINE;
}
- if (!addjob && !refreshall && !usedchanid && !usedstarttime)
+ if (!addjob && !refreshall && !refreshallrules &&
+ !usedchanid && !usedstarttime)
{
refreshall = true;
}
- if (addjob && (refreshall || usedchanid || usedstarttime))
+ if (addjob && (refreshall || refreshallrules || usedchanid ||
+ usedstarttime))
{
LOG(VB_GENERAL, LOG_ERR,
"The jobqueue (-j) command cannot be used with other options.");
return GENERIC_EXIT_INVALID_CMDLINE;
}
- if (!refreshall && !addjob && !(usedchanid && usedstarttime))
+ if (!refreshall && !refreshallrules && !addjob &&
+ !(usedchanid && usedstarttime))
{
LOG(VB_GENERAL, LOG_ERR,
"--chanid and --starttime must be used together.");
@@ -136,9 +155,11 @@ int main(int argc, char *argv[])
}
if (refreshall)
- lookup->HandleAllRecordings();
+ lookup->HandleAllRecordings(refreshrules);
+ else if (refreshallrules)
+ lookup->HandleAllRecordingRules();
else
- lookup->HandleSingleRecording(chanid, starttime);
+ lookup->HandleSingleRecording(chanid, starttime, refreshrules);
while (lookup->StillWorking())
{

0 comments on commit ecfc2ba

Please sign in to comment.
Something went wrong with that request. Please try again.