正在查看: Kreate v1.5.0 应用的 SoundcloudStreamExtractor.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Kreate v1.5.0 应用的 SoundcloudStreamExtractor.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;
import j$.util.Collection;
import j$.util.function.Consumer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampCommentsExtractor$$ExternalSyntheticLambda0;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampCommentsExtractor$$ExternalSyntheticLambda1;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.DeliveryMethod;
import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.Stream;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.extractor.utils.Utils;
public class SoundcloudStreamExtractor extends StreamExtractor {
private boolean isAvailable;
private JsonObject track;
public SoundcloudStreamExtractor(StreamingService streamingService, LinkHandler linkHandler) {
super(streamingService, linkHandler);
this.isAvailable = true;
}
@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
JsonObject resolveFor = SoundcloudParsingHelper.resolveFor(downloader, getUrl());
this.track = resolveFor;
String string = resolveFor.getString("policy", "");
if (string.equals("ALLOW") || string.equals("MONETIZE")) {
return;
}
this.isAvailable = false;
if (string.equals("SNIP")) {
throw new SoundCloudGoPlusContentException();
}
if (string.equals("BLOCK")) {
throw new GeographicRestrictionException("This track is not available in user's country");
}
throw new ContentNotAvailableException("Content not available: policy " + string);
}
@Override
@Nonnull
public String getId() {
return String.valueOf(this.track.getInt("id"));
}
@Override
@Nonnull
public String getName() {
return this.track.getString("title");
}
@Override
@Nonnull
public String getTextualUploadDate() {
return this.track.getString("created_at").replace("T", Stream.ID_UNKNOWN).replace("Z", "");
}
@Override
@Nonnull
public DateWrapper getUploadDate() throws ParsingException {
return new DateWrapper(SoundcloudParsingHelper.parseDateFrom(this.track.getString("created_at")));
}
@Override
@Nonnull
public List<Image> getThumbnails() throws ParsingException {
return SoundcloudParsingHelper.getAllImagesFromTrackObject(this.track);
}
@Override
@Nonnull
public Description getDescription() {
return new Description(this.track.getString("description"), 3);
}
@Override
public long getLength() {
return this.track.getLong("duration") / 1000;
}
@Override
public long getTimeStamp() throws ParsingException {
return getTimestampSeconds("(#t=\\d{0,3}h?\\d{0,3}m?\\d{1,3}s?)");
}
@Override
public long getViewCount() {
return this.track.getLong("playback_count");
}
@Override
public long getLikeCount() {
return this.track.getLong("likes_count", -1L);
}
@Override
@Nonnull
public String getUploaderUrl() {
return SoundcloudParsingHelper.getUploaderUrl(this.track);
}
@Override
@Nonnull
public String getUploaderName() {
return SoundcloudParsingHelper.getUploaderName(this.track);
}
@Override
public boolean isUploaderVerified() throws ParsingException {
return this.track.getObject("user").getBoolean("verified");
}
@Override
@Nonnull
public List<Image> getUploaderAvatars() {
return SoundcloudParsingHelper.getAllImagesFromArtworkOrAvatarUrl(SoundcloudParsingHelper.getAvatarUrl(this.track));
}
@Override
public List<AudioStream> getAudioStreams() throws ExtractionException {
ArrayList arrayList = new ArrayList();
if (this.track.getBoolean("streamable") && this.isAvailable) {
try {
JsonArray array = this.track.getObject("media").getArray("transcodings");
if (!Utils.isNullOrEmpty((Collection<?>) array)) {
extractAudioStreams(array, arrayList);
return arrayList;
}
} catch (NullPointerException e) {
throw new ExtractionException("Could not get audio streams", e);
}
}
return arrayList;
}
@Nonnull
private String getTranscodingUrl(String str) throws IOException, ExtractionException {
String str2 = str + "?client_id=" + SoundcloudParsingHelper.clientId();
String string = this.track.getString("track_authorization");
if (!Utils.isNullOrEmpty(string)) {
str2 = str2 + "&track_authorization=" + string;
}
try {
return ((JsonObject) JsonParser.object().from(NewPipe.getDownloader().get(str2).responseBody())).getString("url");
} catch (JsonParserException e) {
throw new ParsingException("Could not parse streamable URL", e);
}
}
private void extractAudioStreams(@Nonnull JsonArray jsonArray, final List<AudioStream> list) {
Collection.-EL.stream(jsonArray).filter(new BandcampCommentsExtractor$$ExternalSyntheticLambda0(JsonObject.class)).map(new BandcampCommentsExtractor$$ExternalSyntheticLambda1(JsonObject.class)).forEachOrdered(new Consumer() {
@Override
public final void accept(Object obj) {
SoundcloudStreamExtractor.this.m843x25be573d(list, (JsonObject) obj);
}
@Override
public Consumer andThen(Consumer consumer) {
return Consumer.-CC.$default$andThen(this, consumer);
}
});
}
void m843x25be573d(List list, JsonObject jsonObject) {
String string = jsonObject.getString("url");
if (Utils.isNullOrEmpty(string)) {
return;
}
try {
String string2 = jsonObject.getString("preset", Stream.ID_UNKNOWN);
String string3 = jsonObject.getObject("format").getString("protocol");
if (string3.contains("encrypted")) {
return;
}
AudioStream.Builder id = new AudioStream.Builder().setId(string2);
if (string3.equals("hls")) {
id.setDeliveryMethod(DeliveryMethod.HLS);
}
id.setContent(getTranscodingUrl(string), true);
if (string2.contains("mp3")) {
id.setMediaFormat(MediaFormat.MP3);
id.setAverageBitrate(128);
} else {
if (!string2.contains("opus")) {
return;
}
id.setMediaFormat(MediaFormat.OPUS);
id.setAverageBitrate(64);
id.setDeliveryMethod(DeliveryMethod.HLS);
}
AudioStream build = id.build();
if (Stream.containSimilarStream(build, list)) {
return;
}
list.add(build);
} catch (IOException | ExtractionException unused) {
}
}
@Override
public List<VideoStream> getVideoStreams() {
return Collections.EMPTY_LIST;
}
@Override
public List<VideoStream> getVideoOnlyStreams() {
return Collections.EMPTY_LIST;
}
@Override
public StreamType getStreamType() {
return StreamType.AUDIO_STREAM;
}
@Override
@Nullable
public StreamInfoItemsCollector getRelatedItems() throws IOException, ExtractionException {
StreamInfoItemsCollector streamInfoItemsCollector = new StreamInfoItemsCollector(getServiceId());
SoundcloudParsingHelper.getStreamsFromApi(streamInfoItemsCollector, "https://api-v2.soundcloud.com/tracks/" + Utils.encodeUrlUtf8(getId()) + "/related?client_id=" + Utils.encodeUrlUtf8(SoundcloudParsingHelper.clientId()));
return streamInfoItemsCollector;
}
@Override
public StreamExtractor.Privacy getPrivacy() {
return this.track.getString("sharing").equals("public") ? StreamExtractor.Privacy.PUBLIC : StreamExtractor.Privacy.PRIVATE;
}
@Override
@Nonnull
public String getCategory() {
return this.track.getString("genre");
}
@Override
@Nonnull
public String getLicence() {
return this.track.getString("license");
}
@Override
@Nonnull
public List<String> getTags() {
String[] split = this.track.getString("tag_list").split(Stream.ID_UNKNOWN);
ArrayList arrayList = new ArrayList();
StringBuilder sb = new StringBuilder();
boolean z = false;
for (String str : split) {
if (str.startsWith("\"")) {
sb.append(str.replace("\"", ""));
z = true;
} else if (z) {
if (str.endsWith("\"")) {
sb.append(Stream.ID_UNKNOWN);
sb.append(str.replace("\"", ""));
arrayList.add(sb.toString());
z = false;
} else {
sb.append(Stream.ID_UNKNOWN);
sb.append(str);
}
} else if (!str.isEmpty()) {
arrayList.add(str);
}
}
return arrayList;
}
}