Merge remote-tracking branch 'origin/pr/1327'

master
Andrew DeMaria 5 years ago
commit 75a280457e
No known key found for this signature in database
GPG Key ID: 0A3F5E91F8364EDF
  1. 14
      airsonic-main/src/main/java/org/airsonic/player/controller/HLSController.java
  2. 8
      airsonic-main/src/main/java/org/airsonic/player/service/PlaylistService.java
  3. 4
      airsonic-main/src/main/java/org/airsonic/player/service/playlist/DefaultPlaylistImportHandler.java
  4. 2
      airsonic-main/src/main/java/org/airsonic/player/service/playlist/PlaylistImportHandler.java
  5. 4
      airsonic-main/src/main/java/org/airsonic/player/service/playlist/XspfPlaylistImportHandler.java
  6. 36
      airsonic-main/src/main/java/org/airsonic/player/service/sonos/SonosServiceRegistration.java
  7. 69
      airsonic-main/src/main/java/org/airsonic/player/util/Pair.java
  8. 12
      airsonic-main/src/test/java/org/airsonic/player/controller/HLSControllerTestCase.java

@ -25,9 +25,9 @@ import org.airsonic.player.service.JWTSecurityService;
import org.airsonic.player.service.MediaFileService;
import org.airsonic.player.service.PlayerService;
import org.airsonic.player.service.SecurityService;
import org.airsonic.player.util.Pair;
import org.airsonic.player.util.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
@ -128,11 +128,11 @@ public class HLSController {
}
int kbps = Integer.parseInt(matcher.group(1));
if (matcher.group(3) == null) {
return new Pair<Integer, Dimension>(kbps, null);
return Pair.of(kbps, null);
} else {
int width = Integer.parseInt(matcher.group(3));
int height = Integer.parseInt(matcher.group(4));
return new Pair<Integer, Dimension>(kbps, new Dimension(width, height));
return Pair.of(kbps, new Dimension(width, height));
}
}
@ -143,7 +143,7 @@ public class HLSController {
String contextPath = getContextPath(request);
for (Pair<Integer, Dimension> bitRate : bitRates) {
Integer kbps = bitRate.getFirst();
Integer kbps = bitRate.getLeft();
writer.println("#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=" + kbps * 1000L);
UriComponentsBuilder url = (UriComponentsBuilder.fromUriString(contextPath + "ext/hls/hls.m3u8")
.queryParam("id", id)
@ -151,7 +151,7 @@ public class HLSController {
.queryParam("bitRate", kbps));
jwtSecurityService.addJWTToken(url);
writer.print(url.toUriString());
Dimension dimension = bitRate.getSecond();
Dimension dimension = bitRate.getRight();
if (dimension != null) {
writer.print("@" + dimension.width + "x" + dimension.height);
}
@ -188,8 +188,8 @@ public class HLSController {
builder.queryParam("player", player.getId());
builder.queryParam("duration", duration);
if (bitRate != null) {
builder.queryParam("maxBitRate", bitRate.getFirst());
Dimension dimension = bitRate.getSecond();
builder.queryParam("maxBitRate", bitRate.getLeft());
Dimension dimension = bitRate.getRight();
if (dimension != null) {
builder.queryParam("size", dimension.width);
builder.queryParam("x", dimension.height);

@ -31,9 +31,9 @@ import org.airsonic.player.domain.User;
import org.airsonic.player.service.playlist.PlaylistExportHandler;
import org.airsonic.player.service.playlist.PlaylistImportHandler;
import org.airsonic.player.util.FileUtil;
import org.airsonic.player.util.Pair;
import org.airsonic.player.util.StringUtil;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -192,11 +192,11 @@ public class PlaylistService {
Pair<List<MediaFile>, List<String>> result = importHandler.handle(inputSpecificPlaylist);
if (result.getFirst().isEmpty() && !result.getSecond().isEmpty()) {
if (result.getLeft().isEmpty() && !result.getRight().isEmpty()) {
throw new Exception("No songs in the playlist were found.");
}
for (String error : result.getSecond()) {
for (String error : result.getRight()) {
LOG.warn("File in playlist '" + fileName + "' not found: " + error);
}
Date now = new Date();
@ -215,7 +215,7 @@ public class PlaylistService {
playlist = existingPlaylist;
}
setFilesInPlaylist(playlist.getId(), result.getFirst());
setFilesInPlaylist(playlist.getId(), result.getLeft());
return playlist;
}

@ -3,7 +3,7 @@ package org.airsonic.player.service.playlist;
import chameleon.playlist.*;
import org.airsonic.player.domain.MediaFile;
import org.airsonic.player.service.MediaFileService;
import org.airsonic.player.util.Pair;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
@ -87,7 +87,7 @@ public class DefaultPlaylistImportHandler implements PlaylistImportHandler {
errors.add(e.getMessage());
}
return Pair.create(mediaFiles, errors);
return Pair.of(mediaFiles, errors);
}
@Override

@ -2,7 +2,7 @@ package org.airsonic.player.service.playlist;
import chameleon.playlist.SpecificPlaylist;
import org.airsonic.player.domain.MediaFile;
import org.airsonic.player.util.Pair;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.core.Ordered;
import java.util.List;

@ -6,7 +6,7 @@ import chameleon.playlist.xspf.Playlist;
import chameleon.playlist.xspf.StringContainer;
import org.airsonic.player.domain.MediaFile;
import org.airsonic.player.service.MediaFileService;
import org.airsonic.player.util.Pair;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -60,7 +60,7 @@ public class XspfPlaylistImportHandler implements PlaylistImportHandler {
errors.add(errorMsg);
}
});
return Pair.create(mediaFiles, errors);
return Pair.of(mediaFiles, errors);
}
@Override

@ -19,8 +19,8 @@
package org.airsonic.player.service.sonos;
import org.airsonic.player.util.Pair;
import org.airsonic.player.util.StringUtil;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.NameValuePair;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.config.RequestConfig;
@ -54,23 +54,23 @@ public class SonosServiceRegistration {
", SID " + sonosServiceId + ", and Airsonic URL " + localUrl);
List<Pair<String, String>> params = new ArrayList<Pair<String, String>>();
params.add(Pair.create("sid", String.valueOf(sonosServiceId)));
params.add(Pair.of("sid", String.valueOf(sonosServiceId)));
if (enabled) {
params.add(Pair.create("name", sonosServiceName));
params.add(Pair.create("uri", localUrl));
params.add(Pair.create("secureUri", localUrl));
params.add(Pair.create("pollInterval", "1200"));
params.add(Pair.create("authType", "UserId"));
params.add(Pair.create("containerType", "MService"));
params.add(Pair.create("caps", "search"));
params.add(Pair.create("caps", "trFavorites"));
params.add(Pair.create("caps", "alFavorites"));
params.add(Pair.create("caps", "ucPlaylists"));
params.add(Pair.create("caps", "extendedMD"));
params.add(Pair.create("presentationMapVersion", "1"));
params.add(Pair.create("presentationMapUri", airsonicBaseUrl + "sonos/presentationMap.xml"));
params.add(Pair.create("stringsVersion", "5"));
params.add(Pair.create("stringsUri", airsonicBaseUrl + "sonos/strings.xml"));
params.add(Pair.of("name", sonosServiceName));
params.add(Pair.of("uri", localUrl));
params.add(Pair.of("secureUri", localUrl));
params.add(Pair.of("pollInterval", "1200"));
params.add(Pair.of("authType", "UserId"));
params.add(Pair.of("containerType", "MService"));
params.add(Pair.of("caps", "search"));
params.add(Pair.of("caps", "trFavorites"));
params.add(Pair.of("caps", "alFavorites"));
params.add(Pair.of("caps", "ucPlaylists"));
params.add(Pair.of("caps", "extendedMD"));
params.add(Pair.of("presentationMapVersion", "1"));
params.add(Pair.of("presentationMapUri", airsonicBaseUrl + "sonos/presentationMap.xml"));
params.add(Pair.of("stringsVersion", "5"));
params.add(Pair.of("stringsUri", airsonicBaseUrl + "sonos/strings.xml"));
}
String result = execute(controllerUrl, params);
@ -80,7 +80,7 @@ public class SonosServiceRegistration {
private String execute(String url, List<Pair<String, String>> parameters) throws IOException {
List<NameValuePair> params = new ArrayList<NameValuePair>();
for (Pair<String, String> parameter : parameters) {
params.add(new BasicNameValuePair(parameter.getFirst(), parameter.getSecond()));
params.add(new BasicNameValuePair(parameter.getLeft(), parameter.getRight()));
}
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(20 * 1000) // 20 seconds

@ -1,69 +0,0 @@
/*
This file is part of Airsonic.
Airsonic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Airsonic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Airsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2016 (C) Airsonic Authors
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
*/
package org.airsonic.player.util;
import org.apache.commons.lang.ObjectUtils;
import java.io.Serializable;
/**
* @author Sindre Mehus
*/
public class Pair<S, T> implements Serializable {
private final S first;
private final T second;
public static <S, T> Pair<S, T> create(S first, T second) {
return new Pair<S, T>(first, second);
}
public Pair(S first, T second) {
this.first = first;
this.second = second;
}
public S getFirst() {
return first;
}
public T getSecond() {
return second;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Pair pair = (Pair) o;
return ObjectUtils.equals(first, pair.first) && ObjectUtils.equals(second, pair.second);
}
@Override
public int hashCode() {
return ObjectUtils.hashCode(first) * ObjectUtils.hashCode(second);
}
}

@ -20,7 +20,7 @@
package org.airsonic.player.controller;
import junit.framework.TestCase;
import org.airsonic.player.util.Pair;
import org.apache.commons.lang3.tuple.Pair;
import java.awt.*;
@ -34,13 +34,13 @@ public class HLSControllerTestCase extends TestCase {
HLSController controller = new HLSController();
Pair<Integer,Dimension> pair = controller.parseBitRate("1000");
assertEquals(1000, pair.getFirst().intValue());
assertNull(pair.getSecond());
assertEquals(1000, pair.getLeft().intValue());
assertNull(pair.getRight());
pair = controller.parseBitRate("1000@400x300");
assertEquals(1000, pair.getFirst().intValue());
assertEquals(400, pair.getSecond().width);
assertEquals(300, pair.getSecond().height);
assertEquals(1000, pair.getLeft().intValue());
assertEquals(400, pair.getRight().width);
assertEquals(300, pair.getRight().height);
try {
controller.parseBitRate("asdfl");

Loading…
Cancel
Save