forked from cqr/PlayerHater
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move file into place and change names and types some
- Loading branch information
Showing
3 changed files
with
113 additions
and
114 deletions.
There are no files selected for viewing
114 changes: 0 additions & 114 deletions
114
legacyLibraryProject/PlayerHater/src/org/prx/playerhater/mediaplayer/UriParser.java
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
legacyLibraryProject/PlayerHater/src/org/prx/playerhater/util/PlaylistParser.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../../../src/main/java/org/prx/playerhater/util/PlaylistParser.java |
112 changes: 112 additions & 0 deletions
112
src/main/java/org/prx/playerhater/util/PlaylistParser.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package org.prx.playerhater.util; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
|
||
import org.apache.http.Header; | ||
import org.apache.http.HttpEntity; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.client.methods.HttpHead; | ||
|
||
import android.net.Uri; | ||
|
||
public final class PlaylistParser { | ||
|
||
private static String[] PLS_MIME_TYPES = new String[] { "audio/scpls", | ||
"audio/x-scpls" }; | ||
private static String[] M3U_MIME_TYPES = new String[] { "audio/x-mpegurl" }; | ||
|
||
public static Uri[] parsePlaylist(Uri uri) { | ||
try { | ||
HttpClient httpclient = new DefaultHttpClient(); | ||
HttpResponse response = httpclient.execute(new HttpHead(uri | ||
.toString())); | ||
Header contentType = response.getEntity().getContentType(); | ||
if (contentType != null) { | ||
String mimeType = contentType.getValue().split(";")[0].trim(); | ||
|
||
for (String plsMimeType : PLS_MIME_TYPES) { | ||
if (plsMimeType.equalsIgnoreCase(mimeType)) { | ||
return parsePls(uri); | ||
} | ||
} | ||
|
||
for (String m3uMimeType : M3U_MIME_TYPES) { | ||
if (m3uMimeType.equalsIgnoreCase(mimeType)) { | ||
return parseM3u(uri); | ||
} | ||
} | ||
} | ||
} catch (Exception e) {} | ||
return new Uri[] { uri }; | ||
} | ||
|
||
private static Uri[] parsePls(Uri uri) { | ||
try { | ||
HttpClient httpclient = new DefaultHttpClient(); | ||
HttpResponse response = httpclient.execute(new HttpGet(uri.toString())); | ||
HttpEntity entity = response.getEntity(); | ||
InputStream inputStream = entity.getContent(); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader( | ||
inputStream)); | ||
String header = reader.readLine(); | ||
if (header.trim().equalsIgnoreCase("[playlist]")) { | ||
String line; | ||
ArrayList<Uri> uriList = new ArrayList<Uri>(); | ||
do { | ||
line = reader.readLine(); | ||
if (line != null) { | ||
if (line.startsWith("File")) { | ||
String fileName = line.substring( | ||
line.indexOf("=") + 1).trim(); | ||
uriList.add(Uri.parse(fileName)); | ||
} | ||
} | ||
} while (line != null); | ||
if (uriList.size() > 0) { | ||
Uri[] res = new Uri[uriList.size()]; | ||
return uriList.toArray(res); | ||
} | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return new Uri[] { uri }; | ||
} | ||
|
||
private static Uri[] parseM3u(Uri uri) { | ||
|
||
try { | ||
HttpClient httpclient = new DefaultHttpClient(); | ||
HttpResponse response = httpclient.execute(new HttpGet(uri | ||
.toString())); | ||
HttpEntity entity = response.getEntity(); | ||
InputStream inputStream = entity.getContent(); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader( | ||
inputStream)); | ||
String line; | ||
ArrayList<Uri> uriList = new ArrayList<Uri>(); | ||
do { | ||
line = reader.readLine(); | ||
if (line != null) { | ||
if (!line.startsWith("#")) { | ||
uriList.add(Uri.parse(line.trim())); | ||
} | ||
} | ||
} while (line != null); | ||
if (uriList.size() > 0) { | ||
Uri[] res = new Uri[uriList.size()]; | ||
return uriList.toArray(res); | ||
} | ||
} catch (Exception e) { | ||
|
||
} | ||
return new Uri[] { uri }; | ||
} | ||
|
||
} |