MythTV  master
metadatacommon.h
Go to the documentation of this file.
1 #ifndef METADATACOMMON_H_
2 #define METADATACOMMON_H_
3 
4 // c++
5 #include <utility>
6 
7 // qt
8 #include <QDate>
9 #include <QDateTime>
10 #include <QDomElement>
11 #include <QEvent>
12 #include <QList>
13 #include <QMultiMap>
14 #include <QPair>
15 #include <QString>
16 #include <QStringList>
17 
18 #include "mythtypes.h"
19 #include "mythmetaexp.h"
20 #include "metadataimagehelper.h"
21 #include "referencecounterlist.h"
22 #include "metadatagrabber.h"
23 
24 class ProgramInfo;
25 
26 enum LookupStep {
30 };
31 
32 struct PersonInfo
33 {
34  QString name;
35  QString role;
36  QString thumbnail;
37  QString url;
38 };
39 
40 // What type of grabber script to use
46 };
47 
48 // Determines the lookup fallback strategy
49 enum LookupType {
56 };
57 
58 // Actual type of content
66 };
67 
68 enum PeopleType {
81 };
82 
83 using DownloadMap = QMap< VideoArtworkType, ArtworkInfo >;
84 using PeopleMap = QMultiMap< PeopleType, PersonInfo >;
85 
86 class META_PUBLIC MetadataLookup : public QObject, public ReferenceCounter
87 {
88  public:
89  MetadataLookup(void) : ReferenceCounter("MetadataLookup") {}
90  ~MetadataLookup() override = default;
91 
94  LookupType subtype,
95  QVariant data,
96  LookupStep step,
97  bool automatic,
98  bool handleimages,
99  bool allowoverwrites,
100  bool allowgeneric,
101  bool preferdvdorder,
102  QString host,
103  QString filename,
104  const QString &title,
105  QString network,
106  QString status,
107  QStringList categories,
108  float userrating,
109  uint ratingcount,
110  QString language,
111  QString subtitle,
112  QString tagline,
113  QString description,
114  uint season,
115  uint episode,
116  uint chanid,
117  QString channum,
118  QString chansign,
119  QString channame,
120  QString chanplaybackfilters,
121  QString recgroup,
122  QString playgroup,
123  QString seriesid,
124  QString programid,
125  QString storagegroup,
126  QDateTime startts,
127  QDateTime endts,
128  QDateTime recstartts,
129  QDateTime recendts,
130  uint programflags,
131  uint audioproperties,
132  uint videoproperties,
133  uint subtitletype,
134  QString certification,
135  QStringList countries,
136  float popularity,
137  uint budget,
138  uint revenue,
139  QString album,
140  uint tracknum,
141  QString system,
142  uint year,
143  const QDate &releasedate,
144  QDateTime lastupdated,
145  uint runtime,
146  uint runtimesecs,
147  QString inetref,
148  QString collectionref,
149  QString tmsref,
150  QString imdb,
151  PeopleMap people,
152  QStringList studios,
153  QString homepage,
154  QString trailerURL,
155  ArtworkMap artwork,
156  DownloadMap downloads);
157 
158  //ProgramInfo Constructor
161  LookupType subtype,
162  QVariant data,
163  LookupStep step,
164  bool automatic,
165  bool handleimages,
166  bool allowoverwrites,
167  bool allowgeneric,
168  bool preferdvdorder,
169  QString host,
170  QString filename,
171  const QString &title,
172  QStringList categories,
173  float userrating,
174  QString subtitle,
175  QString description,
176  uint chanid,
177  QString channum,
178  QString chansign,
179  QString channame,
180  QString chanplaybackfilters,
181  QString recgroup,
182  QString playgroup,
183  QString seriesid,
184  QString programid,
185  QString storagegroup,
186  QDateTime startts,
187  QDateTime endts,
188  QDateTime recstartts,
189  QDateTime recendts,
190  uint programflags,
191  uint audioproperties,
192  uint videoproperties,
193  uint subtitletype,
194  uint year,
195  const QDate &releasedate,
196  QDateTime lastupdated,
197  uint runtime,
198  uint runtimesecs);
199 
200  // XBMC NFO Constructor
203  LookupType subtype,
204  QVariant data,
205  LookupStep step,
206  bool automatic,
207  bool handleimages,
208  bool allowoverwrites,
209  bool allowgeneric,
210  bool preferdvdorder,
211  QString host,
212  QString filename,
213  const QString &title,
214  QStringList categories,
215  float userrating,
216  QString subtitle,
217  QString tagline,
218  QString description,
219  uint season,
220  uint episode,
221  QString certification,
222  uint year,
223  QDate releasedate,
224  uint runtime,
225  uint runtimesecs,
226  QString inetref,
227  PeopleMap people,
228  QString trailerURL,
229  ArtworkMap artwork,
230  DownloadMap downloads);
231 
232  void toMap(InfoMap &map);
233 
234  // SETS (Only a limited number needed)
235 
236  // Must set a type, data, and step.
237  void SetType(MetadataType type) { m_type = type; };
238  // For some lookup, it helps to know the subtype (TV vs. Movie)
239  void SetSubtype(LookupType subtype) { m_subtype = subtype; };
240  // Reference value- when the event comes back, need to associate with an item.
241  void SetData(QVariant data) { m_data = std::move(data); };
242  // Steps: SEARCH, GETDATA
243  void SetStep(LookupStep step) { m_step = step; };
244  // Don't prompt the user, just make an educated decision.
245  void SetAutomatic(bool autom) { m_automatic = autom; };
246 
247  // Sets for image download handling
248  void SetHandleImages(bool handle) { m_handleImages = handle; };
249  void SetAllowOverwrites(bool allow) { m_allowOverwrites = allow; };
250  void SetAllowGeneric(bool allow) { m_allowGeneric = allow; };
251  void SetHost(const QString &host) { m_host = host; };
252  void SetDownloads(ArtworkMap map) { m_downloads = std::move(map); };
253 
254  // General Sets
255  void SetTitle(const QString &title)
256  {
257  m_title = title;
258  QString manRecSuffix = QString(" (%1)").arg(QObject::tr("Manual Record"));
259  m_baseTitle = title; // m_title with " (Manual Record)" stripped.
260  m_baseTitle.replace(manRecSuffix,"");
261  };
262  void SetFilename(const QString &filename) { m_filename = filename; };
263 
264  // General Sets - Video
265  void SetSubtitle(const QString &subtitle) { m_subtitle = subtitle; };
266  void SetSeason(uint season) { m_season = season; };
267  void SetEpisode(uint episode) { m_episode = episode; };
268  void SetInetref(const QString &inetref) { m_inetRef = inetref; };
269  void SetCollectionref(const QString &collectionref)
270  { m_collectionRef = collectionref; };
271  void SetTMSref(const QString &tmsref) { m_tmsRef = tmsref; };
272  void SetIsCollection(bool collection) { m_isCollection = collection; };
273  void SetPreferDVDOrdering(bool preferdvdorder)
274  { m_dvdOrder = preferdvdorder; };
275 
276  // General Sets - Music
277  void SetAlbum(const QString &album) { m_album = album; };
278  void SetTrack(uint track) { m_trackNum = track; };
279 
280  // General Sets - Games
281  void SetSystem(const QString &system) { m_system = system; };
282 
283  // GETS
284 
285  MetadataType GetType() const { return m_type; };
286  LookupType GetSubtype() const { return m_subtype; };
287  QVariant GetData() const { return m_data; };
288  LookupStep GetStep() const { return m_step; };
289  bool GetAutomatic() const { return m_automatic; };
290 
291  // Image Handling Gets
292  bool GetHandleImages() const { return m_handleImages; };
293  bool GetAllowOverwrites() const { return m_allowOverwrites; };
294  bool GetAllowGeneric() const { return m_allowGeneric; };
295 
296  // General
297  QString GetFilename() const { return m_filename; };
298  QString GetTitle() const { return m_title; };
299  QString GetBaseTitle() const { return m_baseTitle; };
300  QStringList GetCategories() const { return m_categories; };
301  float GetUserRating() const { return m_userRating; };
302  uint GetRatingCount() const { return m_ratingCount; };
303  QString GetLanguage() const { return m_language; };
304  QString GetHost() const { return m_host; };
305 
306  // General - Video & ProgramInfo
307  QString GetNetwork() const { return m_network; };
308  QString GetStatus() const { return m_status; };
309  QString GetSubtitle() const { return m_subtitle; };
310  QString GetTagline() const { return m_tagline; };
311  QString GetDescription() const { return m_description; };
312  bool GetPreferDVDOrdering() const { return m_dvdOrder; };
313  uint GetSeason() const { return m_season; };
314  uint GetEpisode() const { return m_episode; };
315  uint GetChanId() const { return m_chanId; };
316  QString GetChanNum() const { return m_chanNum; };
317  QString GetChanSign() const { return m_chanSign; };
318  QString GetChanName() const { return m_chanName; };
319  QString GetChanPlaybackFilters() const { return m_chanPlaybackFilters; };
320  QString GetRecGroup() const { return m_recGroup; };
321  QString GetPlayGroup() const { return m_playGroup; };
322  QString GetSeriesId() const { return m_seriesId; };
323  QString GetProgramId() const { return m_programid; };
324  QString GetStorageGroup() const { return m_storageGroup; };
325  QDateTime GetStartTS() const { return m_startTs; };
326  QDateTime GetEndTS() const { return m_endTs; };
327  QDateTime GetRecStartTS() const { return m_recStartTs; };
328  QDateTime GetRecEndTS() const { return m_recEndTs; };
329  uint GetProgramFlags() const { return m_programFlags; };
330  uint GetAudioProperties() const { return m_audioProperties; };
331  uint GetVideoProperties() const { return m_videoProperties; };
332  uint GetSubtitleType() const { return m_subtitleType; };
333 
334  QString GetCertification() const { return m_certification; };
335  QStringList GetCountries() const { return m_countries; };
336  float GetPopularity() const { return m_popularity; };
337  uint GetBudget() const { return m_budget; };
338  uint GetRevenue() const { return m_revenue; };
339 
340  // General - Music
341  QString GetAlbumTitle() const { return m_album; };
342  uint GetTrackNumber() const { return m_trackNum; };
343 
344  // General - Game
345  QString GetSystem() const { return m_system; };
346 
347  // Times
348  uint GetYear() const { return m_year; };
349  QDate GetReleaseDate() const { return m_releaseDate; };
350  QDateTime GetLastUpdated() const { return m_lastUpdated; };
351  uint GetRuntime() const { return m_runtime; };
352  uint GetRuntimeSeconds() const { return m_runtimeSecs; };
353 
354  // Inetref
355  QString GetInetref() const { return m_inetRef; };
356  QString GetCollectionref() const { return m_collectionRef; };
357  QString GetIMDB() const { return m_imdb; };
358  QString GetTMSref() const { return m_tmsRef; };
359  bool GetIsCollection() const { return m_isCollection; };
360 
361  // People
362  QList<PersonInfo> GetPeople(PeopleType type) const;
363  QStringList GetStudios() const { return m_studios; };
364 
365  // Web references
366  QString GetHomepage() const { return m_homepage; };
367  QString GetTrailerURL() const { return m_trailerURL; };
368 
369  // Artwork
371  DownloadMap GetDownloads() const { return m_downloads; };
372 
373  private:
374  // General
377  QVariant m_data;
379  bool m_automatic {false};
380  bool m_handleImages {false};
381  bool m_allowOverwrites {false};
382  bool m_allowGeneric {false};
383  bool m_dvdOrder {false};
384  QString m_host;
385 
386  QString m_filename;
387  QString m_title;
388  QString m_baseTitle; // m_title with " (Manual Record)" stripped.
389  QString m_network;
390  QString m_status;
391  const QStringList m_categories;
392  float m_userRating {0.0};
393  uint m_ratingCount {0};
394  const QString m_language;
395 
396  // General - Video & ProgramInfo
397  QString m_subtitle;
398  const QString m_tagline;
399  const QString m_description;
400  uint m_season {0};
401  uint m_episode {0};
402  uint m_chanId {0};
403  const QString m_chanNum;
404  const QString m_chanSign;
405  const QString m_chanName;
406  const QString m_chanPlaybackFilters;
407  const QString m_recGroup;
408  const QString m_playGroup;
409  const QString m_seriesId;
410  const QString m_programid;
411  const QString m_storageGroup;
412  const QDateTime m_startTs;
413  const QDateTime m_endTs;
414  const QDateTime m_recStartTs;
415  const QDateTime m_recEndTs;
416  uint m_programFlags {0};
417  uint m_audioProperties {0};
418  uint m_videoProperties {0};
419  uint m_subtitleType {0};
420 
421  const QString m_certification;
422  const QStringList m_countries;
423  float m_popularity {0};
424  uint m_budget {0};
425  uint m_revenue {0};
426 
427  // General - Music
428  QString m_album;
429  uint m_trackNum {0};
430 
431  // General - Game
432  QString m_system;
433 
434  // Times
435  uint m_year {0};
436  const QDate m_releaseDate;
437  const QDateTime m_lastUpdated;
438  uint m_runtime {0};
439  uint m_runtimeSecs {0};
440 
441  // Inetref
442  QString m_inetRef;
444  QString m_tmsRef;
445  QString m_imdb;
446  bool m_isCollection {false};
447 
448  // People - Video
450  const QStringList m_studios;
451 
452  // Web references
453  const QString m_homepage;
454  const QString m_trailerURL;
455 
456  // Artwork
459 };
460 
462 
464 META_PUBLIC QDomDocument CreateMetadataXML(MetadataLookup *lookup);
465 META_PUBLIC QDomDocument CreateMetadataXML(ProgramInfo *pginfo);
466 
468  QDomElement placetoadd,
469  QDomDocument docroot);
470 
472  QDomElement placetoadd,
473  QDomDocument docroot);
475  QDomElement placetoadd,
476  QDomDocument docroot);
478  QDomElement placetoadd,
479  QDomDocument docroot);
481  QDomElement placetoadd,
482  QDomDocument docroot);
483 
485 
486 META_PUBLIC MetadataLookup *ParseMetadataItem(const QDomElement &item,
487  MetadataLookup *lookup,
488  bool passseas = true);
489 META_PUBLIC MetadataLookup *ParseMetadataMovieNFO(const QDomElement &item,
490  MetadataLookup *lookup);
491 META_PUBLIC PeopleMap ParsePeople(const QDomElement& people);
492 META_PUBLIC ArtworkMap ParseArtwork(const QDomElement& artwork);
493 
494 META_PUBLIC int editDistance(const QString &s, const QString &t);
495 META_PUBLIC QString nearestName(const QString &actual,
496  const QStringList &candidates);
497 
498 META_PUBLIC QDateTime RFC822TimeToQDateTime(const QString &t);
499 
502 
503 #endif // METADATACOMMON_H_
QStringList GetCategories() const
void SetTitle(const QString &title)
void SetHandleImages(bool handle)
QString GetNetwork() const
META_PUBLIC QDomDocument CreateMetadataXML(MetadataLookupList list)
QString GetChanPlaybackFilters() const
QString GetTrailerURL() const
QString url
void SetSubtitle(const QString &subtitle)
void SetAutomatic(bool autom)
QString GetStatus() const
QString GetSeriesId() const
const QString m_seriesId
void SetFilename(const QString &filename)
QString GetIMDB() const
uint GetYear() const
MetadataType
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
const QDateTime m_recStartTs
META_PUBLIC int editDistance(const QString &s, const QString &t)
General purpose reference counter.
void SetInetref(const QString &inetref)
void SetData(QVariant data)
bool GetIsCollection() const
QString GetDescription() const
void SetAllowOverwrites(bool allow)
VideoArtworkType
QString GetSystem() const
const QString m_chanNum
QString GetTMSref() const
const QString m_homepage
QString GetChanNum() const
QString m_collectionRef
const QString m_language
uint GetAudioProperties() const
META_PUBLIC void CreateMetadataXMLItem(MetadataLookup *lookup, QDomElement placetoadd, QDomDocument docroot)
QString GetPlayGroup() const
Q_DECLARE_METATYPE(GrabberScript *)
QString name
void SetPreferDVDOrdering(bool preferdvdorder)
uint GetRuntimeSeconds() const
META_PUBLIC MetadataLookup * ParseMetadataMovieNFO(const QDomElement &item, MetadataLookup *lookup)
QList< ArtworkInfo > ArtworkList
uint GetTrackNumber() const
QString GetAlbumTitle() const
bool GetAutomatic() const
QString GetSubtitle() const
QStringList GetStudios() const
MetadataType GetType() const
float GetUserRating() const
uint GetSeason() const
QString GetTitle() const
void SetStep(LookupStep step)
const QString m_chanPlaybackFilters
META_PUBLIC void AddStudios(MetadataLookup *lookup, QDomElement placetoadd, QDomDocument docroot)
const QString m_recGroup
const QStringList m_countries
uint GetEpisode() const
uint GetVideoProperties() const
Holds information on recordings and videos.
Definition: programinfo.h:67
void SetTMSref(const QString &tmsref)
QString GetTagline() const
META_PUBLIC QString nearestName(const QString &actual, const QStringList &candidates)
uint GetRevenue() const
void SetSystem(const QString &system)
LookupStep
const QString m_chanName
const QString m_trailerURL
uint GetSubtitleType() const
#define META_PUBLIC
Definition: mythmetaexp.h:9
void SetAllowGeneric(bool allow)
QString GetProgramId() const
QStringList GetCountries() const
META_PUBLIC ArtworkMap ParseArtwork(const QDomElement &artwork)
META_PUBLIC void AddCertifications(MetadataLookup *lookup, QDomElement placetoadd, QDomDocument docroot)
float GetPopularity() const
bool GetAllowGeneric() const
QString GetLanguage() const
bool GetAllowOverwrites() const
META_PUBLIC void AddCategories(MetadataLookup *lookup, QDomElement placetoadd, QDomDocument docroot)
const QString m_certification
unsigned int uint
Definition: compat.h:140
const QString m_description
void SetDownloads(ArtworkMap map)
QString GetInetref() const
bool GetPreferDVDOrdering() const
const QDateTime m_recEndTs
QString role
LookupType GetSubtype() const
void SetSeason(uint season)
void SetCollectionref(const QString &collectionref)
QVariant GetData() const
uint GetRatingCount() const
META_PUBLIC void AddCountries(MetadataLookup *lookup, QDomElement placetoadd, QDomDocument docroot)
const QDate m_releaseDate
LookupStep GetStep() const
uint GetChanId() const
const QString m_chanSign
QString thumbnail
QDate GetReleaseDate() const
const QDateTime m_startTs
QMap< VideoArtworkType, ArtworkInfo > DownloadMap
const QString m_storageGroup
void SetHost(const QString &host)
const ArtworkMap m_artwork
QString GetCollectionref() const
const QDateTime m_lastUpdated
const PeopleMap m_people
QString GetHomepage() const
void SetSubtype(LookupType subtype)
void SetAlbum(const QString &album)
QMultiMap< PeopleType, PersonInfo > PeopleMap
QDateTime GetLastUpdated() const
const QStringList m_studios
bool GetHandleImages() const
const QString m_playGroup
const QString m_tagline
uint GetRuntime() const
void SetType(MetadataType type)
void SetIsCollection(bool collection)
DownloadMap GetDownloads() const
VideoContentType
uint GetProgramFlags() const
void SetEpisode(uint episode)
QString GetChanSign() const
QMultiMap< VideoArtworkType, ArtworkInfo > ArtworkMap
QDateTime GetRecStartTS() const
const QDateTime m_endTs
QDateTime GetRecEndTS() const
QDateTime GetStartTS() const
QString GetHost() const
META_PUBLIC MetadataLookup * ParseMetadataItem(const QDomElement &item, MetadataLookup *lookup, bool passseas=true)
LookupType
PeopleType
META_PUBLIC MetadataLookup * LookupFromProgramInfo(ProgramInfo *pginfo)
const QStringList m_categories
QString GetRecGroup() const
QDateTime GetEndTS() const
void SetTrack(uint track)
META_PUBLIC QDateTime RFC822TimeToQDateTime(const QString &t)
META_PUBLIC PeopleMap ParsePeople(const QDomElement &people)
QString GetFilename() const
DownloadMap m_downloads
QString GetCertification() const
ArtworkMap GetArtwork(const QString &inetref, uint season, bool strict)
QString GetChanName() const
const QString m_programid
QString GetStorageGroup() const
QString GetBaseTitle() const
uint GetBudget() const