MD5 校验值:61e58c10a11e4adec8760ee3854e996a
SoundcloudStreamExtractor.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package org.schabi.newpipe.extractor.services.soundcloud.extractors; import S5.l; import V1.z; import Z5.a; import a4.C0230a; import a4.c; import a4.d; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Consumer; 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.soundcloud.SoundcloudParsingHelper; import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamExtractor; 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; import p4.r; public class SoundcloudStreamExtractor extends StreamExtractor { private boolean isAvailable; private c track; public SoundcloudStreamExtractor(StreamingService streamingService, LinkHandler linkHandler) { super(streamingService, linkHandler); this.isAvailable = true; } private static boolean checkMp3ProgressivePresence(C0230a c0230a) { return c0230a.stream().filter(new a(7)).map(new l(17)).anyMatch(new a(1)); } private void extractAudioStreams(C0230a c0230a, final boolean z6, final List<AudioStream> list) { c0230a.stream().filter(new a(7)).map(new l(17)).forEachOrdered(new Consumer() { @Override public final void accept(Object obj) { SoundcloudStreamExtractor.this.lambda$extractAudioStreams$1(z6, list, (a4.c) obj); } }); } private String getDownloadUrl(String str) { try { String h6 = ((c) z.h().H(NewPipe.getDownloader().get("https://api-v2.soundcloud.com/tracks/" + str + "/download?client_id=" + SoundcloudParsingHelper.clientId()).responseBody())).h("redirectUri", null); if (Utils.isNullOrEmpty(h6)) { return null; } return h6; } catch (d e) { throw new ParsingException("Could not parse download URL", e); } } private String getTranscodingUrl(String str) { try { return ((c) z.h().H(NewPipe.getDownloader().get(r.i(str, "?client_id=", SoundcloudParsingHelper.clientId())).responseBody())).h("url", null); } catch (d e) { throw new ParsingException("Could not parse streamable URL", e); } } public static boolean lambda$checkMp3ProgressivePresence$0(c cVar) { if (cVar.h("preset", null).contains("mp3") && cVar.f("format").h("protocol", null).equals("progressive")) { return true; } return false; } public void lambda$extractAudioStreams$1(boolean z6, List list, c cVar) { String h6 = cVar.h("url", null); if (Utils.isNullOrEmpty(h6)) { return; } try { String h7 = cVar.h("preset", Stream.ID_UNKNOWN); String h8 = cVar.f("format").h("protocol", null); AudioStream.Builder id = new AudioStream.Builder().setId(h7); boolean equals = h8.equals("hls"); if (equals) { id.setDeliveryMethod(DeliveryMethod.HLS); } id.setContent(getTranscodingUrl(h6), true); if (h7.contains("mp3")) { if (z6 && equals) { return; } id.setMediaFormat(MediaFormat.MP3); id.setAverageBitrate(128); } else if (h7.contains("opus")) { id.setMediaFormat(MediaFormat.OPUS); id.setAverageBitrate(64); id.setDeliveryMethod(DeliveryMethod.HLS); } else { return; } AudioStream build = id.build(); if (!Stream.containSimilarStream(build, list)) { list.add(build); } } catch (IOException | ExtractionException unused) { } } public void extractDownloadableFileIfAvailable(List<AudioStream> list) { if (this.track.c("downloadable") && this.track.c("has_downloads_left")) { try { String downloadUrl = getDownloadUrl(getId()); if (!Utils.isNullOrEmpty(downloadUrl)) { list.add(new AudioStream.Builder().setId("original-format").setContent(downloadUrl, true).setAverageBitrate(-1).build()); } } catch (Exception unused) { } } } @Override public List<AudioStream> getAudioStreams() { ArrayList arrayList = new ArrayList(); if (this.track.c("streamable") && this.isAvailable) { try { C0230a b7 = this.track.f("media").b("transcodings"); if (!Utils.isNullOrEmpty(b7)) { extractAudioStreams(b7, checkMp3ProgressivePresence(b7), arrayList); } extractDownloadableFileIfAvailable(arrayList); return arrayList; } catch (NullPointerException e) { throw new ExtractionException("Could not get audio streams", e); } } return arrayList; } @Override public String getCategory() { return this.track.h("genre", null); } @Override public Description getDescription() { return new Description(this.track.h("description", null), 3); } @Override public String getId() { return String.valueOf(this.track.d(0, "id")); } @Override public long getLength() { return this.track.e(0L, "duration") / 1000; } @Override public String getLicence() { return this.track.h("license", null); } @Override public long getLikeCount() { return this.track.e(-1L, "likes_count"); } @Override public String getName() { return this.track.h("title", null); } @Override public StreamExtractor.Privacy getPrivacy() { if (this.track.h("sharing", null).equals("public")) { return StreamExtractor.Privacy.PUBLIC; } return StreamExtractor.Privacy.PRIVATE; } @Override public StreamType getStreamType() { return StreamType.AUDIO_STREAM; } @Override public List<String> getTags() { String[] split = this.track.h("tag_list", null).split(Stream.ID_UNKNOWN); ArrayList arrayList = new ArrayList(); StringBuilder sb = new StringBuilder(); boolean z6 = false; for (String str : split) { if (str.startsWith("\"")) { sb.append(str.replace("\"", "")); z6 = true; } else if (z6) { boolean endsWith = str.endsWith("\""); sb.append(Stream.ID_UNKNOWN); if (endsWith) { sb.append(str.replace("\"", "")); arrayList.add(sb.toString()); z6 = false; } else { sb.append(str); } } else if (!str.isEmpty()) { arrayList.add(str); } } return arrayList; } @Override public String getTextualUploadDate() { return this.track.h("created_at", null).replace("T", Stream.ID_UNKNOWN).replace("Z", ""); } @Override public List<Image> getThumbnails() { return SoundcloudParsingHelper.getAllImagesFromTrackObject(this.track); } @Override public long getTimeStamp() { return getTimestampSeconds("(#t=\\d{0,3}h?\\d{0,3}m?\\d{1,3}s?)"); } @Override public DateWrapper getUploadDate() { return new DateWrapper(SoundcloudParsingHelper.parseDateFrom(this.track.h("created_at", null))); } @Override public List<Image> getUploaderAvatars() { return SoundcloudParsingHelper.getAllImagesFromArtworkOrAvatarUrl(SoundcloudParsingHelper.getAvatarUrl(this.track)); } @Override public String getUploaderName() { return SoundcloudParsingHelper.getUploaderName(this.track); } @Override public String getUploaderUrl() { return SoundcloudParsingHelper.getUploaderUrl(this.track); } @Override public List<VideoStream> getVideoOnlyStreams() { return Collections.emptyList(); } @Override public List<VideoStream> getVideoStreams() { return Collections.emptyList(); } @Override public long getViewCount() { return this.track.e(0L, "playback_count"); } @Override public boolean isUploaderVerified() { return this.track.f("user").c("verified"); } @Override public void onFetchPage(Downloader downloader) { c resolveFor = SoundcloudParsingHelper.resolveFor(downloader, getUrl()); this.track = resolveFor; String h6 = resolveFor.h("policy", ""); if (h6.equals("ALLOW") || h6.equals("MONETIZE")) { return; } this.isAvailable = false; if (h6.equals("SNIP")) { throw new SoundCloudGoPlusContentException(); } if (!h6.equals("BLOCK")) { throw new ContentNotAvailableException("Content not available: policy ".concat(h6)); } throw new GeographicRestrictionException("This track is not available in user's country"); } @Override public StreamInfoItemsCollector getRelatedItems() { 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; } }