jquery - Fetching the link to a video from an RSS feed item -


i new web development , first chrome extension. here script fetch , parse rss feeds :

$(document).ready(function() {     // fetch rss feeds , parse them     $.get(rssurl, function(data) {       var $xml = $(data);       $xml.find("item").each(function() {         var $this = $(this),             item = {                      title: $this.find("title").text(),                      link: $this.find("link").text(),                      description: $this.find("description").text(),                      pubdate: $this.find("pubdate").text(),                      url : $this.find("enclosure").attr("url"),                      author: $this.find("author").text()                    };          // add array         items.push(item);         if(items.length == 1){           $(".title").html(item.title);           $(".description").html(item.url);           $(".author").html(item.author);            $(video).attr({"src" : item.url});         }       });// end of each()     });// end of $.get() });   

the problem, this:

url : $this.find("enclosure").attr("url"),   

the idea video play not despite being in .mp4.
here feeds parsing: http://feeds.podtrac.com/ttkj5t05olm$

n.b. have allowed urls in chrome manifest

try add below condition before add item array:

if($("enclosure[url$='.mp4']",this).length>0){} 

[attribute$="value"] jquery attribute end selector. select element have specified attribute value ending given string.

code:

$(document).ready(function() {     // fetch rss feeds , parse them     $.get(rssurl, function(data) {       var $xml = $(data);       $xml.find("item").each(function() {         //if item's enclosure url attribute in .mp4 format... add video array         if($("enclosure[url$='.mp4']",this).length>0){           var $this = $(this),               item = {                        title: $this.find("title").text(),                        link: $this.find("link").text(),                        description: $this.find("description").text(),                        pubdate: $this.find("pubdate").text(),                        url : $this.find("enclosure").attr("url"),                        author: $this.find("author").text()                      };            // add array           items.push(item);            if(items.length == 1){             $(".title").html(item.title);             $(".description").html(item.url);             $(".author").html(item.author);              $(video).attr({"src" : item.url});           }         }       });// end of each()     });// end of $.get() }); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -