Created
September 27, 2011 02:42
-
-
Save aaronksaunders/1244181 to your computer and use it in GitHub Desktop.
Code For Parsing RSS Feed from YouTube used in Appcelerator Application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var processRSS = function(_feedURL, _tableView) { | |
// create table view data object | |
var data = []; | |
Ti.API.info(" "+_feedURL); | |
var xhr = Ti.Network.createHTTPClient(); | |
xhr.open("GET",_feedURL.replace(/\"/g,"")); | |
xhr.setRequestHeader('Accept', 'application/json'); | |
xhr.onerror = function(e) { | |
alert(e); | |
Ti.API.info(" "+e); | |
}; | |
xhr.onload = function() { | |
try { | |
Ti.API.info(" "+xhr.responseText); | |
var data = JSON.parse(xhr.responseText).feed.entry; | |
Ti.API.info(" "+data); | |
//_tableView.window.title = doctitle; | |
var x = 0; | |
for (var c=0;c<data.length;c++) { | |
var i = data[c] | |
var title = i.title.$t; | |
var description = i.content.$t; | |
var video_url = i.media$group.media$content[0].url; | |
var _duration = i.media$group.media$content[0].duration; | |
var _durObject = secondsToTime(_duration); | |
var video_duration = _durObject.m + ":" + _durObject.s; | |
var video_thumb_url = i.media$group.media$thumbnail[0].url; | |
var video_twitter_url = i.link[0].href; | |
//var video_thumb = data[c].media$thumbnail; | |
Ti.API.debug( title +" "+ description +" "+ video_url); | |
var row = Ti.UI.createTableViewRow({ | |
height:'auto', | |
//backgroundColor:'#ADD8E6', | |
width:'100%' | |
}); | |
var thumb = null; | |
if ( Titanium.Platform.name == 'iPhone OS') { | |
// Create new imageView for thumbnail | |
thumb = Ti.UI.createImageView({ | |
left:1, | |
height:'auto', | |
width:120, | |
image:video_thumb_url | |
}); | |
} else { | |
thumb = Ti.UI.createView({ | |
left:1, | |
height:'90', | |
width:120, | |
backgroundImage : video_thumb_url | |
}); | |
} | |
var label = Ti.UI.createLabel({ | |
text: '( ' + video_duration + ' ) ' + title, | |
height:'auto', | |
left:thumb.width + 5, | |
top:5, | |
color:'#333399', | |
right:5 | |
}); | |
row.add(thumb); | |
row.add(label); | |
row.video_url = video_url; | |
row.video_duration = video_duration; | |
row.our_title = title; | |
row.our_description = description; | |
row.video_twitter_url = video_twitter_url.replace('\\u003d','=').replace("&feature=youtube_gdata",""); | |
row.video_thumb = video_thumb_url; | |
Ti.API.debug(" in loop " + row.video_url); | |
Ti.API.debug(" in loop " + row.video_twitter_url); | |
Ti.API.debug(" in loop " + row.video_thumb); | |
Ti.API.debug(" in loop " + row.video_duration); | |
data[x++] = row; | |
} | |
_tableView.fireEvent('reloadData', {rowData:data}); | |
} catch(E) { | |
alert(E); | |
Ti.API.error(" "+E); | |
} | |
}; | |
xhr.send(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment