void VideoInformation::loadPluginFile(QString scriptFile)
{
	// try to regist this
	VideoInformationPlugin *plugin = new VideoInformationPlugin(this, scriptFile);
	// if this plugin has not been loaded, we must destroy it manually
	if (!plugin->isLoaded()) delete plugin;
}
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 BugReportImpl::getPluginInformation(QString URL)
{
	VideoInformationPlugin *plugin = videoInformation->getPluginByHost(QUrl(URL));
	// exists?
	if (plugin != NULL)
		return QString("%1 (%2)").arg(plugin->getScriptFile(true)).arg(plugin->getVersion());
	else
		return "-";
}
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");
}
VideoInformationPlugin* VideoInformation::getRegisteredPlugin(const QString pluginId)
{
	for (int n = 0; n < plugins->count(); n++)
	{
		VideoInformationPlugin *plugin = plugins->at(n);
		// compare names
		if (plugin->getID() == pluginId)
			return plugin;
	}
	// not found
	return NULL;
}
VideoInformationPlugin* VideoInformation::getRegisteredPlugin(const QString fileName, const bool onlyFileName)
{
	for (int n = 0; n < plugins->count(); n++)
	{
		VideoInformationPlugin *plugin = plugins->at(n);
		// compare names
		if (plugin->getScriptFile(onlyFileName) == fileName)
			return plugin;
	}
	// not found
	return NULL;
}
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);
}
Пример #10
0
void PluginTester::run()
{
	stopFlag = false;
    failed = 0;

	emit workingStarted();

	for (int n = 0; n < tests->count(); n++)
	{
		PluginTest *test = tests->at(n);
		//
        if ((onlyFailed && test->isTestOk()) || (onlySelected != -1 && n != onlySelected)) continue;
		//
		emit pluginTestRunning(test);
		// get video information
        emit workingProgress(n * 2, tests->count() * 2, QString("Getting <b>%1</b> video information... [1/2]").arg(test->getPluginTitle()));
		VideoInformationPlugin *plugin = new VideoInformationPlugin(NULL, pluginsDir + test->getPluginFile());
		VideoDefinition  vd = plugin->getVideoInformation(test->getUrl());
		// try to download video
		emit workingProgress(n * 2 + 1, tests->count() * 2, QString("Testing <b>%1</b> video download... [2/2]").arg(test->getPluginTitle()));
		Http *http = new Http();
		if (!vd.cookies.isEmpty()) http->addCookies(vd.cookies);
		if (!vd.headers.isEmpty()) http->addHeaderParameters(vd.headers);
		int contentLength = copyBetween(http->head(QUrl(vd.URL)), "Content-Length: ", "\n").toInt();
		delete http;
		// update test info
		test->setCaption(vd.title);
		test->setFlvUrl(vd.URL);
		test->setSize(contentLength);
		// increase failed tests
		if (!test->isTestOk()) failed++;
		// destroy plugin
		delete plugin;
		// finished
		emit pluginTestFinished(test);
		// small pause, prevent 100% cpu
		if (stopFlag) n = tests->count(); else sleep(1);
	}

	emit workingFinished(tests->count() - failed, failed);
}
Пример #11
0
void SearchVideos::run()
{
	// search started
	emit searchStarted();
	// stop getting previews
	imageCatcher->stop();
	// clear previous results
	searchResults->removeAllSearchResults();
	// has plugins to search?
	if (internalPluginsIds.count() == 0)
	{
		// search finished
		emit searchFinished();
		// abort process
		return;
	}
	// build the plugins search list
	QList<VideoInformationPlugin *> plugins;
	// check which plugins goes into the list
	if (internalPluginsIds.at(0) == SEARCH_ID_ALL) // all plugins
		plugins.append(VideoInformation::instance()->getAllSearchPlugins());
	else if (internalPluginsIds.at(0) == SEARCH_ID_STANDARD) // all standard plugins
		plugins.append(VideoInformation::instance()->getAllSearchStandardPlugins());
	else if (internalPluginsIds.at(0) == SEARCH_ID_ADULTS) // all adult plugins
		plugins.append(VideoInformation::instance()->getAllSearchAdultPlugins());
	else if (internalPluginsIds.count() == 1) // single search
		plugins.append(VideoInformation::instance()->getRegisteredPlugin(internalPluginsIds.at(0)));
	else // custom search, so add them...
		for (int n = 0; n < internalPluginsIds.count(); n++)
			plugins.append(VideoInformation::instance()->getRegisteredPlugin(internalPluginsIds.at(n)));
	// if adult sites are disabled, then remove them from list
	if (VideoInformation::instance()->getBlockAdultContent())
		for (int n = plugins.count() - 1; n >= 0; n--)
			if (plugins.at(n)->hasAdultContent())
				plugins.removeAt(n);
	// inits
	int lastCount = 0;
	// start to search
	while (!plugins.isEmpty())
	{
		VideoInformationPlugin *plugin = plugins.takeFirst();

		if (plugin != NULL)
		{
			// execute search into current thread
			SearchResults results = plugin->searchVideos(internalKeyWords, internalPage);
			// check if we are destroying the searchResults (if yes, then abort the process)
			if (destroying) return;
			// add results
			searchResults->addSearchResults(results);
			searchResults->setSummary(results.getSummary());
			// add new search block
			emit addNewSearchBlock(plugin);
			// has results?
			if (searchResults->getSearchResultCount() == 0)
			{
				// emit add no results
				emit searchResultAdded(NULL);
				// next search...
				continue;
			}
			// show results
			for (int n = lastCount; n < searchResults->getSearchResultCount(); n++)
			{
				// emit add result
				emit searchResultAdded(searchResults->getSearchResult(n));
				// add to previews download previews
				imageCatcher->addPreview(searchResults->getSearchResult(n));
			}
		}
		// update last count
		lastCount = searchResults->getSearchResultCount();
	}
	// search finished
	emit searchFinished();
}