Jquery - URL 检查器(RSS、音频或视频播客)
我尝试使用 google feed api 构建一个 url 检查器。
我的问题:
1: if(result)
检查不起作用。也许是异步问题?
2:对于RSS、音频/视频播客检查有什么想法吗?我确信,我在响应中收到了音频/视频文件的网址(但我现在是盲目的)。
我的想法是检查这个网址。
// somthing like that
if(typeof xxxx == 'undefined') -> rss feed
if xxxx.match(/mp3|wav|XXX/gi) -> audio feed
if xxxx.match(/mpg|avi|flv/gi) -> video feed
JS
$(document).ready(function()
{
// valid rss feed
var result = urlCheck('http://www.bild.de/rssfeeds/vw-home/vw-home-16725562,short=1,sort=1,view=rss2.bild.xml');
if(result){ console.warn('result1 is a '+result.urlIsA+' '); console.dir(result); }
// valid video podcast
var result = urlCheck('http://www.tagesschau.de/export/video-podcast/webl/tagesschau/');
if(result){ console.warn('result1 is a '+result.urlIsA+' '); console.dir(result); }
// valid audio podcast
var result = urlCheck('http://chaosradio.ccc.de/chaosradio-latest.rss');
if(result){ console.warn('result1 is a '+result.urlIsA+' '); console.dir(result); }
});
function urlCheck(url)
{
var feed = new google.feeds.Feed(url);
feed.setResultFormat(google.feeds.Feed.MIXED_FORMAT);
feed.setNumEntries('1');
feed.load(function(result)
{
if (!result.error)
{
var allEntries = result.feed.entries;
console.info(url);
console.dir(allEntries);
/* if(XXX.match(/XXXX/,gi)) {
allEntries.urlIsA = 'rss feed';
return allEntries;
}
if(XXX.match(/XXXX/,gi)) {
allEntries.urlIsA = 'audio podcast';
return allEntries;
}
if(XXX.match(/XXXX/,gi)) {
allEntries.urlIsA = 'video podcast';
return allEntries;
} */
return false;
}
else { return false; }
});
}
工作示例
http://jsbin.com/unikak/edit#javascript,html
注意:您必须将代码复制到 * 中.html 文件,否则您会从 jsBin
收到错误
google.feeds.Feed is not a constructor
i try to built an url checker using the google feed api.
My problems:
1: the if(result)
check doesn't work. Maybe an async problem?
2: any ideas for the rss,audio/video podcast check? I'm sure, i get in the response an url to the audio/video file (but i'm blind at the moment).
My idea is to check this url.
// somthing like that
if(typeof xxxx == 'undefined') -> rss feed
if xxxx.match(/mp3|wav|XXX/gi) -> audio feed
if xxxx.match(/mpg|avi|flv/gi) -> video feed
JS
$(document).ready(function()
{
// valid rss feed
var result = urlCheck('http://www.bild.de/rssfeeds/vw-home/vw-home-16725562,short=1,sort=1,view=rss2.bild.xml');
if(result){ console.warn('result1 is a '+result.urlIsA+' '); console.dir(result); }
// valid video podcast
var result = urlCheck('http://www.tagesschau.de/export/video-podcast/webl/tagesschau/');
if(result){ console.warn('result1 is a '+result.urlIsA+' '); console.dir(result); }
// valid audio podcast
var result = urlCheck('http://chaosradio.ccc.de/chaosradio-latest.rss');
if(result){ console.warn('result1 is a '+result.urlIsA+' '); console.dir(result); }
});
function urlCheck(url)
{
var feed = new google.feeds.Feed(url);
feed.setResultFormat(google.feeds.Feed.MIXED_FORMAT);
feed.setNumEntries('1');
feed.load(function(result)
{
if (!result.error)
{
var allEntries = result.feed.entries;
console.info(url);
console.dir(allEntries);
/* if(XXX.match(/XXXX/,gi)) {
allEntries.urlIsA = 'rss feed';
return allEntries;
}
if(XXX.match(/XXXX/,gi)) {
allEntries.urlIsA = 'audio podcast';
return allEntries;
}
if(XXX.match(/XXXX/,gi)) {
allEntries.urlIsA = 'video podcast';
return allEntries;
} */
return false;
}
else { return false; }
});
}
Working example
http://jsbin.com/unikak/edit#javascript,html
notice: your must copy the code in an *.html file, otherwise you get an error from jsBin
google.feeds.Feed is not a constructor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改您的正则表达式,以便仅匹配字符串末尾的
mpg
:/(mpg|avi|flv/)$/gi
不要使用
return
,而是使用回调函数:在结果检查器中:
Change your RegExps, so that only
mpg
at the end of a string is matched:/(mpg|avi|flv/)$/gi
Instead of using
return
, use callback functions:At your result checker: