00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "FDMFlashVideoDownloads.h"
00009 #include "vmsVideoSiteHtmlCodeParser.h"
00010 #include "FlashVideoDownloadsWnd.h"
00011 #include "UIThread.h"
00012
00013 _COM_SMARTPTR_TYPEDEF (IWGUrlReceiver, __uuidof (IWGUrlReceiver));
00014
00015 STDMETHODIMP CFDMFlashVideoDownloads::ProcessIeDocument(IDispatch *pDispatch)
00016 {
00017 IHTMLDocument2Ptr spDoc (pDispatch);
00018 if (spDoc == NULL)
00019 return E_INVALIDARG;
00020
00021 IPersistFilePtr spFile (pDispatch);
00022 if (spFile == NULL)
00023 return E_INVALIDARG;
00024
00025 USES_CONVERSION;
00026 BSTR bstrHost = NULL;
00027 spDoc->get_URL (&bstrHost);
00028 fsURL url;
00029 if (url.Crack (W2A (bstrHost)) != IR_SUCCESS)
00030 return E_FAIL;
00031 SysFreeString (bstrHost);
00032
00033 char szPath [MY_MAX_PATH];
00034 GetTempPath (sizeof (szPath), szPath);
00035 char szFile [MY_MAX_PATH];
00036 GetTempFileName (szPath, "fdm", 0, szFile);
00037
00038 COleVariant vaFile (szFile);
00039 if (FAILED (spFile->Save (vaFile.bstrVal, FALSE)))
00040 return E_FAIL;
00041
00042 HANDLE hFile = CreateFile (szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
00043 if (hFile == INVALID_HANDLE_VALUE)
00044 return E_FAIL;
00045
00046 DWORD dw = GetFileSize (hFile, NULL);
00047
00048 LPSTR pszHtml = new char [dw + 1];
00049 ReadFile (hFile, pszHtml, dw, &dw, NULL);
00050 pszHtml [dw] = 0;
00051
00052 CloseHandle (hFile);
00053 DeleteFile (szFile);
00054
00055 ProcessHtml (url.GetHostName (), pszHtml);
00056 delete [] pszHtml;
00057
00058 return S_OK;
00059 }
00060
00061 STDMETHODIMP CFDMFlashVideoDownloads::ProcessHtml(BSTR bstrHost, BSTR bstrHtml)
00062 {
00063 USES_CONVERSION;
00064 ProcessHtml (W2A (bstrHost), W2A (bstrHtml));
00065 return S_OK;
00066 }
00067
00068 void CFDMFlashVideoDownloads::ProcessHtml(LPCSTR pszHost, LPCSTR pszHtml)
00069 {
00070 vmsVideoSiteHtmlCodeParser vshcp;
00071 if (FALSE == vshcp.Parse (pszHost, pszHtml))
00072 return;
00073
00074 USES_CONVERSION;
00075
00076 IWGUrlReceiverPtr spRcvr;
00077 spRcvr.CreateInstance (__uuidof (WGUrlReceiver));
00078 spRcvr->put_Url (A2W (vshcp.get_VideoUrl ()));
00079
00080 if (vshcp.get_IsVideoUrlDirectLink ())
00081 {
00082 CString str = vshcp.get_VideoTitle ();
00083 str += "."; str += vshcp.get_VideoType ();
00084 spRcvr->put_FileName (A2W (str));
00085
00086 spRcvr->put_Comment (A2W (vshcp.get_VideoTitle ()));
00087
00088 spRcvr->put_FlashVideoDownload (TRUE);
00089 }
00090
00091 spRcvr->AddDownload ();
00092 }
00093
00094 DWORD WINAPI CFDMFlashVideoDownloads::_threadCreateDownload(LPVOID lp)
00095 {
00096 USES_CONVERSION;
00097
00098 BSTR bstrUrl = (BSTR) lp;
00099
00100 _pwndFVDownloads->CreateDownload (W2A (bstrUrl));
00101
00102 SysFreeString (bstrUrl);
00103
00104 return 0;
00105 }
00106
00107 STDMETHODIMP CFDMFlashVideoDownloads::CreateFromUrl(BSTR bstrUrl)
00108 {
00109 UIThread *thr = (UIThread*) RUNTIME_CLASS (UIThread)->CreateObject ();
00110 thr->set_Thread (_threadCreateDownload, SysAllocString (bstrUrl));
00111 thr->CreateThread ();
00112
00113 return S_OK;
00114 }