Skip to content

Commit d59d23f

Browse files
author
Robert McNamara
committed
MythMetadataLookup: Perform mass grabs and updates or artwork.
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.
1 parent 3697089 commit d59d23f

File tree

3 files changed

+133
-15
lines changed

3 files changed

+133
-15
lines changed

mythtv/programs/mythmetadatalookup/lookup.cpp

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
#include "jobqueue.h"
99
#include "remoteutil.h"
1010

11+
#include "metadataimagehelper.h"
12+
1113
#include "lookup.h"
1214

1315
LookerUpper::LookerUpper() :
1416
m_busyRecList(QList<ProgramInfo*>()),
15-
m_updaterules(false)
17+
m_updaterules(false), m_updateartwork(false)
1618
{
1719
m_metadataFactory = new MetadataFactory(this);
1820
}
@@ -104,6 +106,70 @@ void LookerUpper::HandleAllRecordingRules()
104106
}
105107
}
106108

109+
void LookerUpper::HandleAllArtwork(bool withinetrefsonly)
110+
{
111+
m_updateartwork = true;
112+
113+
// First, handle all recording rules w/ inetrefs
114+
vector<ProgramInfo *> recordingList;
115+
116+
RemoteGetAllScheduledRecordings(recordingList);
117+
118+
for( int n = 0; n < (int)recordingList.size(); n++)
119+
{
120+
ProgramInfo *pginfo = new ProgramInfo(*(recordingList[n]));
121+
bool dolookup = true;
122+
if (withinetrefsonly && pginfo->GetInetRef().isEmpty())
123+
dolookup = false;
124+
if (dolookup)
125+
{
126+
ArtworkMap map = GetArtwork(pginfo->GetInetRef(), pginfo->GetSeason());
127+
if (map.isEmpty())
128+
{
129+
QString msg = QString("Looking up artwork for recording rule: %1 %2")
130+
.arg(pginfo->GetTitle())
131+
.arg(pginfo->GetSubtitle());
132+
LOG(VB_GENERAL, LOG_INFO, msg);
133+
134+
m_busyRecList.append(pginfo);
135+
m_metadataFactory->Lookup(pginfo, false, true);
136+
}
137+
}
138+
}
139+
140+
// Now, Attempt to fill in the gaps for recordings
141+
QMap< QString, ProgramInfo* > recMap;
142+
QMap< QString, uint32_t > inUseMap = ProgramInfo::QueryInUseMap();
143+
QMap< QString, bool > isJobRunning = ProgramInfo::QueryJobsRunning(JOB_COMMFLAG);
144+
145+
ProgramList progList;
146+
147+
LoadFromRecorded( progList, false, inUseMap, isJobRunning, recMap, -1 );
148+
149+
for( int n = 0; n < (int)progList.size(); n++)
150+
{
151+
ProgramInfo *pginfo = new ProgramInfo(*(progList[n]));
152+
bool dolookup = true;
153+
if (withinetrefsonly && pginfo->GetInetRef().isEmpty())
154+
dolookup = false;
155+
if (dolookup)
156+
{
157+
ArtworkMap map = GetArtwork(pginfo->GetInetRef(), pginfo->GetSeason());
158+
if (map.isEmpty())
159+
{
160+
QString msg = QString("Looking up artwork for recording: %1 %2")
161+
.arg(pginfo->GetTitle())
162+
.arg(pginfo->GetSubtitle());
163+
LOG(VB_GENERAL, LOG_INFO, msg);
164+
165+
m_busyRecList.append(pginfo);
166+
m_metadataFactory->Lookup(pginfo, false, true);
167+
}
168+
}
169+
}
170+
171+
}
172+
107173
void LookerUpper::CopyRuleInetrefsToRecordings()
108174
{
109175
QMap< QString, ProgramInfo* > recMap;
@@ -210,6 +276,13 @@ void LookerUpper::customEvent(QEvent *levent)
210276
delete rule;
211277
}
212278

279+
if (m_updateartwork)
280+
{
281+
ArtworkMap map = lookup->GetDownloads();
282+
SetArtwork(lookup->GetInetref(), lookup->GetSeason(),
283+
gCoreContext->GetMasterHostName(), map);
284+
}
285+
213286
m_busyRecList.removeAll(pginfo);
214287
}
215288
else if (levent->type() == MetadataFactoryNoResult::kEventType)

mythtv/programs/mythmetadatalookup/lookup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class LookerUpper : public QObject
2020
bool updaterules = false);
2121
void HandleAllRecordings(bool updaterules = false);
2222
void HandleAllRecordingRules(void);
23+
void HandleAllArtwork(bool withinetrefsonly = true);
2324

2425
void CopyRuleInetrefsToRecordings();
2526

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

3132
QList<ProgramInfo*> m_busyRecList;
3233
bool m_updaterules;
34+
bool m_updateartwork;
3335
};
3436

3537
#endif //LOOKUP_H_

mythtv/programs/mythmetadatalookup/main.cpp

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ void MythMetadataLookupCommandLineParser::LoadArguments(void)
5757
"lookup. This is a best effort, and not guaranteed! If your "
5858
"recordings lack inetrefs but one is found for the rule, it "
5959
"will be inherited.", "");
60+
add("--refresh-all-artwork", "refresh-all-artwork", false,
61+
"Batch update artwork for recording rules and recording which "
62+
"have an inetref set. No lookups will be performed on items "
63+
"which don't already have an inetref. This is a more "
64+
"conservative option that presumes you have set the inetrefs "
65+
"you want for all of your recordings. This option will not "
66+
"overwrite any existing artwork.", "");
67+
add("--refresh-all-artwork-dangerously", "refresh-all-artwork-dangerously", false,
68+
"Batch update artwork for ALL recording rules and recordings. "
69+
"This will attempt to download fanart, coverart, and banner "
70+
"for each season of each recording rule and all recordings. "
71+
"This option will not overwrite any existing artwork. If a "
72+
"rule or recording has not been looked up, this will attempt "
73+
"to look it up. This is a very aggressive option! Use with "
74+
"care.", "");
6075
}
6176

6277
int main(int argc, char *argv[])
@@ -99,47 +114,67 @@ int main(int argc, char *argv[])
99114
return GENERIC_EXIT_NO_MYTHCONTEXT;
100115
}
101116

102-
bool refreshall = cmdline.toBool("refresh-all");
103-
bool refreshrules = cmdline.toBool("refresh-rules");
104-
bool refreshallrules = cmdline.toBool("refresh-all-rules");
105-
bool usedchanid = cmdline.toBool("chanid");
106-
bool usedstarttime = cmdline.toBool("starttime");
107-
bool addjob = cmdline.toBool("jobid");
117+
bool refreshall = cmdline.toBool("refresh-all");
118+
bool refreshrules = cmdline.toBool("refresh-rules");
119+
bool refreshallrules = cmdline.toBool("refresh-all-rules");
120+
bool refreshallsafeart = cmdline.toBool("refresh-all-artwork");
121+
bool refreshallart = cmdline.toBool("refresh-all-artwork-dangerously");
122+
bool usedchanid = cmdline.toBool("chanid");
123+
bool usedstarttime = cmdline.toBool("starttime");
124+
bool addjob = cmdline.toBool("jobid");
108125

109126
int jobid = cmdline.toInt("jobid");
110127
uint chanid = cmdline.toUInt("chanid");
111128
QDateTime starttime = cmdline.toDateTime("starttime");
112129

113-
if (refreshallrules && (refreshall || usedchanid || usedstarttime))
130+
if (refreshallsafeart && (refreshall || refreshallrules ||
131+
refreshallart || usedchanid || usedstarttime))
132+
{
133+
LOG(VB_GENERAL, LOG_ERR,
134+
"--refresh-all-safe-art must not be accompanied by any other argument.");
135+
return GENERIC_EXIT_INVALID_CMDLINE;
136+
}
137+
138+
if (refreshallart && (refreshall || refreshallrules ||
139+
refreshallsafeart || usedchanid || usedstarttime))
140+
{
141+
LOG(VB_GENERAL, LOG_ERR,
142+
"--refresh-all-art must not be accompanied by any other argument.");
143+
return GENERIC_EXIT_INVALID_CMDLINE;
144+
}
145+
146+
if (refreshallrules && (refreshall || refreshallart ||
147+
refreshallsafeart || usedchanid || usedstarttime))
114148
{
115149
LOG(VB_GENERAL, LOG_ERR,
116150
"--refresh-all-rules must not be accompanied by any other argument.");
117151
return GENERIC_EXIT_INVALID_CMDLINE;
118152
}
119153

120-
if (refreshall && (usedchanid || usedstarttime))
154+
if (refreshall && (refreshallrules || refreshallart ||
155+
refreshallsafeart || usedchanid || usedstarttime))
121156
{
122157
LOG(VB_GENERAL, LOG_ERR,
123158
"--refresh-all must not be accompanied by any other argument.");
124159
return GENERIC_EXIT_INVALID_CMDLINE;
125160
}
126161

127-
if (!addjob && !refreshall && !refreshallrules &&
128-
!usedchanid && !usedstarttime)
162+
if (!addjob && !refreshall && !refreshallrules && !refreshallart &&
163+
!usedchanid && !usedstarttime && !refreshallsafeart)
129164
{
130165
refreshall = true;
131166
}
132167

133-
if (addjob && (refreshall || refreshallrules || usedchanid ||
134-
usedstarttime))
168+
if (addjob && (refreshall || refreshallrules || refreshallart ||
169+
refreshallsafeart || usedchanid || usedstarttime))
135170
{
136171
LOG(VB_GENERAL, LOG_ERR,
137172
"The jobqueue (-j) command cannot be used with other options.");
138173
return GENERIC_EXIT_INVALID_CMDLINE;
139174
}
140175

141-
if (!refreshall && !refreshallrules && !addjob &&
142-
!(usedchanid && usedstarttime))
176+
if (!refreshall && !refreshallrules && !refreshallart && !addjob &&
177+
!refreshallsafeart && !(usedchanid && usedstarttime))
143178
{
144179
LOG(VB_GENERAL, LOG_ERR,
145180
"--chanid and --starttime must be used together.");
@@ -168,6 +203,14 @@ int main(int argc, char *argv[])
168203
lookup->HandleAllRecordingRules();
169204
lookup->CopyRuleInetrefsToRecordings();
170205
}
206+
else if (refreshallsafeart)
207+
{
208+
lookup->HandleAllArtwork(true);
209+
}
210+
else if (refreshallart)
211+
{
212+
lookup->HandleAllArtwork(false);
213+
}
171214
else
172215
lookup->HandleSingleRecording(chanid, starttime, refreshrules);
173216

0 commit comments

Comments
 (0)