Ejemplo n.º 1
0
bool FileManager::saveImage(const QString &fileName, const byte fileType)
{
	QString eName = getExtensionName(fileName);
	if(eName.toLower() == "bmp")
	{
		return saveBMP(fileName, fileType);
	}
	else if(eName.toLower() == "png")
	{
		return savePNG(fileName);
	}
	return false;
}
Ejemplo n.º 2
0
void FileManager::loadImage(const QString &fileName)
{
	QString eName = getExtensionName(fileName);
	this->name = fileName;
	if(eName.toLower() == "bmp")
	{
		loadBMP(fileName);
	}
	else if(eName.toLower() == "png")
	{
		loadPNG(fileName);
	}
}
std::set<std::string> YoutubeCrawler::getVideoFile(std::map<std::string, std::string> &result){
	std::set<std::string> unFinishVids;
	if(result.size() == 0){
		return unFinishVids;
	}
	CURL *handle = curl_easy_init();
	if(handle == NULL){
		return unFinishVids;
	}
	CURLM *mhandle = curl_multi_init();
	if(mhandle == NULL){
		curl_easy_cleanup(handle);
		return unFinishVids;
	}
	CURLcode code;
	curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writeFileCallback);
	curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
	curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 10);
	curl_easy_setopt(handle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
	curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, 10);
	curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1);
	curl_easy_setopt(handle, CURLOPT_LOW_SPEED_LIMIT, 1);
	curl_easy_setopt(handle, CURLOPT_LOW_SPEED_TIME, 60);
	std::map<std::string, CURL*> handleList;
	std::map<std::string, RecInfo> addrsList;
	BDB::AddrType tmpAddr;
	std::pair<std::map<std::string, RecInfo>::iterator, bool> addrIt;
	RecInfo recInfo;
	recInfo.ybdb = &ybdb;
	for(std::map<std::string, std::string>::iterator it = result.begin(); it != result.end(); it++){
		tmpAddr = ybdb.put("", 0);
		if(tmpAddr == -1){
			continue;
		}
		recInfo.addr = tmpAddr;
		recInfo.size = 0;
		addrIt = addrsList.insert(std::pair<std::string, RecInfo>(it->first, recInfo));
		curl_easy_setopt(handle, CURLOPT_WRITEDATA, &(addrIt.first->second));
		curl_easy_setopt(handle, CURLOPT_URL, it->second.c_str());
		handleList.insert(std::pair<std::string, CURL*>(it->first, handle));
		curl_multi_add_handle(mhandle, handle);
		handle = curl_easy_duphandle(handle);
	}
	curl_easy_cleanup(handle);
	if(handleList.size() == 0){
		curl_multi_cleanup(mhandle);
		return unFinishVids;
	}
	int runningHandles = 0;
	while(curl_multi_perform(mhandle, &runningHandles) == CURLM_CALL_MULTI_PERFORM){}
	struct timeval timeout;
	timeout.tv_sec = 0;
	timeout.tv_usec = 0;
	int max_fd = 0;
	fd_set read_fd_set;
	fd_set write_fd_set;
	fd_set exc_fd_set;
	FD_ZERO(&read_fd_set);
	FD_ZERO(&write_fd_set);
	FD_ZERO(&exc_fd_set);
	while(runningHandles > 0){
		curl_multi_fdset(mhandle, &read_fd_set, &write_fd_set, &exc_fd_set, &max_fd);
		curl_multi_timeout(mhandle, &(timeout.tv_usec));
		if(timeout.tv_usec > 0){
			select(max_fd + 1, &read_fd_set, &write_fd_set, &exc_fd_set, &timeout);
		}
		while(curl_multi_perform(mhandle, &runningHandles) == CURLM_CALL_MULTI_PERFORM){}
	}
	for(std::map<std::string, CURL*>::iterator it = handleList.begin(); it != handleList.end(); it++){
		curl_multi_remove_handle(mhandle, it->second);
		curl_easy_cleanup(it->second);
	}
	curl_multi_cleanup(mhandle);
	std::map<std::string, std::string>::iterator uIt;
	for(std::map<std::string, RecInfo>::iterator it = addrsList.begin(); it != addrsList.end(); it++){
		if(it->second.size == 0){
			unFinishVids.insert(it->first);
			ybdb.del(it->second.addr);
		}else{
			uIt = result.find(it->first);
			logRids << std::setw(11) << it->first 
				<< std::setfill('0') << std::setw(9) << std::hex << it->second.addr 
				<< std::setfill('0') << std::setw(9) << std::hex << it->second.size 
				<< getExtensionName(uIt->second) << std::endl;
			logRids.flush();
		}
	}
	return unFinishVids;
}