Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sfuhrm/radiorecorder
Browse files Browse the repository at this point in the history
  • Loading branch information
sfuhrm committed Dec 9, 2023
2 parents cc91665 + bea4c63 commit 4f0093e
Show file tree
Hide file tree
Showing 34 changed files with 178 additions and 347 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8, 11, 17 ]
client: [ JAVA_NET, APACHE_CLIENT_4, APACHE_CLIENT_5 ]
java: [ 8, 11, 17, 21 ]
client: [ JAVA_NET, APACHE_CLIENT_5 ]
proxy: [ NO, YES ]
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Restrictions:

## Downloading & installation

The current version can be downloaded for Debian, CentOS and MacOS X systems here:
The current version can be downloaded for Debian, CentOS and Mac OS X systems here:

https://github.com/sfuhrm/radiorecorder/releases

Expand All @@ -50,7 +50,7 @@ Releases typically contain files named like this for downloading:
* `radiorecorder-xxx-bin.tar.gz`: A program-only archive in tar.gz format that requires a Java runtime installed on your system.
* `radiorecorder-xxx-bin.zip`: A program-only archive in ZIP format that requires a Java runtime installed on your system.

You can chose whether you prefer an installation with the runtime as a package or care for the Java runtime yourself.
You can choose whether you prefer an installation with the runtime as a package or care for the Java runtime yourself.
The latter makes sense when you're on Windows, Aarch64, X86, or some other system with no dedicated installer.

## Usage
Expand Down
18 changes: 10 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>de.sfuhrm</groupId>
<artifactId>radiorecorder</artifactId>
<version>1.7.1-SNAPSHOT</version>
<version>1.8.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Radio Recorder</name>
Expand Down Expand Up @@ -38,6 +38,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
</properties>
Expand All @@ -48,15 +49,10 @@
<artifactId>radiobrowser4j</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.3</version>
<version>5.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -139,6 +135,12 @@
<version>5.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down Expand Up @@ -218,7 +220,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.2</version>
<version>3.6.3</version>
<configuration>
<excludePackageNames>de.sfuhrm.foo</excludePackageNames>
<failOnError>false</failOnError>
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/de/sfuhrm/radiorecorder/ConnectionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import de.sfuhrm.radiorecorder.http.HttpConnectionBuilderFactory;
import de.sfuhrm.radiorecorder.metadata.MimeType;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
Expand Down Expand Up @@ -86,19 +86,18 @@ protected void configureClient(HttpConnectionBuilder builder) {
/** Configures the builder with the configuration
* from the {@link #consumerContext}.
* @param builder the builder to configure.
* @throws IOException if configuration fails due to an IO problem.
* */
protected void configure(@NonNull HttpConnectionBuilder builder) throws IOException {
protected void configure(@NonNull HttpConnectionBuilder builder) {
configureIcecast(builder);
configureTimeout(builder);
configureClient(builder);
configureProxy(builder);
}

/** Opens the url using a configured connection. */
private HttpConnection openConnection(URL url) throws RadioException {
private HttpConnection openConnection(URI uri) throws RadioException {
try {
HttpConnectionBuilder builder = builderFactory.newInstance(url);
HttpConnectionBuilder builder = builderFactory.newInstance(uri);
configure(builder);
return builder.build();
} catch (IOException ex) {
Expand All @@ -109,10 +108,10 @@ private HttpConnection openConnection(URL url) throws RadioException {
private static final long GRACE_PERIOD = 5000;

/** Consumes the given URL.
* @param url the URL to process. Must be non-null.
* @param uri the URL to process. Must be non-null.
* @throws NullPointerException if url is null.
* */
public void consume(@NonNull URL url) {
public void consume(@NonNull URI uri) {
boolean first = true;
boolean loop = consumerContext.isReconnect();
do {
Expand All @@ -121,14 +120,15 @@ public void consume(@NonNull URL url) {
try {
Thread.sleep(GRACE_PERIOD);
} catch (InterruptedException ex) {
log.debug("Interrupted", ex);
}
log.info("Reconnecting.");
}
try {
HttpConnection connection = openConnection(url);
first = false;
HttpConnection connection = openConnection(uri);
Consumer<HttpConnection> consumer = consumerFromContentType(consumerContext, connection.getContentType());
consumer.accept(connection);
first = false;
loop = false;
} catch (RadioException re) {
loop &= re.isRetryable();
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/de/sfuhrm/radiorecorder/ConsumerContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
package de.sfuhrm.radiorecorder;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.time.Duration;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -46,20 +45,19 @@ public class ConsumerContext {
private final Radio radio;

@Getter
private final URL url;
private final URI uri;

private final Params params;

/** Constructor for a consumer context.
* @param id numerical unique id of this context.
* @param radio the radio station to process in this context.
* @param params the command line parameters.
* @throws MalformedURLException if the URL of the radio station was malformed.
* */
public ConsumerContext(int id, Radio radio, Params params) throws MalformedURLException {
public ConsumerContext(int id, Radio radio, Params params) {
this.id = id;
this.radio = radio;
this.url = radio.getUrl();
this.uri = radio.getUri();
this.params = Objects.requireNonNull(params);
}

Expand Down Expand Up @@ -161,7 +159,7 @@ public HttpConnectionBuilderFactory.HttpClientType getHttpClient() {
/** The HTTP proxy to use or NULL.
* @return the HTTP proxy requested in the command line.
* */
public URL getProxy() {
public URI getProxy() {
return params.getProxy();
}
}
4 changes: 2 additions & 2 deletions src/main/java/de/sfuhrm/radiorecorder/ListHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import java.util.function.Function;

class ListHelper<T> {
private List<T> list;
private List<ColumnInfo> columns;
private final List<T> list;
private final List<ColumnInfo> columns;
@Getter
@Setter
@AllArgsConstructor
Expand Down
45 changes: 22 additions & 23 deletions src/main/java/de/sfuhrm/radiorecorder/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import de.sfuhrm.radiobrowser4j.Paging;
import de.sfuhrm.radiobrowser4j.RadioBrowser;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -69,7 +68,7 @@ private static RadioBrowser newRadioBrowser(Params params) throws IOException {
RadioBrowser browser = new RadioBrowser(endpoint.get(),
params.getTimeout() * 1000,
GITHUB_URL,
params.getProxy() != null ? params.getProxy().toExternalForm() : null,
params.getProxy() != null ? params.getProxy().toASCIIString() : null,
null,
null);
return browser;
Expand All @@ -86,22 +85,24 @@ private static List<Radio> sanitize(List<String> urls, Params params) throws IOE
RadioBrowser radioBrowser = newRadioBrowser(params);
int limit = params.getStationLimit();
for (String urlString : urls) {
try {
URL url = new URL(urlString); // parse the url
URI uri = URI.create(urlString); // parse the url

String scheme = uri.getScheme();
if (scheme != null) {
Radio s = new Radio();
s.setName("User-Suppplied URL");
s.setUrl(url);
s.setUri(uri);
result.add(s);
} catch (MalformedURLException ex) {
log.debug("Parameter not an URL: "+urlString, ex);
} else {
log.debug("Parameter not an URL: {}", urlString);
try {
UUID uuid = UUID.fromString(urlString);
List<Station> stations = radioBrowser.listStationsBy(SearchMode.BYUUID, uuid.toString()).collect(Collectors.toList());
List<Radio> radios = stations.stream().map(Radio::fromStation).collect(Collectors.toList());
result.addAll(radios);
}
catch (IllegalArgumentException e) {
log.debug("Parameter not an UUID: "+urlString, ex);
log.debug("Parameter not an UUID: {}", urlString);
List<Station> stations = radioBrowser.listStationsBy(
Paging.at(0, limit),
SearchMode.BYNAME,
Expand All @@ -114,7 +115,7 @@ private static List<Radio> sanitize(List<String> urls, Params params) throws IOE
return result;
}

private static ConsumerContext toConsumerContext(Params p, Radio radio) throws MalformedURLException, UnsupportedEncodingException {
private static ConsumerContext toConsumerContext(Params p, Radio radio) throws MalformedURLException {
return new ConsumerContext(nextId++, radio, p);
}

Expand All @@ -127,7 +128,7 @@ private static class CastItem {
}

private static class MyListener implements ChromeCastsListener {
private List<CastItem> discovered = new ArrayList<>();
private final List<CastItem> discovered = new ArrayList<>();
@Override
public void newChromeCastDiscovered(ChromeCast chromeCast) {
CastItem castItem = new CastItem(chromeCast.getTitle(), chromeCast.getModel(), chromeCast.getAddress(), chromeCast.getAppTitle());
Expand Down Expand Up @@ -157,10 +158,10 @@ private static void listCastDevices() throws InterruptedException, IOException {
}

ListHelper<CastItem> helper = new ListHelper<>(instance.discovered);
helper.addColumn("Title", i -> i.getTitle());
helper.addColumn("Model", i -> i.getModel());
helper.addColumn("Address", i -> i.getAddress());
helper.addColumn("App Title", i -> i.getAppTitle());
helper.addColumn("Title", CastItem::getTitle);
helper.addColumn("Model", CastItem::getModel);
helper.addColumn("Address", CastItem::getAddress);
helper.addColumn("App Title", CastItem::getAppTitle);
helper.print(System.out);
}

Expand Down Expand Up @@ -202,17 +203,15 @@ public static void main(String[] args) throws IOException, InterruptedException
}

List<Thread> threadList = new ArrayList<>();
List<RadioRunnable> radioRunnables = new ArrayList<>();
radios.stream().forEach(radio -> {
try {
log.info("Starting radio: {}", radio);
RadioRunnable r = new RadioRunnable(toConsumerContext(params, radio));
radioRunnables.add(r);
Thread t = new Thread(r, "Radio " + radio.getUuid());
threadList.add(t);
t.start();
} catch (IOException ex) {
log.warn("Could not start thread for station url "+radio.getUrl(), ex);
log.warn("Could not start thread for station url "+radio.getUri(), ex);
}
});

Expand Down Expand Up @@ -240,9 +239,9 @@ private static void listMixers() {
}

ListHelper<Mixer.Info> helper = new ListHelper<>(infoList);
helper.addColumn("Name", i -> i.getName());
helper.addColumn("Description", i -> i.getDescription());
helper.addColumn("Vendor", i -> i.getVendor());
helper.addColumn("Name", Mixer.Info::getName);
helper.addColumn("Description", Mixer.Info::getDescription);
helper.addColumn("Vendor", Mixer.Info::getVendor);
helper.print(System.out);
}

Expand All @@ -256,8 +255,8 @@ private static void listStations(List<String> names, Params params) throws IOExc

ListHelper<Radio> helper = new ListHelper<>(radios);
helper.addColumn("UUID", s -> s.getUuid().toString());
helper.addColumn("Name", s -> s.getName());
helper.addColumn("Codec", s -> s.getCodec());
helper.addColumn("Name", Radio::getName);
helper.addColumn("Codec", Radio::getCodec);
helper.addColumn("BR", s -> String.format("%d", s.getBitrate()));
helper.addColumn("Tags", s -> s.getTags().toString());

Expand Down
Loading

0 comments on commit 4f0093e

Please sign in to comment.