Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[audio] fixed m3u and pls audio stream support #1604

Merged
merged 1 commit into from
Aug 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.charset.StandardCharsets;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -67,22 +67,32 @@ private InputStream createInputStream() throws AudioException {
try {
switch (extension) {
case M3U_EXTENSION:
for (final String line : Files.readAllLines(Paths.get(URI.create(url)))) {
if (!line.isEmpty() && !line.startsWith("#")) {
url = line;
break;
try (Scanner scanner = new Scanner(new URL(url).openStream(), StandardCharsets.UTF_8.name())) {
while (true) {
String line = scanner.nextLine();
if (!line.isEmpty() && !line.startsWith("#")) {
url = line;
break;
}
}
} catch (NoSuchElementException e) {
// we reached the end of the file, this exception is thus expected
}
break;
case PLS_EXTENSION:
for (final String line : Files.readAllLines(Paths.get(URI.create(url)))) {
if (!line.isEmpty() && line.startsWith("File")) {
final Matcher matcher = PLS_STREAM_PATTERN.matcher(line);
if (matcher.find()) {
url = matcher.group(1);
break;
try (Scanner scanner = new Scanner(new URL(url).openStream(), StandardCharsets.UTF_8.name())) {
while (true) {
String line = scanner.nextLine();
if (!line.isEmpty() && line.startsWith("File")) {
final Matcher matcher = PLS_STREAM_PATTERN.matcher(line);
if (matcher.find()) {
url = matcher.group(1);
break;
}
}
}
} catch (NoSuchElementException e) {
// we reached the end of the file, this exception is thus expected
}
break;
default:
Expand Down