com.sedmelluq.discord.lavaplayer.track.info.AudioTrackInfoBuilder Java Examples
The following examples show how to use
com.sedmelluq.discord.lavaplayer.track.info.AudioTrackInfoBuilder.
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: GetyarnAudioSourceManager.java From lavaplayer with Apache License 2.0 | 6 votes |
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 #2
Source File: OggContainerProbe.java From lavaplayer with Apache License 2.0 | 6 votes |
@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 #3
Source File: Mp3ContainerProbe.java From lavaplayer with Apache License 2.0 | 6 votes |
@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 #4
Source File: FlacContainerProbe.java From lavaplayer with Apache License 2.0 | 6 votes |
@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 #5
Source File: SafeHttpAudioSourceManager.java From kyoko with MIT License | 5 votes |
@Override public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) { AudioReference httpReference = getAsHttpReference(reference); if (httpReference == null) { return null; } if (httpReference.containerDescriptor != null) { return createTrack(AudioTrackInfoBuilder.create(reference, null).build(), httpReference.containerDescriptor); } else { return handleLoadResult(detectContainer(httpReference)); } }
Example #6
Source File: HttpAudioSourceManager.java From lavaplayer with Apache License 2.0 | 5 votes |
@Override public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) { AudioReference httpReference = getAsHttpReference(reference); if (httpReference == null) { return null; } if (httpReference.containerDescriptor != null) { return createTrack(AudioTrackInfoBuilder.create(reference, null).build(), httpReference.containerDescriptor); } else { return handleLoadResult(detectContainer(httpReference)); } }
Example #7
Source File: PersistentHttpStream.java From lavaplayer with Apache License 2.0 | 5 votes |
private AudioTrackInfoProvider createIceCastHeaderProvider() { AudioTrackInfoBuilder builder = AudioTrackInfoBuilder.empty() .setTitle(getHeaderValue(currentResponse, "icy-description")) .setAuthor(getHeaderValue(currentResponse, "icy-name")); if (builder.getTitle() == null) { builder.setTitle(getHeaderValue(currentResponse, "icy-url")); } return builder; }
Example #8
Source File: M3uPlaylistContainerProbe.java From lavaplayer with Apache License 2.0 | 5 votes |
@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 #9
Source File: OggContainerProbe.java From lavaplayer with Apache License 2.0 | 5 votes |
private void collectStreamInformation(SeekableInputStream stream, AudioTrackInfoBuilder infoBuilder) throws IOException { OggPacketInputStream packetInputStream = new OggPacketInputStream(stream, false); OggMetadata metadata = OggTrackLoader.loadMetadata(packetInputStream); if (metadata != null) { infoBuilder.apply(metadata); } }
Example #10
Source File: MpegAdtsContainerProbe.java From lavaplayer with Apache License 2.0 | 5 votes |
@Override public MediaContainerDetectionResult probe(AudioReference reference, SeekableInputStream inputStream) throws IOException { SavedHeadSeekableInputStream head = inputStream instanceof SavedHeadSeekableInputStream ? (SavedHeadSeekableInputStream) inputStream : null; if (head != null) { head.setAllowDirectReads(false); } MpegTsElementaryInputStream tsStream = new MpegTsElementaryInputStream(inputStream, ADTS_ELEMENTARY_STREAM); PesPacketInputStream pesStream = new PesPacketInputStream(tsStream); AdtsStreamReader reader = new AdtsStreamReader(pesStream); try { if (reader.findPacketHeader() != null) { log.debug("Track {} is an MPEG-TS stream with an ADTS track.", reference.identifier); return supportedFormat(this, null, AudioTrackInfoBuilder.create(reference, inputStream) .apply(tsStream.getLoadedMetadata()) .build() ); } } catch (IndexOutOfBoundsException ignored) { // TS stream read too far and still did not find required elementary stream - SavedHeadSeekableInputStream throws // this because we disabled reads past the loaded "head". } finally { if (head != null) { head.setAllowDirectReads(true); } } return null; }
Example #11
Source File: AdtsContainerProbe.java From lavaplayer with Apache License 2.0 | 5 votes |
@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 #12
Source File: MpegContainerProbe.java From lavaplayer with Apache License 2.0 | 5 votes |
@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); }