Knowledge Base Nr: 00193 videotext.cpp - http://www.swe-kaiser.de

MFC: Videotextseiten extrahieren und Uhrzeit mit Videotext synchronisieren

  
class CVideoTextSupport
{
public:
CVideoTextSupport();
virtual ~CVideoTextSupport();

int LoadPage(const char* lpszSender, const int nFirstPage, const int nLastPage, CStringArray& arPage
, bool bAppend = false, bool bSyncTime = false, int nTimeout_ms = 60000);

int TimeSync(const char* lpszSender, const int nPage, int nTimeout_ms = 60000);
};

int CVideoTextSupport::LoadPage(const char* lpszSender, const int nFirstPage, const int nLastPage, CStringArray& arPage, bool bAppend, int nTimeout_ms)
{
if (!bAppend)
arPage.RemoveAll();

//temp. scriptfile generieren
const char* SCRIPTFILE = "c:\\temp\\vtscript.vts";
char PAGEFILE[100] = "c:\\temp\\vtout.";

CString strScript, str, strFile;

strScript.Format("VTPLUS SCRIPT\n"
"TVSTATION %s\n"
, lpszSender);

for (int n=nFirstPage; n<=nLastPage; n++)
{
strFile.Format("%s%d", PAGEFILE, n);

::DeleteFile(strFile);

str.Format("GET %d\n"
"EXPORT %d FILE=%s\n"
"CLOSE %d\n"
, n, n, (const char*)strFile, n);
strScript += str;
}

strScript += "EXITAPPL\n";

FILE* fp = fopen(SCRIPTFILE, "wt");
if (!fp)
return -1;

fprintf(fp, strScript);
fclose(fp);

//aufruf: "C:\Program Files\vtplus\vtplus32.exe" /se:\mystuff\vtprog_1.vts
CProcessSupport proc;
CString strParam;

//sprintf(PAGEFILE, "c:\\temp\\%c%d.txt", lpszSender[0]=='A'?'a':'z', nPage);
strParam.Format("/s%s", SCRIPTFILE);

int nErr = proc.RunProcess(VT_APPLICATION, strParam, 0, SW_HIDE);
//int nErr = proc.RunProcess(VT_APPLICATION, strParam, 45*1000, SW_MINIMZE);
//int nErr = proc.RunProcess("c:\\winnt\\system32\\cmd.exe", "e:\\mystuff\\getvideotext.bat", 45*1000, SW_SHOW);
//int nErr = proc.RunProcess("e:\\mystuff\\getvideotext.bat", "", 0, SW_SHOW);
if (nErr != PS_OK)
return -2;

DWORD dwNow = ::GetTickCount();
MSG msg;

//sehr seltsam aber die hauppauge applikation startet ohne diese messageloop nicht!
while (::GetMessage(&msg, NULL, 0, 0)) /* die Nachrichtenschleife abarbeiten*/
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);

//timeout?
if (::GetTickCount() - dwNow > nTimeout_ms)
return -3;

//letztes file erzeugt?
int nAttr = ::GetFileAttributes(strFile);
if (nAttr > 0)
{
break;
}
}

//outputfile einlesen und zurückgeben
for (n=nFirstPage; n<=nLastPage; n++)
{
strFile.Format("%s%d", PAGEFILE, n);
fp = fopen(strFile, "rt");
if (!fp)
return -3;

char szLine[500] = {0};
while (fgets(szLine, sizeof(szLine), fp) != NULL)
{
arPage.Add(szLine);
}

fclose(fp);
}

return 0; //ok
}

void CExtractvtDlg::DoGetTVProg(const char* lpszSender)
{
CVideoTextSupport vtsupp;
CStringArray arPage;

int nErr = vtsupp.LoadPage(lpszSender, 301, 304, arPage);

for (int n=0; n<arPage.GetSize(); n++)
{
if (arPage[n][1] == ' ')
{
arPage.RemoveAt(n);
n--;
}
}

m_lb.ResetContent();
for (n=0; n<arPage.GetSize()-1; n++)
{
CString strLine;

strLine.Format("%s\t%s\t%s\t%s"
, lpszSender
, (const char*)arPage[n].Mid(1, 6)
, (const char*)arPage[n+1].Mid(1, 6)
, (const char*)arPage[n].Mid(14, 23) );

m_lb.AddString(strLine);
}
}

void CExtractvtDlg::OnButton1()
{
DoGetTVProg("ARD");
}

void CExtractvtDlg::OnZdf()
{
DoGetTVProg("ZDF");
}


###### diese scriptdatei wird generiert um die videotextseite zu holen:
VTPLUS SCRIPT

TVSTATION ARD
GET 301
EXPORT 301 FILE=c:\temp\a301.txt
CLOSE 301
GET 302
EXPORT 302 FILE=c:\temp\a302.txt
CLOSE 302
GET 303
EXPORT 303 FILE=c:\temp\a303.txt
CLOSE 303
GET 304
EXPORT 304 FILE=c:\temp\a304.txt
CLOSE 304

EXITAPPL

###### beispieldatei einer videotextseite im ascii-format:
302 ZDFtext Di 02.03.04 11:28:20
ZDFtext Heute
Programm Dienstag, 2.März

14.00 heute - in Deutschland
14.15 Wunderbare Welt
Amazonas - In
schwindelnder Höhe ... 312
15.00 heute - Sport
15.15 Discovery
Eiskalt - Tod unter
Null ................. 313
16.00 heute - in Europa
16.15 Herzschlag - Die Retter
Große Sprünge ........ 314
17.00 heute - Wetter UT
17.15 hallo Deutschland .... 365
17.45 Leute heute .......... 366
18.00 SOKO 5113
Ritt in den Tod ...... 316



300 <- ab 19.00 Uhr -> 303
###################