MD5 校验值:61e58c10a11e4adec8760ee3854e996a
SoundcloudParsingHelper.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package org.schabi.newpipe.extractor.services.soundcloud; import S5.l; import S5.p; import U5.d; import V1.z; import Z5.a; import Z5.b; import a4.c; import androidx.fragment.app.X; import f0.AbstractC1761a; import java.io.IOException; import java.net.MalformedURLException; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.regex.Pattern; import java.util.stream.Collector; import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.http.HttpStatus; import org.schabi.newpipe.extractor.Image; import org.schabi.newpipe.extractor.MultiInfoItemsCollector; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector; import org.schabi.newpipe.extractor.downloader.Downloader; import org.schabi.newpipe.extractor.downloader.Response; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelInfoItemExtractor; import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudPlaylistInfoItemExtractor; import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamInfoItemExtractor; import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.utils.ImageSuffix; import org.schabi.newpipe.extractor.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; import p4.r; import v0.AbstractC2363a; public final class SoundcloudParsingHelper { private static final List<ImageSuffix> ALBUMS_AND_ARTWORKS_IMAGE_SUFFIXES; private static final Pattern ON_URL_PATTERN; public static final String SOUNDCLOUD_API_V2_URL = "https://api-v2.soundcloud.com/"; private static final List<ImageSuffix> VISUALS_IMAGE_SUFFIXES; private static String clientId; static { Image.ResolutionLevel resolutionLevel = Image.ResolutionLevel.LOW; ImageSuffix imageSuffix = new ImageSuffix("mini", 16, 16, resolutionLevel); ImageSuffix imageSuffix2 = new ImageSuffix("t20x20", 20, 20, resolutionLevel); ImageSuffix imageSuffix3 = new ImageSuffix("small", 32, 32, resolutionLevel); ImageSuffix imageSuffix4 = new ImageSuffix("badge", 47, 47, resolutionLevel); ImageSuffix imageSuffix5 = new ImageSuffix("t50x50", 50, 50, resolutionLevel); ImageSuffix imageSuffix6 = new ImageSuffix("t60x60", 60, 60, resolutionLevel); ImageSuffix imageSuffix7 = new ImageSuffix("t67x67", 67, 67, resolutionLevel); ImageSuffix imageSuffix8 = new ImageSuffix("t80x80", 80, 80, resolutionLevel); ImageSuffix imageSuffix9 = new ImageSuffix("large", 100, 100, resolutionLevel); ImageSuffix imageSuffix10 = new ImageSuffix("t120x120", 120, 120, resolutionLevel); Image.ResolutionLevel resolutionLevel2 = Image.ResolutionLevel.MEDIUM; ImageSuffix[] imageSuffixArr = {imageSuffix, imageSuffix2, imageSuffix3, imageSuffix4, imageSuffix5, imageSuffix6, imageSuffix7, imageSuffix8, imageSuffix9, imageSuffix10, new ImageSuffix("t200x200", 200, 200, resolutionLevel2), new ImageSuffix("t240x240", 240, 240, resolutionLevel2), new ImageSuffix("t250x250", 250, 250, resolutionLevel2), new ImageSuffix("t300x300", HttpStatus.SC_MULTIPLE_CHOICES, HttpStatus.SC_MULTIPLE_CHOICES, resolutionLevel2), new ImageSuffix("t500x500", HttpStatus.SC_INTERNAL_SERVER_ERROR, HttpStatus.SC_INTERNAL_SERVER_ERROR, resolutionLevel2)}; ArrayList arrayList = new ArrayList(15); for (int i5 = 0; i5 < 15; i5++) { ImageSuffix imageSuffix11 = imageSuffixArr[i5]; Objects.requireNonNull(imageSuffix11); arrayList.add(imageSuffix11); } ALBUMS_AND_ARTWORKS_IMAGE_SUFFIXES = Collections.unmodifiableList(arrayList); Image.ResolutionLevel resolutionLevel3 = Image.ResolutionLevel.MEDIUM; Object[] objArr = {new ImageSuffix("t1240x260", 1240, 260, resolutionLevel3), new ImageSuffix("t2480x520", 2480, 520, resolutionLevel3)}; ArrayList arrayList2 = new ArrayList(2); for (int i6 = 0; i6 < 2; i6++) { Object obj = objArr[i6]; Objects.requireNonNull(obj); arrayList2.add(obj); } VISUALS_IMAGE_SUFFIXES = Collections.unmodifiableList(arrayList2); ON_URL_PATTERN = Pattern.compile("^https?://on.soundcloud.com/[0-9a-zA-Z]+$"); } private SoundcloudParsingHelper() { } public static synchronized String clientId() { synchronized (SoundcloudParsingHelper.class) { if (!Utils.isNullOrEmpty(clientId)) { return clientId; } Downloader downloader = NewPipe.getDownloader(); d P6 = AbstractC2363a.w(downloader.get("https://soundcloud.com").responseBody()).P("script[src*=\"sndcdn.com/assets/\"][src$=\".js\"]"); Collections.reverse(P6); ArrayList arrayList = new ArrayList(1); Object obj = new Object[]{"bytes=0-50000"}[0]; Objects.requireNonNull(obj); arrayList.add(obj); Map<String, List<String>> x6 = X.x(Collections.unmodifiableList(arrayList)); Iterator<E> it = P6.iterator(); while (it.hasNext()) { String c7 = ((p) it.next()).c("src"); if (!Utils.isNullOrEmpty(c7)) { try { String matchGroup1 = Parser.matchGroup1(",client_id:\"(.*?)\"", downloader.get(c7, x6).responseBody()); clientId = matchGroup1; return matchGroup1; } catch (Parser.RegexException unused) { continue; } } } throw new ExtractionException("Couldn't extract client id"); } } public static List<Image> getAllImagesFromArtworkOrAvatarUrl(String str) { if (Utils.isNullOrEmpty(str)) { return Collections.emptyList(); } return getAllImagesFromImageUrlReturned(str.replace("-large.", "-%s."), ALBUMS_AND_ARTWORKS_IMAGE_SUFFIXES); } private static List<Image> getAllImagesFromImageUrlReturned(String str, List<ImageSuffix> list) { Collector unmodifiableList; Stream<R> map = list.stream().map(new b(str, 1)); unmodifiableList = Collectors.toUnmodifiableList(); return (List) map.collect(unmodifiableList); } public static List<Image> getAllImagesFromTrackObject(c cVar) { String h6 = cVar.h("artwork_url", null); if (h6 != null) { return getAllImagesFromArtworkOrAvatarUrl(h6); } String h7 = cVar.f("user").h("avatar_url", null); if (h7 != null) { return getAllImagesFromArtworkOrAvatarUrl(h7); } throw new ParsingException("Could not get track or track user's thumbnails"); } public static List<Image> getAllImagesFromVisualUrl(String str) { if (Utils.isNullOrEmpty(str)) { return Collections.emptyList(); } return getAllImagesFromImageUrlReturned(str.replace("-original.", "-%s."), VISUALS_IMAGE_SUFFIXES); } public static String getAvatarUrl(c cVar) { return Utils.replaceHttpWithHttps(cVar.f("user").h("avatar_url", "")); } public static String getInfoItemsFromApi(MultiInfoItemsCollector multiInfoItemsCollector, String str) { Response response = NewPipe.getDownloader().get(str, ServiceList.SoundCloud.getLocalization()); if (response.responseCode() < 400) { try { c cVar = (c) z.h().H(response.responseBody()); cVar.b("collection").stream().filter(new a(7)).map(new l(17)).forEach(new b6.a(multiInfoItemsCollector, 0)); try { String h6 = cVar.h("next_href", null); if (!h6.contains("client_id=")) { return h6 + "&client_id=" + clientId(); } return h6; } catch (Exception unused) { return ""; } } catch (a4.d e) { throw new ParsingException("Could not parse json response", e); } } throw new IOException(AbstractC1761a.e(response.responseCode(), "Could not get streams from API, HTTP ")); } private static String getNextPageUrl(c cVar) { try { String h6 = cVar.h("next_href", null); if (!h6.contains("client_id=")) { return h6 + "&client_id=" + clientId(); } return h6; } catch (Exception unused) { return ""; } } public static String getStreamsFromApi(StreamInfoItemsCollector streamInfoItemsCollector, String str) { return getStreamsFromApi(streamInfoItemsCollector, str, false); } public static String getStreamsFromApiMinItems(int i5, StreamInfoItemsCollector streamInfoItemsCollector, String str) { do { str = getStreamsFromApi(streamInfoItemsCollector, str); if (str.isEmpty()) { break; } } while (streamInfoItemsCollector.getItems().size() < i5); return str; } public static String getUploaderName(c cVar) { return cVar.f("user").h("username", ""); } public static String getUploaderUrl(c cVar) { return Utils.replaceHttpWithHttps(cVar.f("user").h("permalink_url", "")); } public static String getUsersFromApi(ChannelInfoItemsCollector channelInfoItemsCollector, String str) { try { c cVar = (c) z.h().H(NewPipe.getDownloader().get(str, ServiceList.SoundCloud.getLocalization()).responseBody()); Iterator<E> it = cVar.b("collection").iterator(); while (it.hasNext()) { Object next = it.next(); if (next instanceof c) { channelInfoItemsCollector.commit((ChannelInfoItemsCollector) new SoundcloudChannelInfoItemExtractor((c) next)); } } return getNextPageUrl(cVar); } catch (a4.d e) { throw new ParsingException("Could not parse json response", e); } } public static String getUsersFromApiMinItems(int i5, ChannelInfoItemsCollector channelInfoItemsCollector, String str) { do { str = getUsersFromApi(channelInfoItemsCollector, str); if (str.isEmpty()) { break; } } while (channelInfoItemsCollector.getItems().size() < i5); return str; } public static Image lambda$getAllImagesFromImageUrlReturned$1(String str, ImageSuffix imageSuffix) { return new Image(String.format(str, imageSuffix.getSuffix()), imageSuffix.getHeight(), imageSuffix.getWidth(), imageSuffix.getResolutionLevel()); } public static void lambda$getInfoItemsFromApi$0(MultiInfoItemsCollector multiInfoItemsCollector, c cVar) { Object soundcloudChannelInfoItemExtractor; String h6 = cVar.h("kind", ""); h6.getClass(); char c7 = 65535; switch (h6.hashCode()) { case 3599307: if (h6.equals("user")) { c7 = 0; break; } break; case 110621003: if (h6.equals("track")) { c7 = 1; break; } break; case 1879474642: if (h6.equals("playlist")) { c7 = 2; break; } break; } switch (c7) { case 0: soundcloudChannelInfoItemExtractor = new SoundcloudChannelInfoItemExtractor(cVar); multiInfoItemsCollector.commit((MultiInfoItemsCollector) soundcloudChannelInfoItemExtractor); return; case 1: soundcloudChannelInfoItemExtractor = new SoundcloudStreamInfoItemExtractor(cVar); multiInfoItemsCollector.commit((MultiInfoItemsCollector) soundcloudChannelInfoItemExtractor); return; case 2: soundcloudChannelInfoItemExtractor = new SoundcloudPlaylistInfoItemExtractor(cVar); multiInfoItemsCollector.commit((MultiInfoItemsCollector) soundcloudChannelInfoItemExtractor); return; default: return; } } public static OffsetDateTime parseDateFrom(String str) { try { return OffsetDateTime.parse(str); } catch (DateTimeParseException e) { try { return OffsetDateTime.parse(str, DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss +0000")); } catch (DateTimeParseException e7) { throw new ParsingException(AbstractC1761a.i("Could not parse date: \"", str, "\", ", e.getMessage()), e7); } } } public static c resolveFor(Downloader downloader, String str) { try { return (c) z.h().H(downloader.get(AbstractC1761a.i("https://api-v2.soundcloud.com/resolve?url=", Utils.encodeUrlUtf8(str), "&client_id=", clientId()), ServiceList.SoundCloud.getLocalization()).responseBody()); } catch (a4.d e) { throw new ParsingException("Could not parse json response", e); } } public static String resolveIdWithWidgetApi(String str) { if (ON_URL_PATTERN.matcher(str).find()) { try { str = NewPipe.getDownloader().head(str).latestUrl().split("\\?")[0]; } catch (ExtractionException e) { throw new ParsingException("Could not follow on.soundcloud.com redirect", e); } } if (str.charAt(str.length() - 1) == '/') { str = str.substring(0, str.length() - 1); } try { try { return String.valueOf(JsonUtils.getValue((c) z.h().H(NewPipe.getDownloader().get("https://api-widget.soundcloud.com/resolve?url=" + Utils.encodeUrlUtf8(Utils.stringToURL(Utils.removeMAndWWWFromUrl(str.toLowerCase())).toString()) + "&format=json&client_id=" + clientId(), ServiceList.SoundCloud.getLocalization()).responseBody()), "id")); } catch (a4.d e7) { throw new ParsingException("Could not parse JSON response", e7); } catch (ExtractionException e8) { throw new ParsingException("Could not resolve id with embedded player. ClientId not extracted", e8); } } catch (MalformedURLException unused) { throw new IllegalArgumentException("The given URL is not valid"); } } public static String resolveUrlWithEmbedPlayer(String str) { return AbstractC2363a.w(NewPipe.getDownloader().get(r.n("https://w.soundcloud.com/player/?url=", Utils.encodeUrlUtf8(str)), ServiceList.SoundCloud.getLocalization()).responseBody()).P("link[rel=\"canonical\"]").d().c("abs:href"); } public static String getStreamsFromApi(StreamInfoItemsCollector streamInfoItemsCollector, String str, boolean z6) { Response response = NewPipe.getDownloader().get(str, ServiceList.SoundCloud.getLocalization()); if (response.responseCode() >= 400) { throw new IOException(AbstractC1761a.e(response.responseCode(), "Could not get streams from API, HTTP ")); } try { c cVar = (c) z.h().H(response.responseBody()); Iterator<E> it = cVar.b("collection").iterator(); while (it.hasNext()) { Object next = it.next(); if (next instanceof c) { c cVar2 = (c) next; if (z6) { cVar2 = cVar2.f("track"); } streamInfoItemsCollector.commit((StreamInfoItemExtractor) new SoundcloudStreamInfoItemExtractor(cVar2)); } } return getNextPageUrl(cVar); } catch (a4.d e) { throw new ParsingException("Could not parse json response", e); } } }