aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-09-30 13:49:45 -0700
committerScott Jackson <daneren2005@gmail.com>2016-09-30 13:49:45 -0700
commitbc2709aa309d4e62f35903bffb486b1eb1e5726f (patch)
tree5edf9f0b171eec9aedfbea408340b5971a5ca424 /app
parent538cb889c45559f7af54fee33801547de719fbfc (diff)
downloaddsub-bc2709aa309d4e62f35903bffb486b1eb1e5726f.tar.gz
dsub-bc2709aa309d4e62f35903bffb486b1eb1e5726f.tar.bz2
dsub-bc2709aa309d4e62f35903bffb486b1eb1e5726f.zip
Fixes #738: Add support for radio station playlists
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java
index 16082cbd..c39e9f61 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java
@@ -18,10 +18,18 @@
*/
package github.daneren2005.dsub.fragments;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -37,6 +45,8 @@ import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.UpdateView;
public class SelectInternetRadioStationFragment extends SelectRecyclerFragment<InternetRadioStation> {
+ private static final String TAG = SelectInternetRadioStationFragment.class.getSimpleName();
+
@Override
public int getOptionsMenu() {
return R.menu.abstract_top_menu;
@@ -67,6 +77,7 @@ public class SelectInternetRadioStationFragment extends SelectRecyclerFragment<I
return null;
}
+ getStreamFromPlaylist(item);
downloadService.download(item);
return null;
}
@@ -94,6 +105,40 @@ public class SelectInternetRadioStationFragment extends SelectRecyclerFragment<I
return false;
}
+ private void getStreamFromPlaylist(InternetRadioStation internetRadioStation) {
+ if(internetRadioStation.getStreamUrl() != null && (internetRadioStation.getStreamUrl().indexOf(".m3u") != -1 || internetRadioStation.getStreamUrl().indexOf(".pls") != -1)) {
+ try {
+ URL url = new URL(internetRadioStation.getStreamUrl());
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+ try {
+ BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ String line;
+ while((line = in.readLine()) != null) {
+ // Not blank line or comment
+ if(line.length() > 0 && line.indexOf('#') != 0) {
+ if(internetRadioStation.getStreamUrl().indexOf(".m3u") != -1) {
+ internetRadioStation.setStreamUrl(line);
+ break;
+ } else {
+ if(line.indexOf("File1=") == 0) {
+ internetRadioStation.setStreamUrl(line.replace("File1=", ""));
+ } else if(line.indexOf("Title1=") == 0) {
+ internetRadioStation.setTitle(line.replace("Title1=", ""));
+ }
+ }
+ }
+ }
+ } finally {
+ connection.disconnect();
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Failed to get stream data from playlist");
+ }
+
+ }
+ }
+
private void displayInternetRadioStationInfo(final InternetRadioStation station) {
List<Integer> headers = new ArrayList<>();
List<String> details = new ArrayList<>();