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(); }
void ThumbGenerator::run() { RunProlog(); m_cancel = false; while (moreWork() && !m_cancel) { QString file, dir; bool isGallery; m_mutex.lock(); dir = m_directory; isGallery = m_isGallery; file = m_fileList.first(); if (!m_fileList.isEmpty()) m_fileList.pop_front(); m_mutex.unlock(); if (file.isEmpty()) continue; QString filePath = dir + QString("/") + file; QFileInfo fileInfo(filePath); if (!fileInfo.exists()) continue; if (isGallery) { if (fileInfo.isDir()) isGallery = checkGalleryDir(fileInfo); else isGallery = checkGalleryFile(fileInfo); } if (!isGallery) { QString cachePath = QString("%1%2.jpg").arg(getThumbcacheDir(dir)) .arg(file); QFileInfo cacheInfo(cachePath); if (cacheInfo.exists() && cacheInfo.lastModified() >= fileInfo.lastModified()) { continue; } else { // cached thumbnail not there or out of date QImage image; // Remove the old one if it exists if (cacheInfo.exists()) QFile::remove(cachePath); if (fileInfo.isDir()) loadDir(image, fileInfo); else loadFile(image, fileInfo); if (image.isNull()) continue; // give up; // if the file is a movie save the image to use as a screenshot if (GalleryUtil::IsMovie(fileInfo.filePath())) { QString screenshotPath = QString("%1%2-screenshot.jpg") .arg(getThumbcacheDir(dir)) .arg(file); image.save(screenshotPath, "JPEG", 95); } image = image.scaled(m_width,m_height, Qt::KeepAspectRatio, Qt::SmoothTransformation); image.save(cachePath, "JPEG", 95); // deep copies all over ThumbData *td = new ThumbData; td->directory = dir; td->fileName = file; td->thumb = image.copy(); // inform parent we have thumbnail ready for it QApplication::postEvent(m_parent, new ThumbGenEvent(td)); } } } RunEpilog(); }
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(); }