MetadataLookupList MetadataDownload::runGrabber(QString cmd, QStringList args, MetadataLookup* lookup, bool passseas) { MythSystem grabber(cmd, args, kMSNoRunShell | kMSStdOut | kMSBuffered); MetadataLookupList list; LOG(VB_GENERAL, LOG_INFO, QString("Running Grabber: %1 %2") .arg(cmd).arg(args.join(" "))); grabber.Run(); grabber.Wait(); QByteArray result = grabber.ReadAll(); if (!result.isEmpty()) { QDomDocument doc; doc.setContent(result, true); QDomElement root = doc.documentElement(); QDomElement item = root.firstChildElement("item"); while (!item.isNull()) { MetadataLookup *tmp = ParseMetadataItem(item, lookup, passseas); list.append(tmp); item = item.nextSiblingElement("item"); } } return list; }
// TODO // using the MetadataLookup object as both argument input, and parsed output, // is clumsy. break the inputs out into a separate object, and spawn a new // MetadataLookup object in ParseMetadataItem, rather than requiring an // existing one to reuse. MetadataLookupList MetaGrabberScript::RunGrabber(const QStringList &args, MetadataLookup *lookup, bool passseas) { MythSystemLegacy grabber(m_fullcommand, args, kMSStdOut); MetadataLookupList list; LOG(VB_GENERAL, LOG_INFO, QString("Running Grabber: %1 %2") .arg(m_fullcommand).arg(args.join(" "))); grabber.Run(); if (grabber.Wait() != GENERIC_EXIT_OK) return list; QByteArray result = grabber.ReadAll(); if (!result.isEmpty()) { QDomDocument doc; doc.setContent(result, true); QDomElement root = doc.documentElement(); QDomElement item = root.firstChildElement("item"); while (!item.isNull()) { MetadataLookup *tmp = ParseMetadataItem(item, lookup, passseas); tmp->SetInetref(QString("%1_%2").arg(m_command) .arg(tmp->GetInetref())); if (!tmp->GetCollectionref().isEmpty()) { tmp->SetCollectionref(QString("%1_%2").arg(m_command) .arg(tmp->GetCollectionref())); } list.append(tmp); // MetadataLookup is to be owned by the list tmp->DecrRef(); item = item.nextSiblingElement("item"); } } return list; }
void MetadataDownload::run() { RunProlog(); MetadataLookup* lookup; while ((lookup = moreWork()) != NULL) { MetadataLookupList list; // Go go gadget Metadata Lookup if (lookup->GetType() == kMetadataVideo) { if (lookup->GetSubtype() == kProbableTelevision) list = handleTelevision(lookup); else if (lookup->GetSubtype() == kProbableMovie) list = handleMovie(lookup); else list = handleVideoUndetermined(lookup); if (!list.size() && lookup->GetSubtype() == kUnknownVideo) { list = handleMovie(lookup); } } else if (lookup->GetType() == kMetadataRecording) { if (lookup->GetSubtype() == kProbableTelevision) { if (lookup->GetSeason() > 0 || lookup->GetEpisode() > 0) list = handleTelevision(lookup); else if (!lookup->GetSubtitle().isEmpty()) list = handleVideoUndetermined(lookup); if (!list.size()) list = handleRecordingGeneric(lookup); } else if (lookup->GetSubtype() == kProbableMovie) { list = handleMovie(lookup); if (lookup->GetInetref().isEmpty()) list.append(handleRecordingGeneric(lookup)); } else { list = handleRecordingGeneric(lookup); if (lookup->GetInetref().isEmpty()) list.append(handleMovie(lookup)); } } else if (lookup->GetType() == kMetadataGame) list = handleGame(lookup); // inform parent we have lookup ready for it if (m_parent && list.count() >= 1) { // If there's only one result, don't bother asking // our parent about it, just add it to the back of // the queue in kLookupData mode. if (list.count() == 1 && list.at(0)->GetStep() == kLookupSearch) { MetadataLookup *newlookup = list.takeFirst(); newlookup->SetStep(kLookupData); prependLookup(newlookup); continue; } // If we're in automatic mode, we need to make // these decisions on our own. Pass to title match. if (list.at(0)->GetAutomatic() && list.count() > 1) { if (!findBestMatch(list, lookup->GetTitle())) QCoreApplication::postEvent(m_parent, new MetadataLookupFailure(MetadataLookupList() << lookup)); continue; } LOG(VB_GENERAL, LOG_INFO, QString("Returning Metadata Results: %1 %2 %3") .arg(lookup->GetTitle()).arg(lookup->GetSeason()) .arg(lookup->GetEpisode())); QCoreApplication::postEvent(m_parent, new MetadataLookupEvent(list)); } else { list.append(lookup); QCoreApplication::postEvent(m_parent, new MetadataLookupFailure(list)); } } RunEpilog(); }
MetadataLookupList MetadataDownload::readNFO(QString NFOpath, MetadataLookup* lookup) { MetadataLookupList list; LOG(VB_GENERAL, LOG_INFO, QString("Matching NFO file found. Parsing %1 for metadata...") .arg(NFOpath)); if (lookup->GetType() == kMetadataVideo) { QByteArray nforaw; QDomElement item; if (NFOpath.startsWith("myth://")) { RemoteFile *rf = new RemoteFile(NFOpath); if (rf && rf->Open()) { bool loaded = rf->SaveAs(nforaw); if (loaded) { QDomDocument doc; if (doc.setContent(nforaw, true)) { lookup->SetStep(kLookupData); item = doc.documentElement(); } else LOG(VB_GENERAL, LOG_ERR, QString("PIRATE ERROR: Invalid NFO file found.")); } rf->Close(); } delete rf; rf = NULL; } else { QFile file(NFOpath); if (file.open(QIODevice::ReadOnly)) { nforaw = file.readAll(); QDomDocument doc; if (doc.setContent(nforaw, true)) { lookup->SetStep(kLookupData); item = doc.documentElement(); } else LOG(VB_GENERAL, LOG_ERR, QString("PIRATE ERROR: Invalid NFO file found.")); file.close(); } } MetadataLookup *tmp = ParseMetadataMovieNFO(item, lookup); list.append(tmp); } return list; }
MetadataLookupList MetadataDownload::readMXML(QString MXMLpath, MetadataLookup* lookup, bool passseas) { MetadataLookupList list; LOG(VB_GENERAL, LOG_INFO, QString("Matching MXML file found. Parsing %1 for metadata...") .arg(MXMLpath)); if (lookup->GetType() == kMetadataVideo) { QByteArray mxmlraw; QDomElement item; if (MXMLpath.startsWith("myth://")) { RemoteFile *rf = new RemoteFile(MXMLpath); if (rf && rf->Open()) { bool loaded = rf->SaveAs(mxmlraw); if (loaded) { QDomDocument doc; if (doc.setContent(mxmlraw, true)) { lookup->SetStep(kLookupData); QDomElement root = doc.documentElement(); item = root.firstChildElement("item"); } else LOG(VB_GENERAL, LOG_ERR, QString("Corrupt or invalid MXML file.")); } rf->Close(); } delete rf; rf = NULL; } else { QFile file(MXMLpath); if (file.open(QIODevice::ReadOnly)) { mxmlraw = file.readAll(); QDomDocument doc; if (doc.setContent(mxmlraw, true)) { lookup->SetStep(kLookupData); QDomElement root = doc.documentElement(); item = root.firstChildElement("item"); } else LOG(VB_GENERAL, LOG_ERR, QString("Corrupt or invalid MXML file.")); file.close(); } } MetadataLookup *tmp = ParseMetadataItem(item, lookup, passseas); list.append(tmp); } return list; }
void MetadataDownload::run() { MetadataLookup* lookup; threadRegister("MetadataDownload"); while ((lookup = moreWork()) != NULL) { MetadataLookupList list; // Go go gadget Metadata Lookup if (lookup->GetType() == VID) { if (lookup->GetSeason() > 0 || lookup->GetEpisode() > 0) list = handleTelevision(lookup); else if (!lookup->GetSubtitle().isEmpty()) list = handleVideoUndetermined(lookup); else list = handleMovie(lookup); } // else if (lookup->GetType() == MUSIC) // list = handleMusic(lookup); else if (lookup->GetType() == GAME) list = handleGame(lookup); // inform parent we have lookup ready for it if (m_parent && list.count() >= 1) { // If there's only one result, don't bother asking // our parent about it, just add it to the back of // the queue in GETDATA mode. if (list.count() == 1 && list.at(0)->GetStep() == SEARCH) { MetadataLookup *newlookup = list.takeFirst(); newlookup->SetStep(GETDATA); prependLookup(newlookup); continue; } // If we're in automatic mode, we need to make // these decisions on our own. Pass to title match. if (list.at(0)->GetAutomatic() && list.count() > 1) { if (!findBestMatch(list, lookup->GetTitle())) QCoreApplication::postEvent(m_parent, new MetadataLookupFailure(MetadataLookupList() << lookup)); continue; } VERBOSE(VB_GENERAL, QString("Returning Metadata Results: %1 %2 %3") .arg(lookup->GetTitle()).arg(lookup->GetSeason()) .arg(lookup->GetEpisode())); QCoreApplication::postEvent(m_parent, new MetadataLookupEvent(list)); } else { list.append(lookup); QCoreApplication::postEvent(m_parent, new MetadataLookupFailure(list)); } } threadDeregister(); }