com.sedmelluq.discord.lavaplayer.track.AudioReference Java Examples

The following examples show how to use com.sedmelluq.discord.lavaplayer.track.AudioReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BandcampAudioSourceManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
private AudioItem extractFromPageWithInterface(HttpInterface httpInterface, String url, AudioItemExtractor extractor) throws Exception {
  String responseText;

  try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(url))) {
    int statusCode = response.getStatusLine().getStatusCode();

    if (statusCode == HttpStatus.SC_NOT_FOUND) {
      return new AudioReference(null, null);
    } else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
      throw new IOException("Invalid status code for track page: " + statusCode);
    }

    responseText = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
  }

  return extractor.extract(httpInterface, responseText);
}
 
Example #2
Source File: YoutubeAudioSourceManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
/**
 * Loads a single track from video ID.
 *
 * @param videoId ID of the YouTube video.
 * @param mustExist True if it should throw an exception on missing track, otherwise returns AudioReference.NO_TRACK.
 * @return Loaded YouTube track.
 */
public AudioItem loadTrackWithVideoId(String videoId, boolean mustExist) {
  try (HttpInterface httpInterface = getHttpInterface()) {
    YoutubeTrackDetails details = trackDetailsLoader.loadDetails(httpInterface, videoId);

    if (details == null) {
      if (mustExist) {
        throw new FriendlyException("Video unavailable", COMMON, null);
      } else {
        return AudioReference.NO_TRACK;
      }
    }

    return new YoutubeAudioTrack(details.getTrackInfo(), this);
  } catch (Exception e) {
    throw ExceptionTools.wrapUnfriendlyExceptions("Loading information for a YouTube track failed.", FAULT, e);
  }
}
 
Example #3
Source File: YoutubeAudioSourceManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public AudioItem anonymous(String videoIds) {
  try (HttpInterface httpInterface = getHttpInterface()) {
    try (CloseableHttpResponse response = httpInterface.execute(new HttpGet("https://www.youtube.com/watch_videos?video_ids=" + videoIds))) {
      int statusCode = response.getStatusLine().getStatusCode();
      HttpClientContext context = httpInterface.getContext();
      if (!HttpClientTools.isSuccessWithContent(statusCode)) {
        throw new IOException("Invalid status code for playlist response: " + statusCode);
      }
      // youtube currently transforms watch_video links into a link with a video id and a list id.
      // because thats what happens, we can simply re-process with the redirected link
      List<URI> redirects = context.getRedirectLocations();
      if (redirects != null && !redirects.isEmpty()) {
        return new AudioReference(redirects.get(0).toString(), null);
      } else {
        throw new FriendlyException("Unable to process youtube watch_videos link", SUSPICIOUS,
            new IllegalStateException("Expected youtube to redirect watch_videos link to a watch?v={id}&list={list_id} link, but it did not redirect at all"));
      }
    }
  } catch (Exception e) {
    throw ExceptionTools.wrapUnfriendlyExceptions(e);
  }
}
 
Example #4
Source File: XmpContainerProbe.java    From kyoko with MIT License 6 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
    try (Player p = newPlayer(inputStream, 48000)) {
        log.debug("Loaded module {} via XMP.", reference.identifier);
        inputStream.seek(0);

        return MediaContainerDetectionResult.supportedFormat(this, null, new AudioTrackInfo(
                p.getModule().getName().isEmpty() ? "(No title)" : p.getModule().getName(),
                UNKNOWN_ARTIST,
                Long.MAX_VALUE,
                reference.identifier,
                true,
                reference.identifier
        ));
    } catch (IOException ee) {
        log.debug("XMP error: {}", ee.getMessage());
        return null;
    }
}
 
Example #5
Source File: GetyarnAudioSourceManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
private AudioTrack extractVideoUrlFromPage(AudioReference reference) {
  try (final CloseableHttpResponse response = getHttpInterface().execute(new HttpGet(reference.identifier))) {
    final String html = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
    final Document document = Jsoup.parse(html);

    final AudioTrackInfo trackInfo = AudioTrackInfoBuilder.empty()
        .setUri(reference.identifier)
        .setAuthor("Unknown")
        .setIsStream(false)
        .setIdentifier(document.selectFirst("meta[property=og:video:secure_url]").attr("content"))
        .setTitle(document.selectFirst("meta[property=og:title]").attr("content"))
        .build();

    return createTrack(trackInfo);
  } catch (IOException e) {
    throw new FriendlyException("Failed to load info for yarn clip", SUSPICIOUS, null);
  }
}
 
Example #6
Source File: SoundCloudAudioSourceManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
  AudioItem track = processAsSingleTrack(reference);

  if (track == null) {
    track = playlistLoader.load(reference.identifier, httpInterfaceManager, this::buildTrackFromInfo);
  }

  if (track == null) {
    track = processAsLikedTracks(reference);
  }

  if (track == null && allowSearch) {
    track = processAsSearchQuery(reference);
  }

  return track;
}
 
Example #7
Source File: HttpAudioSourceManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
private MediaContainerDetectionResult detectContainerWithClient(HttpInterface httpInterface, AudioReference reference) throws IOException {
  try (PersistentHttpStream inputStream = new PersistentHttpStream(httpInterface, new URI(reference.identifier), Units.CONTENT_LENGTH_UNKNOWN)) {
    int statusCode = inputStream.checkStatusCode();
    String redirectUrl = HttpClientTools.getRedirectLocation(reference.identifier, inputStream.getCurrentResponse());

    if (redirectUrl != null) {
      return refer(null, new AudioReference(redirectUrl, null));
    } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
      return null;
    } else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
      throw new FriendlyException("That URL is not playable.", COMMON, new IllegalStateException("Status code " + statusCode));
    }

    MediaContainerHints hints = MediaContainerHints.from(getHeaderValue(inputStream.getCurrentResponse(), "Content-Type"), null);
    return new MediaContainerDetection(containerRegistry, reference, inputStream, hints).detectContainer();
  } catch (URISyntaxException e) {
    throw new FriendlyException("Not a valid URL.", COMMON, e);
  }
}
 
Example #8
Source File: M3uPlaylistContainerProbe.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
private MediaContainerDetectionResult loadSingleItemPlaylist(String[] lines) {
  String trackTitle = null;

  for (String line : lines) {
    if (line.startsWith("#EXTINF")) {
      trackTitle = extractTitleFromInfo(line);
    } else if (!line.startsWith("#") && line.length() > 0) {
      if (line.startsWith("http://") || line.startsWith("https://") || line.startsWith("icy://")) {
        return refer(this, new AudioReference(line.trim(), trackTitle));
      }

      trackTitle = null;
    }
  }

  return null;
}
 
Example #9
Source File: PlsPlaylistContainerProbe.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
private MediaContainerDetectionResult loadFromLines(String[] lines) {
  Map<String, String> trackFiles = new HashMap<>();
  Map<String, String> trackTitles = new HashMap<>();

  for (String line : lines) {
    Matcher fileMatcher = filePattern.matcher(line);

    if (fileMatcher.matches()) {
      trackFiles.put(fileMatcher.group(1), fileMatcher.group(2));
      continue;
    }

    Matcher titleMatcher = titlePattern.matcher(line);
    if (titleMatcher.matches()) {
      trackTitles.put(titleMatcher.group(1), titleMatcher.group(2));
    }
  }

  for (Map.Entry<String, String> entry : trackFiles.entrySet()) {
    String title = trackTitles.get(entry.getKey());
    return refer(this, new AudioReference(entry.getValue(), title != null ? title : UNKNOWN_TITLE));
  }

  return unsupportedFormat(this, "The playlist file contains no links.");
}
 
Example #10
Source File: WavContainerProbe.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
  if (!checkNextBytes(inputStream, WAV_RIFF_HEADER)) {
    return null;
  }

  log.debug("Track {} is a WAV file.", reference.identifier);

  WavFileInfo fileInfo = new WavFileLoader(inputStream).parseHeaders();

  return supportedFormat(this, null, new AudioTrackInfo(
      defaultOnNull(reference.title, UNKNOWN_TITLE),
      UNKNOWN_ARTIST,
      fileInfo.getDuration(),
      reference.identifier,
      false,
      reference.identifier
  ));
}
 
Example #11
Source File: OggContainerProbe.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream stream) throws IOException {
  if (!checkNextBytes(stream, OGG_PAGE_HEADER)) {
    return null;
  }

  log.debug("Track {} is an OGG stream.", reference.identifier);

  AudioTrackInfoBuilder infoBuilder = AudioTrackInfoBuilder.create(reference, stream).setIsStream(true);

  try {
    collectStreamInformation(stream, infoBuilder);
  } catch (Exception e) {
    log.warn("Failed to collect additional information on OGG stream.", e);
  }

  return supportedFormat(this, null, infoBuilder.build());
}
 
Example #12
Source File: AudioTrackInfoBuilder.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an instance of an audio track builder based on an audio reference and a stream.
 *
 * @param reference Audio reference to use as the starting point for the builder.
 * @param stream Stream to get additional data from.
 * @return An instance of the builder with the reference and track info providers from the stream preapplied.
 */
public static AudioTrackInfoBuilder create(AudioReference reference, SeekableInputStream stream) {
  AudioTrackInfoBuilder builder = new AudioTrackInfoBuilder()
      .setAuthor(UNKNOWN_ARTIST)
      .setTitle(UNKNOWN_TITLE)
      .setLength(DURATION_MS_UNKNOWN);

  builder.apply(reference);

  if (stream != null) {
    for (AudioTrackInfoProvider provider : stream.getTrackInfoProviders()) {
      builder.apply(provider);
    }
  }

  return builder;
}
 
Example #13
Source File: XmContainerProbe.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
  Module module;
  try {
    module = new Module(inputStream);
  } catch (IllegalArgumentException e) {
    return null;
  }

  log.debug("Track {} is a module.", reference.identifier);

  inputStream.seek(0);

  return supportedFormat(this, null, new AudioTrackInfo(
      module.songName,
      UNKNOWN_ARTIST,
      Units.DURATION_MS_UNKNOWN,
      reference.identifier,
      true,
      reference.identifier
  ));
}
 
Example #14
Source File: TwitchStreamAudioSourceManager.java    From kyoko with MIT License 6 votes vote down vote up
@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
    String streamName = getChannelIdentifierFromUrl(reference.identifier);
    if (streamName == null) {
        return null;
    }

    JsonBrowser channelInfo = fetchChannelInfo(streamName);

    if (channelInfo == null) {
        return AudioReference.NO_TRACK;
    } else {
        final String displayName = channelInfo.get("display_name").text();
        final String status = channelInfo.get("status").text();

        return new TwitchStreamAudioTrack(new AudioTrackInfo(
                status,
                displayName,
                Long.MAX_VALUE,
                reference.identifier,
                true,
                reference.identifier
        ), this);
    }
}
 
Example #15
Source File: DefaultAudioPlayerManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
private Callable<Void> createItemLoader(final String identifier, final AudioLoadResultHandler resultHandler) {
  return () -> {
    boolean[] reported = new boolean[1];

    try {
      if (!checkSourcesForItem(new AudioReference(identifier, null), resultHandler, reported)) {
        log.debug("No matches for track with identifier {}.", identifier);
        resultHandler.noMatches();
      }
    } catch (Throwable throwable) {
      if (reported[0]) {
        log.warn("Load result handler for {} threw an exception", identifier, throwable);
      } else {
        dispatchItemLoadFailure(identifier, resultHandler, throwable);
      }

      ExceptionTools.rethrowErrors(throwable);
    }

    return null;
  };
}
 
Example #16
Source File: Mp3ContainerProbe.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
  if (!checkNextBytes(inputStream, ID3_TAG)) {
    byte[] frameHeader = new byte[4];
    Mp3FrameReader frameReader = new Mp3FrameReader(inputStream, frameHeader);
    if (!frameReader.scanForFrame(STREAM_SCAN_DISTANCE, false)) {
      return null;
    }

    inputStream.seek(0);
  }

  log.debug("Track {} is an MP3 file.", reference.identifier);

  Mp3TrackProvider file = new Mp3TrackProvider(null, inputStream);

  try {
    file.parseHeaders();

    return supportedFormat(this, null, AudioTrackInfoBuilder.create(reference, inputStream)
        .apply(file).setIsStream(!file.isSeekable()).build());
  } finally {
    file.close();
  }
}
 
Example #17
Source File: FlacContainerProbe.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
  if (!checkNextBytes(inputStream, FlacFileLoader.FLAC_CC)) {
    return null;
  }

  log.debug("Track {} is a FLAC file.", reference.identifier);

  FlacTrackInfo fileInfo = new FlacFileLoader(inputStream).parseHeaders();

  AudioTrackInfo trackInfo = AudioTrackInfoBuilder.create(reference, inputStream)
      .setTitle(fileInfo.tags.get(TITLE_TAG))
      .setAuthor(fileInfo.tags.get(ARTIST_TAG))
      .setLength(fileInfo.duration)
      .build();

  return supportedFormat(this, null, trackInfo);
}
 
Example #18
Source File: MatroskaContainerProbe.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
  if (!checkNextBytes(inputStream, EBML_TAG)) {
    return null;
  }

  log.debug("Track {} is a matroska file.", reference.identifier);

  MatroskaStreamingFile file = new MatroskaStreamingFile(inputStream);
  file.readFile();

  if (!hasSupportedAudioTrack(file)) {
    return unsupportedFormat(this, "No supported audio tracks present in the file.");
  }

  return supportedFormat(this, null, new AudioTrackInfo(UNKNOWN_TITLE, UNKNOWN_ARTIST,
      (long) file.getDuration(), reference.identifier, false, reference.identifier));
}
 
Example #19
Source File: UserContextAudioPlayerManager.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
private Callable<Void> createItemLoader(final String identifier, final AudioLoadResultHandler resultHandler, boolean isPatron) {
    return () -> {
        final boolean[] reported = new boolean[1];

        try {
            if (!checkSourcesForItem(new AudioReference(identifier, null), resultHandler, reported, isPatron)) {
                log.debug("No matches for track with identifier {}.", identifier);
                resultHandler.noMatches();
            }
        } catch (Throwable throwable) {
            if (reported[0]) {
                log.warn("Load result handler for {} threw an exception", identifier, throwable);
            } else {
                dispatchItemLoadFailure(identifier, resultHandler, throwable);
            }

            ExceptionTools.rethrowErrors(throwable);
        }

        return null;
    };
}
 
Example #20
Source File: DefaultAudioPlayerManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
private AudioItem checkSourcesForItemOnce(AudioReference reference, AudioLoadResultHandler resultHandler, boolean[] reported) {
  for (AudioSourceManager sourceManager : sourceManagers) {
    if (reference.containerDescriptor != null && !(sourceManager instanceof ProbingAudioSourceManager)) {
      continue;
    }

    AudioItem item = sourceManager.loadItem(this, reference);

    if (item != null) {
      if (item instanceof AudioTrack) {
        log.debug("Loaded a track with identifier {} using {}.", reference.identifier, sourceManager.getClass().getSimpleName());
        reported[0] = true;
        resultHandler.trackLoaded((AudioTrack) item);
      } else if (item instanceof AudioPlaylist) {
        log.debug("Loaded a playlist with identifier {} using {}.", reference.identifier, sourceManager.getClass().getSimpleName());
        reported[0] = true;
        resultHandler.playlistLoaded((AudioPlaylist) item);
      }
      return item;
    }
  }

  return null;
}
 
Example #21
Source File: SafeHttpAudioSourceManager.java    From kyoko with MIT License 6 votes vote down vote up
private MediaContainerDetectionResult detectContainerWithClient(HttpInterface httpInterface, AudioReference reference) throws IOException {
    try (PersistentHttpStream inputStream = new PersistentHttpStream(httpInterface, new URI(reference.identifier), Long.MAX_VALUE)) {
        if (!trustedDomains.contains(new URI(reference.identifier).getHost().toLowerCase())) return null;

        int statusCode = inputStream.checkStatusCode();
        String redirectUrl = HttpClientTools.getRedirectLocation(reference.identifier, inputStream.getCurrentResponse());

        if (redirectUrl != null) {
            return refer(null, new AudioReference(redirectUrl, null));
        } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        } else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
            throw new FriendlyException("That URL is not playable.", COMMON, new IllegalStateException("Status code " + statusCode));
        }

        MediaContainerHints hints = MediaContainerHints.from(getHeaderValue(inputStream.getCurrentResponse(), "Content-Type"), null);
        return new MediaContainerDetection(registry, reference, inputStream, hints).detectContainer();
    } catch (URISyntaxException e) {
        throw new FriendlyException("Not a valid URL.", COMMON, e);
    }
}
 
Example #22
Source File: M3uPlaylistContainerProbe.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
  if (!checkNextBytes(inputStream, M3U_HEADER_TAG) && !checkNextBytes(inputStream, M3U_ENTRY_TAG)) {
    return null;
  }

  log.debug("Track {} is an M3U playlist file.", reference.identifier);
  String[] lines = DataFormatTools.streamToLines(inputStream, StandardCharsets.UTF_8);

  String hlsStreamUrl = HlsStreamSegmentUrlProvider.findHlsEntryUrl(lines);

  if (hlsStreamUrl != null) {
    AudioTrackInfoBuilder infoBuilder = AudioTrackInfoBuilder.create(reference, inputStream);
    AudioReference httpReference = HttpAudioSourceManager.getAsHttpReference(reference);

    if (httpReference != null) {
      return supportedFormat(this, TYPE_HLS_OUTER, infoBuilder.setIdentifier(httpReference.identifier).build());
    } else {
      return refer(this, new AudioReference(hlsStreamUrl, infoBuilder.getTitle(),
          new MediaContainerDescriptor(this, TYPE_HLS_INNER)));
    }
  }

  MediaContainerDetectionResult result = loadSingleItemPlaylist(lines);
  if (result != null) {
    return result;
  }

  return unsupportedFormat(this, "The playlist file contains no links.");
}
 
Example #23
Source File: YoutubeSearchProvider.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private AudioItem extractSearchResults(Document document, String query,
                                       Function<AudioTrackInfo, AudioTrack> trackFactory) {

  List<AudioTrack> tracks = new ArrayList<>();
  Elements resultsSelection = document.select("#page > #content #results");
  if (!resultsSelection.isEmpty()) {
    for (Element results : resultsSelection) {
      for (Element result : results.select(".yt-lockup-video")) {
        if (!result.hasAttr("data-ad-impressions") && result.select(".standalone-ypc-badge-renderer-label").isEmpty()) {
          extractTrackFromResultEntry(tracks, result, trackFactory);
        }
      }
    }
  } else {
    log.debug("Attempting to parse results page as polymer");
    try {
      tracks = polymerExtractTracks(document, trackFactory);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  if (tracks.isEmpty()) {
    return AudioReference.NO_TRACK;
  } else {
    return new BasicAudioPlaylist("Search results for: " + query, tracks, null, true);
  }
}
 
Example #24
Source File: GetyarnAudioSourceManager.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
  final Matcher m = GETYARN_REGEX.matcher(reference.identifier);

  if (!m.matches()) {
    return null;
  }

  return extractVideoUrlFromPage(reference);
}
 
Example #25
Source File: MpegContainerProbe.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
  if (!checkNextBytes(inputStream, ISO_TAG)) {
    return null;
  }

  log.debug("Track {} is an MP4 file.", reference.identifier);

  MpegFileLoader file = new MpegFileLoader(inputStream);
  file.parseHeaders();

  MpegTrackInfo audioTrack = getSupportedAudioTrack(file);

  if (audioTrack == null) {
    return unsupportedFormat(this, "No supported audio format in the MP4 file.");
  }

  MpegTrackConsumer trackConsumer = new MpegNoopTrackConsumer(audioTrack);
  MpegFileTrackProvider fileReader = file.loadReader(trackConsumer);

  if (fileReader == null) {
    return unsupportedFormat(this, "MP4 file uses an unsupported format.");
  }

  AudioTrackInfo trackInfo = AudioTrackInfoBuilder.create(reference, inputStream)
      .setTitle(file.getTextMetadata("Title"))
      .setAuthor(file.getTextMetadata("Artist"))
      .setLength(fileReader.getDuration())
      .build();

  return supportedFormat(this, null, trackInfo);
}
 
Example #26
Source File: PlainPlaylistContainerProbe.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
  if (!matchNextBytesAsRegex(inputStream, STREAM_SCAN_DISTANCE, linkPattern, StandardCharsets.UTF_8)) {
    return null;
  }

  log.debug("Track {} is a plain playlist file.", reference.identifier);
  return loadFromLines(DataFormatTools.streamToLines(inputStream, StandardCharsets.UTF_8));
}
 
Example #27
Source File: AdtsContainerProbe.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
  AdtsStreamReader reader = new AdtsStreamReader(inputStream);

  if (reader.findPacketHeader(MediaContainerDetection.STREAM_SCAN_DISTANCE) == null) {
    return null;
  }

  log.debug("Track {} is an ADTS stream.", reference.identifier);

  return supportedFormat(this, null, AudioTrackInfoBuilder.create(reference, inputStream).build());
}
 
Example #28
Source File: PlainPlaylistContainerProbe.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private MediaContainerDetectionResult loadFromLines(String[] lines) {
  for (String line : lines) {
    Matcher matcher = linkPattern.matcher(line);

    if (matcher.matches()) {
      return refer(this, new AudioReference(matcher.group(0), null));
    }
  }

  return unsupportedFormat(this, "The playlist file contains no links.");
}
 
Example #29
Source File: PlsPlaylistContainerProbe.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException {
  if (!checkNextBytes(inputStream, PLS_HEADER)) {
    return null;
  }

  log.debug("Track {} is a PLS playlist file.", reference.identifier);
  return loadFromLines(DataFormatTools.streamToLines(inputStream, StandardCharsets.UTF_8));
}
 
Example #30
Source File: MediaContainerDetection.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * @param reference Reference to the track with an identifier, used in the AudioTrackInfo in result
 * @param inputStream Input stream of the file
 * @param hints Hints about the format (mime type, extension)
 */
public MediaContainerDetection(MediaContainerRegistry containerRegistry, AudioReference reference,
                               SeekableInputStream inputStream, MediaContainerHints hints) {

  this.containerRegistry = containerRegistry;
  this.reference = reference;
  this.inputStream = inputStream;
  this.hints = hints;
}