Skip to content

Commit

Permalink
Merge pull request #360 from kagemomiji/issue271-fix-stream-api-offset
Browse files Browse the repository at this point in the history
#271 Force ignoring icecast request from Tempo client
  • Loading branch information
kagemomiji authored Feb 5, 2024
2 parents fded47f + 270a871 commit 3c0d5e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
You should have received a copy of the GNU General Public License
along with Airsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2023 (C) Y.Tory
Copyright 2023-2024 (C) Y.Tory
Copyright 2016 (C) Airsonic Authors
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
*/
package org.airsonic.player.controller;

import com.google.common.io.ByteStreams;
import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
import org.airsonic.player.domain.*;
Expand All @@ -47,6 +46,7 @@
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -62,6 +62,7 @@
import java.io.InputStream;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
Expand All @@ -79,6 +80,8 @@ public class StreamController {

private static final Logger LOG = LoggerFactory.getLogger(StreamController.class);

private static final Set<String> ICY_IGNORED_CLIENT = Set.of("Tempo");

@Autowired
private StatusService statusService;
@Autowired
Expand Down Expand Up @@ -228,7 +231,8 @@ public ResponseEntity<Resource> handleRequest(Authentication authentication,
BiConsumer<InputStream, TransferStatus> streamInit = (i, s) -> {};

// Enabled SHOUTcast, if requested.
if ("1".equals(swr.getHeader("icy-metadata"))) {
String clientId = Optional.ofNullable(swr.getParameter("c")).orElse("");
if (!ICY_IGNORED_CLIENT.contains(clientId) && "1".equals(swr.getHeader("icy-metadata"))) {
expectedSize = null;
ShoutcastDetails shoutcastDetails = getShoutcastDetails(playStream);
playStream = shoutcastDetails.getStream();
Expand Down Expand Up @@ -303,9 +307,7 @@ private ShoutcastDetails getShoutcastDetails(InputStream input) throws IOExcepti
.map(TransferStatus::getMediaFile)
.map(MediaFile::getTitle)
.orElseGet(settingsService::getWelcomeTitle))) {
// IOUtils.copy(playStream, shout);
ByteStreams.copy(in, shout);
// StreamUtils.copy(playStream, shout);
StreamUtils.copy(in, shout);
} catch (Exception e) {
LOG.debug("Error with output to Shoutcast stream", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License
along with Airsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2024 (C) Y.Tory
Copyright 2016 (C) Airsonic Authors
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
*/
Expand Down Expand Up @@ -1393,7 +1394,7 @@ public ResponseEntity<Resource> stream(Authentication authentication,
@RequestParam Optional<Integer> maxBitRate,
@RequestParam Optional<Integer> id,
@RequestParam Optional<String> path,
@RequestParam(required = false) Double offsetSeconds,
@RequestParam(required = false) Double timeOffset,
ServletWebRequest swr) throws Exception {
HttpServletRequest request = wrapRequest(swr.getRequest());
User user = securityService.getUserByName(authentication.getName());
Expand All @@ -1402,7 +1403,7 @@ public ResponseEntity<Resource> stream(Authentication authentication,
}

return streamController.handleRequest(authentication, playlist, format, suffix, maxBitRate, id, path,
offsetSeconds, new ServletWebRequest(request, swr.getResponse()));
timeOffset, new ServletWebRequest(request, swr.getResponse()));
}

@RequestMapping("/hls")
Expand Down

0 comments on commit 3c0d5e2

Please sign in to comment.