QPixmap VideoInformation::getHostImage(QString URL, bool checkURL) { const QString path = ":/services/images/services/%1.png"; bool valid = !checkURL ? true : validURL(URL); // if is a valid URL if (valid) { QPixmap result; // find a plugin which can resolve this url VideoInformationPlugin *plugin = getPluginByHost(QUrl(URL)); // check if we found a plugin which can give us the service icon if (plugin != NULL) { QPixmap *p = plugin->getIcon(); result = *p; } else // is an invalid service result = QPixmap(QString(path).arg("invalid")); // if this plugin hasn't an image loaded, then set an standard icon if (result.isNull()) result = QPixmap(QString(path).arg("no_icon")); // return the final image return result; } else // return link error image return QPixmap(QString(path).arg("link_error")); }
QString VideoInformation::getHostCaption(QString URL) { if (validURL(URL)) { VideoInformationPlugin *plugin = getPluginByHost(QUrl(URL)); return plugin != NULL ? plugin->getCaption() : tr("Unsupported video service"); } else if (isRtmpURL(URL)) return tr("Adobe Flash streaming"); else return tr("Invalid URL"); }
void DetailView::onDownload() { int current_row = ui->sourceListWidget->currentRow(); if (current_row < 0) return; QString host = QUrl(QString::fromUtf8(urls[current_row])).host(); Plugin *plugin = getPluginByHost(host); if (plugin) plugin->parse(urls[current_row].constData(), true); else QMessageBox::warning(this, "warning", tr("Cannot find plugin which can parse this source.")); }
void VideoInformation::abortExecution() { if (videoItem != NULL && isGettingInfo()) { VideoInformationPlugin *service = getPluginByHost(QUrl(videoItem->getURL())); if (service != NULL) { service->abortExecution(); videoItem->setAsGettedURL(this); videoItem->unlock(this); } } }
bool VideoInformation::isBlockedHost(QString URL, BlockedState &result) { VideoInformationPlugin *service = getPluginByHost(QUrl(URL)); result = bsNotBlocked; if (service != NULL) { if (service->hasAdultContent() && blockAdultContent) result = bsAdultContent; else if (blockAdultContentList.indexOf(service->getID(), 0) != -1) result = bsBlocked; } return result != bsNotBlocked; }
void VideoInformation::run() { videoItem->lock(this); VideoInformationPlugin *service = getPluginByHost(QUrl(videoItem->getURL())); if (service != NULL) { if (isBlockedHost(videoItem->getURL())) videoItem->setAsBlocked(this); else { videoItem->setAsGettingURL(this); // if this item was market as "need update the url" then change the status to "updating url..." bool urlWasUpdated = videoItem->needUpdateUrl(); if (urlWasUpdated) videoItem->setAsUpdatingURL(); emit informationStarted(videoItem); VideoDefinition info = service->getVideoInformation(videoItem->getURL()); // canceled? if (videoItem == NULL) return; if (info.needLogin) { videoItem->setAsNeedLogin(this); videoItem->removeUpdatingURLStatus(); } else // ok, assign information and prepare the item to be downloaded { videoItem->setVideoInformation(info, this); if (!urlWasUpdated) videoItem->setVideoFile(cleanFileName(info.title + info.extension), this); videoItem->setAsGettedURL(this); } } } else videoItem->setAsError(this); videoItem->unlock(this); emit informationFinished(videoItem); }
bool VideoInformation::isValidHost(QString URL) { return getPluginByHost(QUrl(URL)) != NULL && QUrl(URL).isValid() && !isRtmpURL(URL)? true : false; }