Skip to content

Commit

Permalink
Don't use 'User-Suppplied+URL' in the directory names. #8
Browse files Browse the repository at this point in the history
  • Loading branch information
sfuhrm committed Jan 1, 2024
1 parent 5b70bb1 commit a2f3b0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/main/java/de/sfuhrm/radiorecorder/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ private static RadioBrowser newRadioBrowser(Params params) throws IOException {
return browser;
}

public static final String NO_RADIO_NAME = "";

/** Read the URLs or names given and resolve them using {@link RadioBrowser}.
* @param urls the input urls from the command line.
* @param params the command line.
Expand All @@ -90,7 +92,7 @@ private static List<Radio> sanitize(List<String> urls, Params params) throws IOE
String scheme = uri.getScheme();
if (scheme != null) {
Radio s = new Radio();
s.setName("User-Suppplied URL");
s.setName(NO_RADIO_NAME);
s.setUri(uri);
result.add(s);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,21 @@ public StreamCopyConsumer(ConsumerContext consumerContext) {

private File createDirectory(ConsumerContext context) {
File parent = context.getTargetDirectory();
String hostAndPath;
try {
hostAndPath = URLEncoder.encode(context.getRadio().getName(), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
File result;
String radioName = context.getRadio().getName();
if (! radioName.isEmpty()) {
String hostAndPath;
try {
hostAndPath = URLEncoder.encode(context.getRadio().getName(), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
result= new File(parent, hostAndPath);
} else {
result = parent;
}
File dir = new File(parent, hostAndPath);
dir.mkdirs();
return dir;
result.mkdirs();
return result;
}

/**
Expand Down

0 comments on commit a2f3b0e

Please sign in to comment.