/** * @param videoId Video ID. Used as {@link AudioTrackInfo#identifier}. * @param title See {@link AudioTrackInfo#title}. * @param uploader Name of the uploader. Used as {@link AudioTrackInfo#author}. * @param isStream See {@link AudioTrackInfo#isStream}. * @param duration See {@link AudioTrackInfo#length}. * @return An audio track instance. */ public YoutubeAudioTrack buildTrackObject(String videoId, String title, String uploader, boolean isStream, long duration) { return new YoutubeAudioTrack(new AudioTrackInfo(title, uploader, duration, videoId, isStream, getWatchUrl(videoId)), this); }
private AudioTrack extractTrackFromXml(String videoId, Document document) { for (Element element : document.select(":root > thumb")) { String uploader = element.select("user_nickname").first().text(); String title = element.select("title").first().text(); long duration = DataFormatTools.durationTextToMillis(element.select("length").first().text()); return new NicoAudioTrack(new AudioTrackInfo(title, uploader, duration, videoId, false, getWatchUrl(videoId)), this); } return null; }
/** * @return Audio track info instance. */ public AudioTrackInfo build() { long finalLength = DataFormatTools.defaultOnNull(length, Long.MAX_VALUE); return new AudioTrackInfo( title, author, finalLength, identifier, DataFormatTools.defaultOnNull(isStream, finalLength == Long.MAX_VALUE), uri ); }
@Override public TrackStartRequestMessage decode(DataInput in, int version) throws IOException { long executorId = in.readLong(); AudioTrackInfo trackInfo = new AudioTrackInfo(in.readUTF(), in.readUTF(), in.readLong(), in.readUTF(), in.readBoolean(), null); byte[] encodedTrack = new byte[in.readInt()]; in.readFully(encodedTrack); int volume = in.readInt(); AudioConfiguration configuration = new AudioConfiguration(); configuration.setResamplingQuality(AudioConfiguration.ResamplingQuality.valueOf(in.readUTF())); configuration.setOpusEncodingQuality(in.readInt()); if (version >= VERSION_WITH_FORMAT) { AudioDataFormat format = createFormat(in.readInt(), in.readInt(), in.readInt(), in.readUTF()); configuration.setOutputFormat(format); } long position = 0; if (version >= VERSION_WITH_POSITION) { position = in.readLong(); } return new TrackStartRequestMessage(executorId, trackInfo, encodedTrack, volume, configuration, position); }
@Override public DecodedTrackHolder decodeTrack(MessageInput stream) throws IOException { DataInput input = stream.nextMessage(); if (input == null) { return null; } int version = (stream.getMessageFlags() & TRACK_INFO_VERSIONED) != 0 ? (input.readByte() & 0xFF) : 1; AudioTrackInfo trackInfo = new AudioTrackInfo(input.readUTF(), input.readUTF(), input.readLong(), input.readUTF(), input.readBoolean(), version >= 2 ? DataFormatTools.readNullableText(input) : null); AudioTrack track = decodeTrackDetails(trackInfo, input); long position = input.readLong(); if (track != null) { track.setPosition(position); } stream.skipRemainingBytes(); return new DecodedTrackHolder(track); }
@Override public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) { String streamName = getChannelNameFromUrl(reference.identifier); if (streamName == null) { return null; } JsonBrowser channelInfo = fetchStreamChannelInfo(streamName); if (channelInfo == null) { return AudioReference.NO_TRACK; } else { String displayName = channelInfo.get("name").text(); String id = getPlayedStreamId(channelInfo); if (displayName == null || id == null) { throw new IllegalStateException("Expected id and name fields from Beam channel info."); } return new BeamAudioTrack(new AudioTrackInfo( displayName, streamName, Long.MAX_VALUE, id + "|" + streamName + "|" + reference.identifier, true, "https://beam.pro/" + streamName ), this); } }
String status = channelData.get("title").text(); return new TwitchStreamAudioTrack(new AudioTrackInfo( status, displayName,
private AudioTrack extractTrack(JsonBrowser trackInfo, String bandUrl, String artist) { String trackPageUrl = bandUrl + trackInfo.get("title_link").text(); return new BandcampAudioTrack(new AudioTrackInfo( trackInfo.get("title").text(), artist, (long) (trackInfo.get("duration").as(Double.class) * 1000.0), bandUrl + trackInfo.get("title_link").text(), false, trackPageUrl ), this); }
@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 )); }
@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)); }
private AudioTrack loadTrackFromPageContent(String trackUrl, String content) throws IOException { JsonBrowser config = loadConfigJsonFromPageContent(content); if (config == null) { throw new FriendlyException("Track information not found on the page.", SUSPICIOUS, null); } return new VimeoAudioTrack(new AudioTrackInfo( config.get("clip").get("title").text(), config.get("owner").get("display_name").text(), (long) (config.get("clip").get("duration").get("raw").as(Double.class) * 1000.0), trackUrl, false, trackUrl ), this); } }
private AudioTrack buildAudioTrack(JsonBrowser trackInfoJson, String secretToken) { String trackId = trackInfoJson.get("id").text(); AudioTrackInfo trackInfo = new AudioTrackInfo( trackInfoJson.get("title").text(), trackInfoJson.get("user").get("username").text(), trackInfoJson.get("duration").as(Integer.class), secretToken != null ? trackId + "|" + secretToken : trackId, false, trackInfoJson.get("permalink_url").text() ); return new SoundCloudAudioTrack(trackInfo, this); }