Skip to content

Commit

Permalink
Bugfix: Use auto discovery instead of using the same endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sfuhrm committed Aug 5, 2023
1 parent 99b89c5 commit 7ddff26
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/de/sfuhrm/radiorecorder/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package de.sfuhrm.radiorecorder;

import de.sfuhrm.radiobrowser4j.EndpointDiscovery;
import de.sfuhrm.radiobrowser4j.Paging;
import de.sfuhrm.radiobrowser4j.RadioBrowser;
import java.io.IOException;
Expand All @@ -25,6 +26,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -53,8 +55,15 @@ public class Main {
/** Id for {@link ConsumerContext}. */
private static int nextId = 1;

private static RadioBrowser newRadioBrowser(Params params) {
RadioBrowser browser = new RadioBrowser("https://de1.api.radio-browser.info/",
private static RadioBrowser newRadioBrowser(Params params) throws IOException {
EndpointDiscovery endpointDiscovery = new EndpointDiscovery(GITHUB_URL);
Optional<String> endpoint = endpointDiscovery.discover();

if (! endpoint.isPresent()) {
throw new Error("Radiobrowser endpoint discovery failed");
}

RadioBrowser browser = new RadioBrowser(endpoint.get(),
params.getTimeout() * 1000,
GITHUB_URL,
params.getProxy() != null ? params.getProxy().toExternalForm() : null,
Expand All @@ -68,7 +77,7 @@ private static RadioBrowser newRadioBrowser(Params params) {
* @param params the command line.
* @return the sanitized URLs.
*/
private static List<Radio> sanitize(List<String> urls, Params params) {
private static List<Radio> sanitize(List<String> urls, Params params) throws IOException {
List<Radio> result = new ArrayList<>();

RadioBrowser radioBrowser = newRadioBrowser(params);
Expand Down Expand Up @@ -210,7 +219,7 @@ private static void listMixers() {
helper.print(System.out);
}

private static void listStations(List<String> names, Params params) {
private static void listStations(List<String> names, Params params) throws IOException {
List<Radio> radios = sanitize(names, params);

if (radios.isEmpty()) {
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/de/sfuhrm/radiorecorder/MainIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2017 Stephan Fuhrmann.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.sfuhrm.radiorecorder;

import org.junit.Test;

import java.io.IOException;

public class MainIntegrationTest {

@Test
public void testlistStation() throws IOException, InterruptedException {
Main.main(new String[] {"-Z", "synth"});
}
}

0 comments on commit 7ddff26

Please sign in to comment.