开发者

Jquery - Url checker (rss, audio or video podcast)

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('h开发者_如何学运维ttp://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


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:

function urlCheck(url, callback){

....
//Insread of return false:
callback(false);
//Instead of return true:
callback(true);

At your result checker:

urlCheck("http://....", function(result){
    if(result){
         console.warn(...);
    } else {
       //..
    }
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜