Closed rustyhodge closed 8 years ago
It looks like we need to do the following to do so:
id
and title
from the xml file (for the station
variable and description utilized in popup.js
(to populate the select list in popup.html
)popup.js
and popup.html
to reflect these changes; looks like we'll need a method to parse the XML file here and another to populate the select list since it is hard coded.I'm not fluent in coffeescript but I'll be happy to give this a shot when I have some free time.
Oh hey, this would be nice! I just released version 0.0.0.4 with Folk Forward and some other new stations. I'd be happy with it trying to fetch the XML list of stations, and if that fails for whatever reason, falling back to a hardcoded list of known stations.
One thing holding me back from doing this is the lack of CORS headers on the Soma server. When my extension's popup tries to make an AJAX request to http://api.somafm.com/channels.xml, I get the following error:
You would have to add particular headers to your server to allow me to fetch this XML feed via AJAX. See http://enable-cors.org/ for more info.
Out of curiosity, if you just got to somafm.com/channels.xml does it work?
On Jun 20, 2015, at 11:36 AM, Sarah Vessels notifications@github.com wrote:
One thing holding me back from doing this is the lack of CORS headers on the Soma server. When my extension's popup tries to make an AJAX request to http://api.somafm.com/channels.xml, I get the following error:
You would have to add particular headers to your server to allow me to fetch this XML feed via AJAX. See http://enable-cors.org/ for more info.
— Reply to this email directly or view it on GitHub.
Actually, I think I just changed the server config so that header is there now.
Can you confirm that this is working for http://api.somafm.com/channels.xml
thanks
On Jun 20, 2015, at 11:36 AM, Sarah Vessels notifications@github.com wrote:
One thing holding me back from doing this is the lack of CORS headers on the Soma server. When my extension's popup tries to make an AJAX request to http://api.somafm.com/channels.xml, I get the following error:
You would have to add particular headers to your server to allow me to fetch this XML feed via AJAX. See http://enable-cors.org/ for more info.
— Reply to this email directly or view it on GitHub.
It did not appear to work. I am still seeing an error when independently trying to fetch the XML from another sever. Did you restart the server that you updated the settings on? Also, really cool of you to be this involved with this extension :+1:
We are sending that header in the request for curl -i api.somafm.com/channels.xml
I wonder if it has to do with the fact that we're by default gzipping it?
HTTP/1.1 200 OK Server: nginx/1.1.19 Date: Sun, 21 Jun 2015 23:30:00 GMT Content-Type: application/xml Content-Length: 4249 Connection: keep-alive Last-Modified: Sun, 21 Jun 2015 23:29:45 GMT ETag: "37c0d5-6b5a-5190f88454c40"-gzip Vary: Accept-Encoding Content-Encoding: gzip Expires: Sun, 21 Jun 2015 23:30:10 GMT Cache-Control: max-age=10 Access-Control-Allow-Origin: * X-Proxy-Cache: HIT Accept-Ranges: bytes
On Jun 21, 2015, at 4:26 PM, James notifications@github.com wrote:
It did not appear to work. I am still seeing an error when independently trying to fetch the XML from another sever. Did you restart the server that you updated the settings on? Also, really cool of you to be this involved with this extension
� Reply to this email directly or view it on GitHub.
That could be; I am not sure and some Google/StackOverflow searching didn't yield much (to be fair I just browsed the first two pages of search results). Curl requests on my local machine and http://onlinecurl.com/ do work, though.
Here's something you can use to test it using jQuery's $.ajax
. You may need to open the developer console to see the specific CORS error if it exists. If you want to play around and setup another endpoint that doesn't serve a GZipped version I left you the ability to change the URL. http://jsfiddle.net/codeforcoffee/t911vapt/
Does fetching it from http://somafm.com/channels.xml work?
That's still being served off the main server with Apache not nginx.
On Jun 21, 2015, at 5:03 PM, James notifications@github.com wrote:
That could be; I am not sure and some Google/StackOverflow searching didn't yield much (to be fair I just browsed the first two pages of search results). Curl requests on my local machine and http://onlinecurl.com/ do work, though.
Here's something you can use to test it using jQuery's $.ajax. You may need to open the developer console to see the specific CORS error if it exists. If you want to play around and setup another endpoint that doesn't serve a GZipped version I left you the ability to change the URL. http://jsfiddle.net/codeforcoffee/t911vapt/
— Reply to this email directly or view it on GitHub.
I cleared my browser cache and the request to http://api.somafm.com/channels.xml returns a valid XMLDocument
object. So this should work a-ok now! I'll start fiddling with this to see if I can write anything helpful. I have very little exposure to CoffeeScript but I'll do my best.
@moneypenny I threw this together to return an array of channel objects from the current API. Inside of popup.coffee you could update your $.get
call inside of fetch_soma_channels()
to something like this; I've went ahead and parsed the XML so hopefully you find this somewhat helpful.
$.ajax({
url: 'http://api.somafm.com/channels.xml',
dataType: "xml",
success:function(data) {
var channels = data.getElementsByTagName("channel");
var channelsObjArray = [];
for (var inc = 0; inc < channels.length; inc++) {
var channel = channels[inc].childNodes;
//channel[3].textContent is the channel description
//channel[11] is the image for the station
//channel[21] is I believe the highest quality station URL (highestpls)
//console.log("Title: " + channel[1].textContent);
//console.log("Description: " + channel[3].textContent);
//console.log("MP3: " + channel[21].textContent);
var channelObj = {
title: channel[1].textContent,
description: channel[3].textContent,
mp3: channel[21].textContent
};
channelsObjArray.push(channelObj);
}
console.log(channelsObjArray);
}
});
Tested and working here: http://jsfiddle.net/codeforcoffee/t911vapt/ (check the Developer Console the results)
@rustyhodge I saw that the API documentation on Soma.FM is currently not up to available; could you confirm if a channel's highestpls
is the best quality playlist?
Thanks, James! I'll try this out.
I just started tinkering around with this in my own fork. I've had some luck. Good news! The JSON loads now because CORS is enabled. Thanks, @rustyhodge.
@moneypenny, in the popup.coffee
file, I've been tinkering with the following method (and googling coffee script along the way). I've found that I can get the stations to load correctly using something along these lines:
fetch_soma_channels: ->
# Github Issue #5 fix by code-for-coffee
# Fetching from the soma.fm channels JSON now that CORS is enabled
console.log 'Fetching channels.json...'
url = 'http://api.somafm.com/channels.json'
on_success = (data) ->
console.log 'Retrieved channels.json successfully!'
console.log data
for station in data
@station_option = $('option')
@station_option.prop 'value': station.id
console.log @station_option
#append to @station_select.append('<option value="test">hi</option>')
I need to clean it up a bit, verify everything works, and then submit a PR. Would you prefer me to call fetch_soma_channels
in the constructor? Great news is that the JSON object from the channels.json file contains the exact value you need in your select list value
; for each station in the array of objects there is an id
key that is equal to what you had in the HAML file.
No ETA on finishing this up and submitting a PR but I should clean it up soon.
I have finally finished this and submitted a pull request to @moneypenny.
Fixed in version 0.0.0.7 of the extension.
The list of current channels should be grabbed from http://api.somafm.com/channels.xml so you don't have to worry about updating the source when a new channel is added. I looks like this: