I've been asked to make unofficial online streaming android application for a certain radio station.
I've experience with streaming in android for certain mp3 or whatever stream.
But I don't know the stream url to provide in mediaPlayer.setDataSource(url).
Is there any way to get the stream url from the ofiicial streaming page for ex. this radio stream?
not that hard,
if you take a look at the page source, you'll see that it uses to stream the audio via shoutcast.
this is the stream url
"StreamUrl": "http://stream.radiotime.com/listen.stream?streamIds=3244651&rti=c051HQVbfRc4FEMbKg5RRVMzRU9KUBw%2fVBZHS0dPF1VIExNzJz0CGQtRcX8OS0o0CUkYRFJDDW8LEVRxGAEOEAcQXko%2bGgwSBBZrV1pQZgQZZxkWCA4L%7e%7e%7e",
which returns a JSON like that:
{
"Streams": [
{
"StreamId": 3244651,
"Reliability": 92,
"Bandwidth": 64,
"HasPlaylist": false,
"MediaType": "MP3",
"Url": "http://mp3hdfm32.hala.jo:8132",
"Type": "Live"
}
]
}
i believe that's the url you need:
http://mp3hdfm32.hala.jo:8132
this is the station WebSite
Edited ZygD's answer for python 3.x.:
import re
import urllib.request
import string
url1 = input("Please enter a URL from Tunein Radio: ");
request = urllib.request.Request(url1);
response = urllib.request.urlopen(request);
raw_file = response.read().decode('utf-8');
API_key = re.findall(r"StreamUrl\":\"(.*?),\"",raw_file);
#print API_key;
#print "The API key is: " + API_key[0];
request2 = urllib.request.Request(str(API_key[0]));
response2 = urllib.request.urlopen(request2);
key_content = response2.read().decode('utf-8');
raw_stream_url = re.findall(r"Url\": \"(.*?)\"",key_content);
bandwidth = re.findall(r"Bandwidth\":(.*?),", key_content);
reliability = re.findall(r"lity\":(.*?),", key_content);
isPlaylist = re.findall(r"HasPlaylist\":(.*?),",key_content);
codec = re.findall(r"MediaType\": \"(.*?)\",", key_content);
tipe = re.findall(r"Type\": \"(.*?)\"", key_content);
total = 0
for element in raw_stream_url:
total = total + 1
i = 0
print ("I found " + str(total) + " streams.");
for element in raw_stream_url:
print ("Stream #" + str(i + 1));
print ("Stream stats:");
print ("Bandwidth: " + str(bandwidth[i]) + " kilobytes per second.");
print ("Reliability: " + str(reliability[i]) + "%");
print ("HasPlaylist: " + str(isPlaylist[i]));
print ("Stream codec: " + str(codec[i]));
print ("This audio stream is " + tipe[i].lower());
print ("Pure streaming URL: " + str(raw_stream_url[i]));
i = i + 1
input("Press enter to close")
The provided answers didn't work for me. I'm adding another answer because this is where I ended up when searching for radio stream urls.
Radio Browser is a searchable site with streaming urls for radio stations around the world:
http://www.radio-browser.info/
Search for a station like FIP, Pinguin Radio or Radio Paradise, then click the save button, which downloads a PLS file that you can open in your radioplayer (Rhythmbox), or you open the file in a text editor and copy the URL to add in Goodvibes.
Shahar's answer was really helpful, but I found it quite tedious to do this all myself, so I made a nifty little Python program:
import re
import urllib2
import string
url1 = raw_input("Please enter a URL from Tunein Radio: ");
open_file = urllib2.urlopen(url1);
raw_file = open_file.read();
API_key = re.findall(r"StreamUrl\":\"(.*?),",raw_file);
#print API_key;
#print "The API key is: " + API_key[0];
use_key = urllib2.urlopen(str(API_key[0]));
key_content = use_key.read();
raw_stream_url = re.findall(r"Url\": \"(.*?)\"",key_content);
bandwidth = re.findall(r"Bandwidth\":(.*?),", key_content);
reliability = re.findall(r"lity\":(.*?),", key_content);
isPlaylist = re.findall(r"HasPlaylist\":(.*?),",key_content);
codec = re.findall(r"MediaType\": \"(.*?)\",", key_content);
tipe = re.findall(r"Type\": \"(.*?)\"", key_content);
total = 0
for element in raw_stream_url:
total = total + 1
i = 0
print "I found " + str(total) + " streams.";
for element in raw_stream_url:
print "Stream #" + str(i + 1);
print "Stream stats:";
print "Bandwidth: " + str(bandwidth[i]) + " kilobytes per second."
print "Reliability: " + str(reliability[i]) + "%"
print "HasPlaylist: " + str(isPlaylist[i]) + "."
print "Stream codec: " + str(codec[i]) + "."
print "This audio stream is " + tipe[i].lower() + "."
print "Pure streaming URL: " + str(raw_stream_url[i]) + ".";
i = i + 1
raw_input("Press enter to close TMUS.")
It's basically Shahar's solution automated.
When you go to a stream url, you get offered a file. feed this file to a parser to extract the contents out of it. the file is (usually) plain text and contains the url to play.
Related
I have been attempting to code a button into my adobe PDF form using an article from quora. The goal is to click a button and it opens an email box with the "to", "subject line", "body" and the "PDF" attaching to the email without having to save the pdf somewhere locally on the clients computer.
These are the three different codes I have found and attempted to use. No matter what I do, I end up getting an "Unterminated String Literal" on line 3 where the body field starts. I have tried adding/removing everything I can think of. ;"'{{:.
Please help if you can! See code below.
var customSubject = this.getField("MyTextField").value;
var mailtoUrl = "mailto:email#email.com?subject=" + Information Form;
this.submitForm({Thank you for your considerate attention to the attached pdf. Let me know if you need anything.; further.
cURL: mailtoUrl, cSubmitAs: "PDF" });
var customSubject = this.getField("MyTextField").value;
var mailtoUrl = "mailto:email#email.com=" + Information Form;
this.submitForm({Thank you for your considerate attention to the attached pdf. Let me know if you need anything.
cURL: mailtoUrl, bPDF:true});
var cToAddr = "email#email.comm"
var cSubLine = "Information Form - " + this.getField(No1LastName) + ", " + this.getField(No2LastName) + "
var cBody = "Please find the attached Information Form. Thank you for your considerate attention to the attached."
this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody});
I found that declaring a variable for the email portion worked. I was able to include custom to, cc, subject, and body, as well as attaching the PDF.
var customREmail = this.getField("ReqEmail").value;
var customAEmail = this.getField("AgyEmail").value;
var customAgency = this.getField("Agency").value;
var customLName = this.getField("Lease").value;
var customBAddr = this.getField("BldgAddr").value;
var customBCity = this.getField("BldgCity").value;
var mailtoUrl =
"mailto:XXX#XXX.XXX?cc=" +
customREmail +
"; " +
customAEmail +
"&subject=Compliance%20Request: " +
customAgency +
", " +
customLName +
" - " +
customBAddr +
", " +
customBCity +
"&body=Please review the attached request.%0A%0AThank you,%0A%0A";
this.submitForm({
cURL:mailtoUrl, cSubmitAs:"PDF", bPDF:true
});
I wrote a js code that exported data into .csv table. My problem is that when I open the file Excel cannot show Czech diacritics like č or š. Anyone can help me?
function exportData(){
console.log("Started export to CSV.");
const rows = [
["Procesor" + " " + String(window.localStorage.getItem("CPU"))],
["RAM" + " " + String(window.localStorage.getItem("RAM"))],
["Displej" + " " + String(window.localStorage.getItem("display"))],
["Baterie" + " " + String(window.localStorage.getItem("battery"))],
["Grafická karta" + " " + String(window.localStorage.getItem("GPU"))],
];
let csvContent = "data:text/csv;charset=utf-8,"
+ rows.map(e => e.join(",")).join("\n");
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "parametry.csv");
document.body.appendChild(link); // Required for FF
link.click(); // This will download the data file named "my_data.csv".
}`
On my mac, the UTF-8 CSV gets displayed properly, so this is a bug in Excel.
There's a similar question on SO that might be of interest to you, but here's a summary:
Open Excel
Import the data using Data-->Import External Data --> Import Data
Select the file type of "csv" and browse to your file
In the import wizard change the File_Origin to "65001 UTF" (or choose correct language character identifier)
Change the Delimiter to comma
Select where to import to and Finish
Credit to original answer: Is it possible to force Excel recognize UTF-8 CSV files automatically?
I have a chrome extension that, right now, is purely a cosmetic addition to a Counter-Strike forum and matchmaking site. I'm trying to implement some Javascript to show players ranks when looking at the statistics of a match. Currently, it looks like this: statistics page imgur
I'm trying to add a new column to the left of where players' names appear that shows their ranks. Ranks are currently only stored on the players' profile page, so I'm trying to write code that will go to each players' profile (currently hyperlinked to their name), get their rank and display that as text.
I have 0 understanding of Javascript despite trying to learn it many times but this is a heavily requested feature and I'd like to implement it for my users.
sample statistics page
sample profile page
As of a few months ago, the following code worked:
function findRanks(i) {
var allUsers = $(document).find("#body-match-total" + i + " tr");
$.each($(document).find("#body-match-total" + i + " tr"), function(index, value){
var userLink = "https://play.esea.net/users/" + allUsers[index].children[0].children[1].innerHTML
$.get(userLink, function(data) {
var parsed = $('<div/>').append(data);
rank = $(parsed).find("#rankGraph h1").text();
allUsers[index].children[0].children[1].innerHTML += " (" + rank + ") ";
});
});
}
findRanks(1);
findRanks(2)
Was missing a bracket. Thanks to some random guy on ESEA forums for the help.
Here is the functional code for people with the same issue
function findRanks(i) {
var allUsers = $(document).find("#body-match-total" + i + " tr");
$.each($(document).find("#body-match-total" + i + " tr"), function(index, value){
var userLink = "https://play.esea.net/users/" + allUsers[index].children[0].children[1].innerHTML
$.get(userLink, function(data) {
data = data.replace(/<img[^>]*>/g,"");
var parsed = $('<div/>').append(data);
rank = $(parsed).find("#rankGraph h1").text();
allUsers[index].children[0].children[1].innerHTML += " (" + rank + ") ";
});
});
}
findRanks(1);
findRanks(2);
This is the code i have so far.
At the end of the email, I would like to provide social icons like these ones that i found free online. And to lead them to corresponding links i have. Minus the skype.
https://codepen.io/anon/pen/QgjeXw
function sendEmails() {
var allData,counter,emailAddress,fourRowsOfData,i,lastRow,
message,messageStart,messageEnd,numRows,
row,sheet,startRow,studentName,subject;
//USER INPUT
startRow = 2; // First row of data to process
numRows = 4; // Number of rows to process
subject = "Camp Pursuit: Report Card ";
messageStart = "Dear Parents,"+'\n' +'\n' +
"Every week at Camp Pursuit, we ask the teachers to make observations about how the kiddos did." +'\n' +
"We know that one week isn't enough to truly know a child, so we call this our " +"Glows, Grows, & Apropos." +'\n' +
"Meaning..." + '\n' +'\n' +
"Glows: Positive things the teacher noticed" +'\n' +
"Grows: Areas for continued growth" +'\n' +
"Apropos: Ways to continue your son/daughter's enrichment" +'\n' +
"We hope you appreciate seeing what the teachers saw last week, and perhaps you can use some of"+'\n' +
"the recommendations for further enrichment this summer. Feel free to let us know your thoughts on the camp through our anonymous online survey."+'\n' +
"Your feedback helps us improve the experience for all kiddos! "+'\n' +
"Survey Link: https://docs.google.com/forms/d/1g4LvA9a8sdKECr1yvp5uOoPnvKACFm3HvbTBfvQGRyo/viewform?usp=send_form" +'\n' +
"We look forward to seeing your child at our programs throughout the year!" +'\n' +
"Sincerely, "+'\n' +
"The Camp Pursuit Team"
+'\n';
//END USER INPUT
sheet = SpreadsheetApp.getActiveSheet();
lastRow = sheet.getLastRow();
allData = sheet.getRange(startRow, 1, lastRow-startRow, 10);// Get All data first
counter = 0;
while (counter < lastRow-startRow) {
Logger.log('counter: ' + counter)
fourRowsOfData = sheet.getRange(startRow + counter, 1, numRows, 6).getValues();
emailAddress = fourRowsOfData[0][0]; // First column of first row
Logger.log('emailAddress: ' + emailAddress)
studentName = fourRowsOfData[0][1];
messageEnd = "";//Reset on every outer loop
for (i = 0; i < numRows; i++) {//loop numRows times - once for each row
row = fourRowsOfData[i];
messageEnd = messageEnd + '\n' +
"Class: " + row[2] + '\n' +'\n' +
"Glows: " + row[3]+ '\n' +
"Grows: " + row[4] +'\n' +
"Apropos: " + row[5] +'\n';
}
message = messageStart + "\n" + studentName + "\n" + messageEnd;
MailApp.sendEmail(emailAddress, subject, message);//Send the email outside of inner loop
counter+=numRows;//Increment counter by number of rows to process
}
}
I don't think you will be able to use examples from codepen as they involve lots of code (e.g. for displaying hover states, etc). However, you could save the buttons as images and store them in your Drive or elsewhere.
The next step is to get the blob for your image from external URL
var imageBlob = UrlFetchApp.fetch(yourImageUrl).getBlob();
or from Drive
var imageBlob = DriveApp.getFileById(yourFileId).getBlob();
Build the string for the html body of your email. Use 'br' tags for line breaks. Wrap your images in 'a' tags to get them to link to external websites. In 'src' attribute of the 'img' tag, create a unique id for your image blob and put it after 'cid'.
var body = "<h1> Header </h1> <br />" +
"<a href='www.example.com'><img src='cid:uid' /></a> Image <br />" +
"Content";
Instead of string parameters, pass the following object to MailApp.sendEmail() method. At runtime, the script will parse the string stored in 'body' variable and create html output, using cid identifiers to retrieve images from inlineImages object. The property names of 'inlineImages' object must match the ids you put created for your images in 'body'
MailApp.sendEmail({
to: "recipient#example.com",
subject: "subject",
htmlBody: body,
inlineImages: {
uid: imageBlob
}
});
Concatenating the string to produce html body is not the best solution though. Consider creating a reusable html template using HtmlService https://developers.google.com/apps-script/guides/html/
I have the domain http://whatthecatdragged.in/ forwarded (cloaked) to http://moppy.co.uk/wtcdi/
The root page (index.html) uses Ajax to load the content. At the original host (moppy.co.uk/wtcdi) the page and all content loads. However, at the domain forwarded domain (whatthecatdragged.in), some of the content does not load. Has it something to do with the way .each is used to fire off Ajax calls, as mentioned by AnthonyWJones?
I've attempted to debug this, but peculiarly turning on the Firebug console in Firefox 3.5 actually seems to make all the content load.
// Content building code:
$(function() {
// Set a few variables (no need for secrecy with Flickr API key).
var apiKey = 'myapikey';
// var tags = '';
var tagsArr = new Array();
// Get the photos of flickr user WhatTheCatDraggedIn.
// This Ajax call always seems to complete.
$.getJSON('http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key=' +
apiKey +
'&user_id=46206266#N05&extras=date_taken,tags&format=json&jsoncallback=?',
function(data) {
// Set some variables to ensure alldata is fecthed from second API
// call (below) before building majority of content.
var totalExpected = data.photos.total;
var totalFetched = 0;
var photohtml = '';
// For each photo, do the following:
$.each(data.photos.photo, function(i, item) {
// Set size of photo thumbnail to display.
var size = 's';
var append = '';
if (i == 0) {
// Display most recent thumbnail larger, and add a line
// break for small pics beneath it.
size = 'm';
append = '<br />'
}
//Only display thmbnails of 4 most recent catches (1 large, 3 small).
if (i <= 3) {
var photoSrc =
'http://farm' + item.farm + '.static.flickr.com/' +
item.server + '/' + item.id + '_' + item.secret + '_' +
size + '.jpg'
//Each thumbnail links to that photo's Flickr page.
var flickrPage =
'http://flickr.com/photos/' + item.owner +
'/' + item.id + '/';
// Each thumbnail has a big tooltip, with tags formatted appropriately.
var formattedTags = item.tags.replace(/\s/g, "<br />");
formattedTags = formattedTags.replace(/cat/, "cat: ");
formattedTags = formattedTags.replace(/loc/, "location: ");
formattedTags = formattedTags.replace(/victim/, "victim: ");
formattedTags = formattedTags.replace(/status/, "status: ");
formattedTags = formattedTags.replace(/floor/, " floor");
formattedTags = formattedTags.replace(/toy/, " toy");
//Append the built html to one varable for adding to page shortly
photohtml +=
'<a class="flickr-page-link" href="' +
flickrPage + '"><img src = "' +
photoSrc + '" title="' + formattedTags + '"/>' +
append + '</a>';
}
var photoID = item.id;
// Get the detailed photo information (including tags) for the photo.
// This is the call that perhaps fails or at least content
// generated after this call does not load.
$.getJSON(
'http://api.flickr.com/services/rest/?&method=flickr.photos.getInfo&api_key=' +
apiKey + '&photo_id=' + photoID +
'&format=json&jsoncallback=?',
function(data) {
if (data.photo.tags.tag != '') {
$.each(data.photo.tags.tag, function(j, item) {
// Place all tags in an aray for easier handling.
tagsArr.push(item.raw);
});
// Incrememt number of photos fetched.
totalFetched += 1;
// Have we got them all?
if (totalFetched == totalExpected)
fetchComplete();
}
});
// Builds a shedload more content once all JSON calls are completed.
function fetchComplete() {
// ### BUILD VICTIM list ###
// format a regex to match tags beginnign : "victim: "
var vicRe = /^v[a-z]+:\s([a-z\s]+)/
// Match the regex to the tags and count number of matches per tag.
var vicCounts = tagsArr.countVals(vicRe);
var victimsHtml = "";
// For each victim.
for (var i in vicCounts) {
var strippedTag = [i].toString().replace(/\W/g, "");
console.debug(strippedTag);
// Add a line of html with the type of victim and the number of victims of that type
victimsHtml +=
"<a href='http://flickr.com/photos/46206266#N05/tags/victim" +
strippedTag + "/'>" + [i] +
" (" + vicCounts[i] + ") </a><br />";
};
// Replace existing HTML with new version.
$('#types-dragged').html(victimsHtml);
// ### BUILD STATUS PIE CHART ###
// Build a theme for chart colours.
var wtcdicharttheme = {
colors: ['#C66800', '#D3C70B', '#DD3D0B', '#D30729',
'#DDA70B'
],
marker_color: '#000000',
font_color: '#000000',
background_colors: ['#ffffff', '#ffffff']
};
// Create a new chart object, include css id of canvas
// where chart will be drawn.
var g = new Bluff.Pie('status', '275x250');
// Set a theme and stuff.
g.set_theme(wtcdicharttheme);
// No title, as this exists via the raw page HTML.
g.title = '';
g.legend_font_size = "50px";
g.marker_font_size = "20px";
// Build a regex string to match tags beginning "status: ".
var statRe = /^s[a-z]+:\s([a-z\s]+)/
// Match regex to tags and return an object with tag
// names and number of occurences.
var statCounts = tagsArr.countVals(statRe);
// For each status.
for (var i in statCounts) {
// Add data to the chart
g.data([i], [statCounts[i]]);
};
// Draw the chart.
g.draw();
// ### BUILD LOCATION LIST ###
// Build a regex that matches tags beginning "loc: "
var locRe = /^l[a-z]+:\s([a-z\s]+)/
// Match regex to tags and return an object with
// tag names and number of occurences.
var locCounts = tagsArr.countVals(locRe);
var locatHtml = "";
// For each location.
for (var i in locCounts) {
var strippedTag = [i].toString().replace(/\W/g, "");
// Add a line of html with the location and the
//number of times victims found in that location.
locatHtml +=
"<a href='http://flickr.com/photos/46206266#N05/tags/loc" +
strippedTag + "/'>" + [i] + " (" +
locCounts[i] + ") <br />";
};
// Replace existing html with newly built information.
$('#locations').html(locatHtml);
// ### BUILD CAT LIST ###
// Build a regex that maches tags beginning "cat: ".
var catRe = /^c[a-z]+:\s([a-z_\s]+)/
//Match regex to find number of catches each cat has made
var catCounts = tagsArr.countVals(catRe);
// For each cat.
for (var i in catCounts) {
var strippedTag = [i].toString().replace(/\W/g, "");
// Insert number of catches to div titled "(catname)-catch"
$('#' + [i] + '-catch').html(
"<a href='http://flickr.com/photos/46206266#N05/tags/" +
strippedTag + "/'>" + catCounts[i] + "</a>");
};
}
});
// Insert total dragged onto page.
$('#total-dragged').html(data.photos.total);
// Insert photos onto page.
$('#latest-catches').html(photohtml);
// Add tooltips to the images from Flickr.
$('img').each(function() {
$(this).qtip({
style: {
name: 'wtcdin'
},
position: {
target: 'mouse',
adjust: {
x: 8,
y: 10
}
}
})
});
});
});
UPDATE 1: I contacted the domain name company, their advice was basically "don't use JavaScript". Still can't see why it would work under one domain name and not another... Could it be to do with the fact that they "forward" the domain by means of a frame?
The browser will block AJAX requests that are sent outside of the domain that the script is hosted on. This is most likely the cause of your problem from the sound of things.
EDIT: I've found the problem, you have console.debug() calls in your script. This method is defined by the Firebug Console which is why it's only working while the Console is active. Try removing any calls to console.debug() and see how it goes.