【发布时间】:2013-02-06 10:20:29
【问题描述】:
我正在尝试使用 youtube 数据 api 获取 youtube 播放列表的总持续时间。例如,我从 http://gdata.youtube.com/feeds/api/playlists/63F0C78739B09958 下载响应,我的想法是遍历每个 <yt:duration='xxx'/> 出现,其中 xxx 是每个视频的持续时间(以秒为单位),并将它们相加以获得总播放列表运行时间。
为了得到每个我使用CAtlRegExp 和以下字符串:
<yt:duration seconds='{[0-9]+}'/>
但是它只匹配第一次出现,而不匹配其余的任何(参考下面粘贴的源代码,循环只迭代一次)。
我尝试了其他一些正则表达式字符串,例如
(<yt:duration seconds='{[0-9]+}'/>)(<yt:duration seconds='{[0-9]+}'/>)*
但是他们也没有工作(同样的原因)。
这是源代码的摘录,其中 for 循环仅迭代一次,因为 mcDuration.m_uNumGroups 等于 1:
//get video duration
CAtlRegExp<> reDurationFinder;
CAtlREMatchContext<> mcDuration;
REParseError status = reDurationFinder.Parse(_T("<yt:duration seconds='{[0-9]+}'/>"));
if ( status != REPARSE_ERROR_OK )
{
// Unexpected error.
return false;
}
if ( !reDurationFinder.Match(sFeed, &mcDuration) ) //i checked it with debug, sFeed contains full response from youtube data api
{
//cannot find video url
return false;
}
m_nLengthInSeconds = 0;
for ( UINT nGroupIndex = 0; nGroupIndex < mcDuration.m_uNumGroups; ++nGroupIndex )
{
const CAtlREMatchContext<>::RECHAR* szStart = 0;
const CAtlREMatchContext<>::RECHAR* szEnd = 0;
mcDuration.GetMatch(nGroupIndex, &szStart, &szEnd);
ptrdiff_t nLength = szEnd - szStart;
m_nLengthInSeconds += _ttoi(CString(szStart, nLength));
}
我怎样才能使CAtlRegExp 匹配<yt:duration ... 的所有出现?
【问题讨论】:
标签: c++ regex youtube-api atl