Example #1
0
//-------- Go through the processes involved in getting a video file
int GrabMovie(char *Path, int MovType)
{
int i;
char *Proto=NULL, *Server=NULL, *Doc=NULL, *Tempstr=NULL, *Title=NULL;
char *NextPath=NULL;
char *ptr, *Token=NULL;
int Port;
int RetVal=FALSE;

if (!StrLen(Path)) return(FALSE);

Type=MovType;
NextPath=CopyStr(NextPath,Path);
ParseURL(Path,&Proto,&Server,&Tempstr,NULL,NULL,&Doc,NULL);
if (Tempstr) Port=atoi(Tempstr);

if (Proto && (strcasecmp(Proto,"https")==0) )
{
	if (! SSLAvailable)
	{
		printf("SSL NOT COMPILED IN! Switching from 'https' to 'http'\n");
		NextPath=MCopyStr(NextPath,"http://",Server,"/",ptr);
	}
}

if (Type==TYPE_NONE) Type=IdentifyServiceType(Path);


if (Type==TYPE_NONE)
{
if (! (Flags & FLAG_QUIET)) fprintf(stderr,"Unrecognized url type. Falling Back to 'generic youtube frontend'.\n Try using the -t option to force the service type ( \"movgrab -?\" for more details )\n");
Type=TYPE_GENERIC;
}

NextPath=SiteSpecificPreprocessing(NextPath, Path, Proto, Server, Port, Doc, &Type, &Title, &Flags);
if (DownloadPage(NextPath, Type, Title, Flags)) RetVal=TRUE;

DestroyString(Tempstr);
DestroyString(Server);
DestroyString(Doc);
DestroyString(NextPath);
DestroyString(Token);
DestroyString(Title);
DestroyString(Proto);

return(RetVal);
}
Example #2
0
UINT CGetImageDlg::RunTask()
{
	int ret;
	CString status,tmp;

	status.LoadString(IDS_STATUS_DLD_PAGE); SetStatus(status+m_strAddress);
	if(ret = DownloadPage(m_strAddress))
	{
		tmp.LoadString(IDS_DLD_MPAGE_ERR);
		status.Format(tmp,ret);
		Echo(status);
	}
	else
	{
		m_strBufUrl = m_strAddress;
		m_lstUsedPage.AddTail(m_strAddress);
	}

	do
	{

// 分析网页链接
		m_pcThrdNum.SetPos(m_nThrdNum);
		status.LoadString(IDS_STATUS_DLD_PAGE); SetStatus(status);
		m_csBufCtt.Lock();
		if (m_strBufUrl.IsEmpty()) // 没有网页可供继续下载
		{
			m_csBufCtt.Unlock();
			break;
		}
		m_strCurPageCtt = m_strBufPageCtt;
		RenewPageList(m_strBufUrl);
		int nPage = m_lstPage.GetCount();
		m_strCurUrl = m_strBufUrl;
		m_strBufUrl.Empty();	
		m_csBufCtt.Unlock();


// 下载网页
		if (!m_bStarted) break;

		if (!m_lstPage.IsEmpty())
		{
			::AfxBeginThread(DldPageProc, NULL);
		}
		

// 分析图片链接
		tmp.LoadString(IDS_DLDD_PAGE);
		status.Format(tmp,++m_nDldPage,m_strCurUrl);
		Echo(status);
		GetImgList(m_strCurUrl);		
		tmp.LoadString(IDS_ANLZ_RSLT);
		status.Format(tmp, m_lstImg.GetCount(),nPage);
		Echo(status);
		if (!m_bStarted) break;


// 下载图片
		status.LoadString(IDS_STATUS_DLD_IMGS);
		SetStatus(status+m_strCurUrl);
		while(!m_lstImg.IsEmpty())
		{
			//Echo(m_lstImg.GetNext(pos));
			CString imgUrl = m_lstImg.RemoveHead();
			
			if (m_optDlg.m_nMaxThread == 0) // 单线程
			{
				tmp.LoadString(IDS_DLD_IMG);
				status.Format(tmp,++m_nDldImg,imgUrl);
				Echo(status);
				ret = DownloadSaveImg(imgUrl);
			}
			else // 多线程
			{
				for (int i = 0;i < m_nThrdNum-m_optDlg.m_nMaxThread+1;i++) // 线程数限制
				{
					::WaitForSingleObject(m_event.m_hObject,INFINITE);
				}
				::AfxBeginThread(DldImgProc,(LPVOID)(LPCTSTR)imgUrl);

				m_pcThrdNum.SetPos(m_nThrdNum);
				tmp.LoadString(IDS_DLD_IMG);
				status.Format(tmp,++m_nDldImg,imgUrl);
				Echo(status);
			}

			if (!m_bStarted) // || (m_nDldImg == m_optDlg.m_ucMaxImg && m_optDlg.m_ucMaxImg != 0))
				break;
			tmp.LoadString(IDS_STATUS_DLDD_NUM);
			status.Format(tmp,m_nDldImg);
			SetStatus(status);
		}

		if (!m_bStarted || (m_nDldImg >= m_optDlg.m_ucMaxImg && m_optDlg.m_ucMaxImg != 0)
			|| m_nDldPage == m_optDlg.m_ucMaxPage) // 检查结束条件
		{
			break;
		}


	}
	while(1);

	OnStop(); // 下载结束
	return 0;
}