示例#1
0
stream2file_error_msg_t stop_recording(void)
{
	if (exit_flag == STREAM2FILE_STATUS_RUNNING)
	{
		CMovieInfo mi;
		MI_MOVIE_INFO movieinfo; 
		mi.clearMovieInfo(&movieinfo);

		time(&record_end_time);
		printf("record time: %lu \n",record_end_time-record_start_time);
		//load MovieInfo and set record time
		movieinfo.file.Name = myfilename;
		movieinfo.file.Name += ".ts";
		mi.loadMovieInfo(&movieinfo);
		movieinfo.rec_length += record_end_time - record_start_time;
		mi.saveMovieInfo(movieinfo);

		/* reset record_start_time, so that we know the recording was not
		   aborted abnormally */
		record_start_time = 0;
		exit_flag = STREAM2FILE_STATUS_IDLE;
		return STREAM2FILE_OK;
	}
	else
	{
		record_start_time = 0;
		return STREAM2FILE_RECORDING_THREADS_FAILED;
	}
}
void CMovieCut::save_info(MI_MOVIE_INFO * minfo, char * dpart, off64_t spos, off64_t secsize)
{
	CMovieInfo cmovie;
	MI_MOVIE_INFO ninfo = *minfo;
	ninfo.file.Name = dpart;
	ninfo.file.Size = spos;
	ninfo.length = spos/secsize/60;
	ninfo.bookmarks.end = 0;
	ninfo.bookmarks.start = 0;
	ninfo.bookmarks.lastPlayStop = 0;
	for (int book_nr = 0; book_nr < MI_MOVIE_BOOK_USER_MAX; book_nr++) {
		if (ninfo.bookmarks.user[book_nr].pos != 0 && ninfo.bookmarks.user[book_nr].length > 0) {
			ninfo.bookmarks.user[book_nr].pos = 0;
			ninfo.bookmarks.user[book_nr].length = 0;
		}
	}
	cmovie.saveMovieInfo(ninfo);
	WriteHeader(ninfo.file.Name.c_str(), spos/secsize*1000);
	reset_atime(dpart, minfo->file.Time);
}
bool CMovieCut::truncateMovie(MI_MOVIE_INFO * minfo)
{
	off64_t secsize = getSecondSize(minfo);
	if (minfo->bookmarks.end == 0 || secsize == 0)
		return false;

	off64_t newsize = secsize * minfo->bookmarks.end;

	printf("CMovieCut::%s: [%s] truncate to %d sec, new size %" PRId64 "\n", __func__, minfo->file.Name.c_str(), minfo->bookmarks.end, newsize);
	if (truncate(minfo->file.Name.c_str(), newsize)) {
		perror(minfo->file.Name.c_str());
		return false;
	}
	minfo->file.Size = newsize;
	minfo->length = minfo->bookmarks.end/60;
	minfo->bookmarks.end = 0;
	reset_atime(minfo->file.Name.c_str(), minfo->file.Time);
	CMovieInfo cmovie;
	cmovie.saveMovieInfo(*minfo);
	WriteHeader(minfo->file.Name.c_str(), newsize/secsize*1000);
	return true;
}
示例#4
0
bool cYTCache::download(MI_MOVIE_INFO *mi)
{
	std::string file = getName(mi);
	std::string xml = getName(mi, "xml");
	if (!access(file, R_OK) && !access(xml, R_OK)) {
		fprintf(stderr, "%s: %s already present and valid\n", __func__, file.c_str());
		return true;
	}

	FILE * fp = fopen(file.c_str(), "wb");
	if (!fp) {
		perror(file.c_str());
		return false;
	}

	CURL *curl = curl_easy_init();
	if (!curl) {
		fclose(fp);
		return false;
	}

	curl_easy_setopt(curl, CURLOPT_URL, mi->file.Url.c_str());
	curl_easy_setopt(curl, CURLOPT_FILE, fp);
	curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
	curl_easy_setopt(curl, CURLOPT_TIMEOUT, URL_TIMEOUT);
	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
	curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, cYTCache::curlProgress); 
	curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this); 
	curl_easy_setopt(curl, CURLOPT_NOPROGRESS, (long)0); 
	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);

	char cerror[CURL_ERROR_SIZE];
	curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, cerror);

	if(!g_settings.softupdate_proxyserver.empty()) {
		curl_easy_setopt(curl, CURLOPT_PROXY, g_settings.softupdate_proxyserver.c_str());
		if(!g_settings.softupdate_proxyusername.empty()) {
			std::string tmp = g_settings.softupdate_proxyusername + ":" + g_settings.softupdate_proxypassword;
			curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, tmp.c_str());
		}
	}

	dltotal = 0;
	dlnow = 0;
	dlstart = time(NULL);

	fprintf (stderr, "downloading %s to %s\n", mi->file.Url.c_str(), file.c_str());
	CURLcode res = curl_easy_perform(curl);
	curl_easy_cleanup(curl);

	fclose(fp);

	if (res) {
		fprintf (stderr, "downloading %s to %s failed: %s\n", mi->file.Url.c_str(), file.c_str(), cerror);
		unlink(file.c_str());
		return false;
	}
	CMovieInfo cMovieInfo;
	CFile File;
	File.Name = xml;
	cMovieInfo.saveMovieInfo(*mi, &File);
	std::string thumbnail_dst = getName(mi, "jpg");
	CFileHelpers fh;
	fh.copyFile(mi->tfile.c_str(), thumbnail_dst.c_str(), 0644);
	return true;
}