Skip to content

Commit

Permalink
MythMetadataLookup: Perform mass grabs and updates or artwork.
Browse files Browse the repository at this point in the history
This adds two new options:

--refresh-all-artwork: Iterate through all recording rules and recordings, and queue those with inetrefs already set.  Of those, queue the remaining amount which have no artwork assigned to them in the database.  Download all available artwork for the remaining items and assign in the database.  This is the safe option, and it's the one you want to use.

--refresh-all-artwork-dangerously: Iterate through all recording rules and recordings, and queue everything.  If something doesn't have an inetref, attempt to look it up.  Queue anything without artwork already set in the database.  Set all found and downloaded artwork.

The above completes the transition from needing JAMU to perform random attempted grabs of artwork for recordings.  You can now set them statically if you want, look them all up automatically if you want, or use a mix of the two, setting the artwork you want when the grabber-assigned one isn't something you like.

For now, users of Jamu -MW should cron mythmetadatalookup --refresh-all-artwork.  In the very very near future, the housekeeper will handle this and no cron will be required whatsoever.
  • Loading branch information
Robert McNamara committed Jul 12, 2011
1 parent 3697089 commit d59d23f
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 15 deletions.
75 changes: 74 additions & 1 deletion mythtv/programs/mythmetadatalookup/lookup.cpp
Expand Up @@ -8,11 +8,13 @@
#include "jobqueue.h"
#include "remoteutil.h"

#include "metadataimagehelper.h"

#include "lookup.h"

LookerUpper::LookerUpper() :
m_busyRecList(QList<ProgramInfo*>()),
m_updaterules(false)
m_updaterules(false), m_updateartwork(false)
{
m_metadataFactory = new MetadataFactory(this);
}
Expand Down Expand Up @@ -104,6 +106,70 @@ void LookerUpper::HandleAllRecordingRules()
}
}

void LookerUpper::HandleAllArtwork(bool withinetrefsonly)
{
m_updateartwork = true;

// First, handle all recording rules w/ inetrefs
vector<ProgramInfo *> recordingList;

RemoteGetAllScheduledRecordings(recordingList);

for( int n = 0; n < (int)recordingList.size(); n++)
{
ProgramInfo *pginfo = new ProgramInfo(*(recordingList[n]));
bool dolookup = true;
if (withinetrefsonly && pginfo->GetInetRef().isEmpty())
dolookup = false;
if (dolookup)
{
ArtworkMap map = GetArtwork(pginfo->GetInetRef(), pginfo->GetSeason());
if (map.isEmpty())
{
QString msg = QString("Looking up artwork for recording rule: %1 %2")
.arg(pginfo->GetTitle())
.arg(pginfo->GetSubtitle());
LOG(VB_GENERAL, LOG_INFO, msg);

m_busyRecList.append(pginfo);
m_metadataFactory->Lookup(pginfo, false, true);
}
}
}

// Now, Attempt to fill in the gaps for recordings
QMap< QString, ProgramInfo* > recMap;
QMap< QString, uint32_t > inUseMap = ProgramInfo::QueryInUseMap();
QMap< QString, bool > isJobRunning = ProgramInfo::QueryJobsRunning(JOB_COMMFLAG);

ProgramList progList;

LoadFromRecorded( progList, false, inUseMap, isJobRunning, recMap, -1 );

for( int n = 0; n < (int)progList.size(); n++)
{
ProgramInfo *pginfo = new ProgramInfo(*(progList[n]));
bool dolookup = true;
if (withinetrefsonly && pginfo->GetInetRef().isEmpty())
dolookup = false;
if (dolookup)
{
ArtworkMap map = GetArtwork(pginfo->GetInetRef(), pginfo->GetSeason());
if (map.isEmpty())
{
QString msg = QString("Looking up artwork for recording: %1 %2")
.arg(pginfo->GetTitle())
.arg(pginfo->GetSubtitle());
LOG(VB_GENERAL, LOG_INFO, msg);

m_busyRecList.append(pginfo);
m_metadataFactory->Lookup(pginfo, false, true);
}
}
}

}

void LookerUpper::CopyRuleInetrefsToRecordings()
{
QMap< QString, ProgramInfo* > recMap;
Expand Down Expand Up @@ -210,6 +276,13 @@ void LookerUpper::customEvent(QEvent *levent)
delete rule;
}

if (m_updateartwork)
{
ArtworkMap map = lookup->GetDownloads();
SetArtwork(lookup->GetInetref(), lookup->GetSeason(),
gCoreContext->GetMasterHostName(), map);
}

m_busyRecList.removeAll(pginfo);
}
else if (levent->type() == MetadataFactoryNoResult::kEventType)
Expand Down
2 changes: 2 additions & 0 deletions mythtv/programs/mythmetadatalookup/lookup.h
Expand Up @@ -20,6 +20,7 @@ class LookerUpper : public QObject
bool updaterules = false);
void HandleAllRecordings(bool updaterules = false);
void HandleAllRecordingRules(void);
void HandleAllArtwork(bool withinetrefsonly = true);

void CopyRuleInetrefsToRecordings();

Expand All @@ -30,6 +31,7 @@ class LookerUpper : public QObject

QList<ProgramInfo*> m_busyRecList;
bool m_updaterules;
bool m_updateartwork;
};

#endif //LOOKUP_H_
71 changes: 57 additions & 14 deletions mythtv/programs/mythmetadatalookup/main.cpp
Expand Up @@ -57,6 +57,21 @@ void MythMetadataLookupCommandLineParser::LoadArguments(void)
"lookup. This is a best effort, and not guaranteed! If your "
"recordings lack inetrefs but one is found for the rule, it "
"will be inherited.", "");
add("--refresh-all-artwork", "refresh-all-artwork", false,
"Batch update artwork for recording rules and recording which "
"have an inetref set. No lookups will be performed on items "
"which don't already have an inetref. This is a more "
"conservative option that presumes you have set the inetrefs "
"you want for all of your recordings. This option will not "
"overwrite any existing artwork.", "");
add("--refresh-all-artwork-dangerously", "refresh-all-artwork-dangerously", false,
"Batch update artwork for ALL recording rules and recordings. "
"This will attempt to download fanart, coverart, and banner "
"for each season of each recording rule and all recordings. "
"This option will not overwrite any existing artwork. If a "
"rule or recording has not been looked up, this will attempt "
"to look it up. This is a very aggressive option! Use with "
"care.", "");
}

int main(int argc, char *argv[])
Expand Down Expand Up @@ -99,47 +114,67 @@ int main(int argc, char *argv[])
return GENERIC_EXIT_NO_MYTHCONTEXT;
}

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");
bool refreshall = cmdline.toBool("refresh-all");
bool refreshrules = cmdline.toBool("refresh-rules");
bool refreshallrules = cmdline.toBool("refresh-all-rules");
bool refreshallsafeart = cmdline.toBool("refresh-all-artwork");
bool refreshallart = cmdline.toBool("refresh-all-artwork-dangerously");
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");

if (refreshallrules && (refreshall || usedchanid || usedstarttime))
if (refreshallsafeart && (refreshall || refreshallrules ||
refreshallart || usedchanid || usedstarttime))
{
LOG(VB_GENERAL, LOG_ERR,
"--refresh-all-safe-art must not be accompanied by any other argument.");
return GENERIC_EXIT_INVALID_CMDLINE;
}

if (refreshallart && (refreshall || refreshallrules ||
refreshallsafeart || usedchanid || usedstarttime))
{
LOG(VB_GENERAL, LOG_ERR,
"--refresh-all-art must not be accompanied by any other argument.");
return GENERIC_EXIT_INVALID_CMDLINE;
}

if (refreshallrules && (refreshall || refreshallart ||
refreshallsafeart || 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))
if (refreshall && (refreshallrules || refreshallart ||
refreshallsafeart || usedchanid || usedstarttime))
{
LOG(VB_GENERAL, LOG_ERR,
"--refresh-all must not be accompanied by any other argument.");
return GENERIC_EXIT_INVALID_CMDLINE;
}

if (!addjob && !refreshall && !refreshallrules &&
!usedchanid && !usedstarttime)
if (!addjob && !refreshall && !refreshallrules && !refreshallart &&
!usedchanid && !usedstarttime && !refreshallsafeart)
{
refreshall = true;
}

if (addjob && (refreshall || refreshallrules || usedchanid ||
usedstarttime))
if (addjob && (refreshall || refreshallrules || refreshallart ||
refreshallsafeart || usedchanid || usedstarttime))
{
LOG(VB_GENERAL, LOG_ERR,
"The jobqueue (-j) command cannot be used with other options.");
return GENERIC_EXIT_INVALID_CMDLINE;
}

if (!refreshall && !refreshallrules && !addjob &&
!(usedchanid && usedstarttime))
if (!refreshall && !refreshallrules && !refreshallart && !addjob &&
!refreshallsafeart && !(usedchanid && usedstarttime))
{
LOG(VB_GENERAL, LOG_ERR,
"--chanid and --starttime must be used together.");
Expand Down Expand Up @@ -168,6 +203,14 @@ int main(int argc, char *argv[])
lookup->HandleAllRecordingRules();
lookup->CopyRuleInetrefsToRecordings();
}
else if (refreshallsafeart)
{
lookup->HandleAllArtwork(true);
}
else if (refreshallart)
{
lookup->HandleAllArtwork(false);
}
else
lookup->HandleSingleRecording(chanid, starttime, refreshrules);

Expand Down

0 comments on commit d59d23f

Please sign in to comment.