Skip to content

Commit

Permalink
Merge pull request #9 from choorp/luneos-testing
Browse files Browse the repository at this point in the history
Initial LuneOS support
  • Loading branch information
Garrett committed Mar 4, 2016
2 parents 86680cd + f1ce969 commit 026de20
Show file tree
Hide file tree
Showing 16 changed files with 360 additions and 120 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
/build
/deploy
2 changes: 1 addition & 1 deletion fxos/manifest.webapp
Expand Up @@ -2,7 +2,7 @@
"name": "FoxCasts",

"description": "A fully-featured podcast app for your FirefoxOS device.",
"version": "1.2.0",
"version": "1.3.0",
"launch_path": "/index.html",
"icons": {
"256": "/assets/icon-256.png",
Expand Down
Binary file modified icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions lib/xmlprequest/XmlpRequest.js
@@ -0,0 +1,79 @@
/**
Allows for cross-domain JSONp style requests for XML documents, via YQL,
converted and returned in JSON format.
*/

enyo.kind({
name: "enyo.XmlpRequest",
kind: enyo.JsonpRequest,
published: {
/**
If true, on a query failure, it will re-query the XML url/params
to get the plain-text content and return it in the format of
{"error":"unescaped-plain-text-content"}
*/
detailedErrors:true
},
//* @protected
callbackName: "callback",
//* @public
//* Executes the XML document request via YQL, with an optional parameters object
go: function(inParams) {
var parts = this.url.split("?");
var uri = parts.shift() || "";
var args = parts.join("?").split("&");
args.push(enyo.Ajax.objectToQuery(inParams || {}));
this.xmlUrl = [uri, args.join("&")].join("?");
this.url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'"
+ encodeURIComponent(this.xmlUrl) + "'&format=json";
inParams = {};
this.inherited(arguments);
},
//* @protected
respond: function(inValue) {
if(inValue && inValue.query) {
inValue = inValue.query.results || undefined;
if(!inValue && this.detailedErrors) {
var fallbackUrl = "http://query.yahooapis.com/v1/public/yql?q=use%20%22http"
+ "%3A%2F%2Fwww.datatables.org%2Fdata%2Fhtmlstring.xml%22%20"
+ "as%20htmlstring%3B%20select%20*%20from%20htmlstring%20where"
+ "%20url%3D'"+ encodeURIComponent(this.xmlUrl) + "'&format=json";
this.fallbackTextRequest = new enyo.JsonpRequest({url:fallbackUrl,
callbackName:"callback"});
this.fallbackTextRequest.response(this, "fallbackTextCallback");
this.fallbackTextRequest.go();
return;
}
}
this.inherited(arguments);
},
fallbackTextCallback: function(inSender, inResponse) {
if(inResponse && inResponse.query) {
inResponse = inResponse.query.results || undefined;
if(inResponse && inResponse.result) {
inResponse = inResponse.result;
//plain text is within auto-generated html, so extract it
var prefix = "<html>\n \n \n <head>\n \n \n <meta content=\"HTML Tidy for Java (vers. 26 Sep 2004), see www.w3.org\" name=\"generator\"/>\n \n \n <title/>\n \n \n </head>\n \n \n <body>\n \n \n <p>"
var suffix = "</p>\n \n \n </body>\n \n\n</html>";
inResponse = inResponse.replace(prefix, "");

inResponse = inResponse.replace(suffix, "");
var iOpen = inResponse.indexOf("<");
var iClose = inResponse.lastIndexOf(">");

//if still contains html, we know it wasn't plain text to begin with
if(iOpen>-1 && iOpen<iClose) {
inResponse = {"error":"Query is not in XML format"};
} else {
inResponse = {"error":inResponse};
}
} else if(inResponse && !inResponse.result) {
inResponse = {"error":"Unknown XML query failure"};
} else if(!inResponse) {
inResponse = {"error":"Unable to connect to server"};
}
}
this.respond(inResponse);
}
});
3 changes: 3 additions & 0 deletions lib/xmlprequest/package.js
@@ -0,0 +1,3 @@
enyo.depends(
'XmlpRequest.js'
);
11 changes: 11 additions & 0 deletions luneos/appinfo.json
@@ -0,0 +1,11 @@
{
"title": "FoxCasts",
"id": "com.choorp.app.foxcasts",
"version": "1.3.0",
"vendor": "Garrett Downs",
"vendor_url": "https://github.com/choorp/foxcasts",
"type": "web",
"main": "index.html",
"icon": "icon.png",
"uiRevision": "2"
}
7 changes: 7 additions & 0 deletions luneos/framework_config.json
@@ -0,0 +1,7 @@
{
"logLevel": 99,
"debuggingEnabled": true,
"timingEnabled": false,
"logEvents": true,
"escapeHTMLInTemplates" : true
}
6 changes: 2 additions & 4 deletions source/package.js
@@ -1,9 +1,7 @@
enyo.depends(
// Layout library
"$lib/layout",
// Onyx UI library
"$lib/onyx", // To theme Onyx using Theme.less, change this line to $lib/onyx/source,
// CSS/LESS style files
"$lib/onyx",
"$lib/xmlprequest",
"style",
// Model and data definitions
"data",
Expand Down
1 change: 1 addition & 0 deletions source/style/main.less
Expand Up @@ -125,6 +125,7 @@ a {
position: relative;
margin: 2px 2px -2px 2px;
width: 32%; /* desired width */
max-width: 200px;
}
.podcast-tile:before {
content: "";
Expand Down
2 changes: 1 addition & 1 deletion source/views/App.js
Expand Up @@ -8,7 +8,7 @@ enyo.kind({
fit: true,
components:[
{kind: "Panels", name: "menuSlider", fit:true, classes: "", arrangerKind: "CarouselArranger", index: 1, draggable: true, narrowFit: false, onTransitionFinish: "", components: [
{name: "menu", kind: "Menu", style: "width: 80vw;", onChangePanel: "changePanel", onRefreshAll: "checkForUpdates"},
{name: "menu", kind: "Menu", style: "width: 80vw; max-width: 300px;", onChangePanel: "changePanel", onRefreshAll: "checkForUpdates"},
{kind: "Panels", fit:true, classes: "panels-container", arrangerKind: "CardArranger", index: 1, draggable: false, onTransitionFinish: "panelChanged", components: [
{name: "player", kind: "Player"},
{name: "subscriptionsGrid", kind: "SubscriptionsGrid", onOpenPodcast: "showPodcastDetail"},
Expand Down
197 changes: 136 additions & 61 deletions source/views/FeedParser.js
@@ -1,76 +1,151 @@
var ParseFeed = function(xml, podcast, dateLimit) {
// console.log("Begin parseFeed");
var ParseFeed = function(xml, podcast, dateLimit, dataType) {
console.log("Begin parseFeed");
console.log(xml);

if (!dateLimit) {
dateLimit = 0;
}

var items = xml.getElementsByTagName("item");

var episodes = [];

for (var i=0; i< items.length; i++) {
var e = items[i];
// console.log(e);
// if (dataType == 'xml') {
if (xml.contentType && xml.contentType == 'text/xml') {
console.log('Parsing episodes as XML');

var date, author, title, description, abort;
try {
date = e.getElementsByTagName("pubDate")[0].textContent;
date = Date.parse(date);
// console.log("Most recent: " + podcast.mostRecent + " This Episode: " + date);
// console.log("Datelimit: " + dateLimit);
if (date <= dateLimit) {
console.log("Episode " + i + " is not new. Stopping.");
break;
} else {
// console.log("Episode " + i + " is new. Continuing.");
var items = xml.getElementsByTagName("item");
for (var i = 0; i < items.length; i++) {
var e = items[i];
// console.log(e);

var date, author, title, description, abort;
try {
date = e.getElementsByTagName("pubDate")[0].textContent;
date = Date.parse(date);
// console.log("Most recent: " + podcast.mostRecent + " This Episode: " + date);
// console.log("Datelimit: " + dateLimit);
if (date <= dateLimit) {
console.log("Episode " + i + " is not new. Stopping.");
break;
} else {
// console.log("Episode " + i + " is new. Continuing.");
}
} catch (e) {
date = "?";
abort = true;
}
try {
author = e.getElementsByTagName("author")[0].textContent;
} catch (e) {
author = "?";
}
try {
title = e.getElementsByTagName("title")[0].textContent;
} catch (e) {
title = "?";
}
try {
description = e.getElementsByTagName("description")[0].textContent;
} catch (e) {
description = "?";
}

// Let's see if this episode is even worth keeping around
try {
enclosure = e.getElementsByTagName("enclosure")[0].getAttribute("url");
abort = false;
} catch (e) {
abort = true;
}
} catch (e) {
date = "?";
abort = true;
}
try {
author = e.getElementsByTagName("author")[0].textContent;
} catch (e) {
author = "?";
}
try {
title = e.getElementsByTagName("title")[0].textContent;
} catch (e) {
title = "?";
}
try {
description = e.getElementsByTagName("description")[0].textContent;
} catch (e) {
description = "?";
}

// Let's see if this episode is even worth keeping around
try {
enclosure = e.getElementsByTagName("enclosure")[0].getAttribute("url");
abort = false;
} catch (e) {
abort = true;
if (!abort) {
episodes.push({
name: podcast.name || podcast.collectionName,
date: date,
author: author,
title: title,
description: description,
logo100: podcast.artworkUrl100,
logo600: podcast.artworkUrl600,
length: e.getElementsByTagName("enclosure")[0].getAttribute("length"),
type: e.getElementsByTagName("enclosure")[0].getAttribute("type"),
fileUrl: e.getElementsByTagName("enclosure")[0].getAttribute("url"),
localUrl: "",
progress: 0,
duration: 0,
played: "false",
downloaded: "false",
inprogress: "false"
});
}
}
} else {
console.log('Parsing episodes as JSON');

var items = xml.rss.channel.item;
for (var i = 0; i < items.length; i++) {
var e = items[i];
// console.log(e);

if (!abort) {
episodes.push({
name: podcast.name || podcast.collectionName,
date: date,
author: author,
title: title,
description: description,
logo100: podcast.artworkUrl100,
logo600: podcast.artworkUrl600,
length: e.getElementsByTagName("enclosure")[0].getAttribute("length"),
type: e.getElementsByTagName("enclosure")[0].getAttribute("type"),
fileUrl: e.getElementsByTagName("enclosure")[0].getAttribute("url"),
localUrl: "",
progress: 0,
duration: 0,
played: "false",
downloaded: "false",
inprogress: "false"
});
var date, author, title, description, abort;
try {
date = e.pubDate;
date = Date.parse(date);
// console.log("Most recent: " + podcast.mostRecent + " This Episode: " + date);
// console.log("Datelimit: " + dateLimit);
if (date <= dateLimit) {
console.log("Episode " + i + " is not new. Stopping.");
break;
} else {
// console.log("Episode " + i + " is new. Continuing.");
}
} catch (e) {
date = "?";
abort = true;
}
try {
author = e.author[0];
} catch (e) {
author = "?";
}
try {
title = e.title;
} catch (e) {
title = "?";
}
try {
description = e.description;
} catch (e) {
description = "?";
}

// Let's see if this episode is even worth keeping around
if (!e.enclosure.url) {
abort = true;
} else {
abort = false;
}

if (!abort) {
episodes.push({
name: podcast.name || podcast.collectionName,
date: date,
author: author,
title: title,
description: description,
logo100: podcast.artworkUrl100,
logo600: podcast.artworkUrl600,
length: e.enclosure.length,
type: e.enclosure.type,
fileUrl: e.enclosure.url,
localUrl: "",
progress: 0,
duration: 0,
played: "false",
downloaded: "false",
inprogress: "false"
});
}
}
}

Expand Down

0 comments on commit 026de20

Please sign in to comment.