Skip to content

Commit de0d874

Browse files
[SoundCloud] Add logging to SoundcloudParsingHelper, SoundcloudStreamExtractor, StreamInfo
1 parent 7828a2a commit de0d874

5 files changed

Lines changed: 50 additions & 2 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void init(final Downloader d) {
4949
}
5050

5151
public static void init(final Downloader d, final Localization l) {
52-
ExtractorLogger.d(TAG, "Default init called with localization={}");
52+
ExtractorLogger.d(TAG, "Default init called with localization");
5353
init(d, l, l.getCountryCode().isEmpty()
5454
? ContentCountry.DEFAULT : new ContentCountry(l.getCountryCode()));
5555
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
import java.util.Objects;
4+
5+
public enum StreamingServiceId {
6+
NO_SERVICE_ID,
7+
YOUTUBE,
8+
SOUNDCLOUD,
9+
MEDIACCC,
10+
PEERTUBE,
11+
BANDCAMP;
12+
13+
14+
private static final StreamingServiceId[] VALUES = values();
15+
16+
public static String nameFromId(final int serviceId) {
17+
try {
18+
return VALUES[Objects.checkIndex(serviceId + 1, VALUES.length)].name();
19+
} catch (final IndexOutOfBoundsException e) {
20+
throw new IllegalArgumentException("Invalid serviceId: " + serviceId, e);
21+
}
22+
}
23+
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudLikesInfoItemExtractor;
3030
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamInfoItemExtractor;
3131
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
32+
import org.schabi.newpipe.extractor.utils.ExtractorLogger;
3233
import org.schabi.newpipe.extractor.utils.ImageSuffix;
3334
import org.schabi.newpipe.extractor.utils.JsonUtils;
3435
import org.schabi.newpipe.extractor.utils.Parser;
@@ -87,6 +88,7 @@ public final class SoundcloudParsingHelper {
8788
private static final List<ImageSuffix> VISUALS_IMAGE_SUFFIXES =
8889
List.of(new ImageSuffix("t1240x260", 1240, 260, MEDIUM),
8990
new ImageSuffix("t2480x520", 2480, 520, MEDIUM));
91+
public static final String TAG = SoundcloudParsingHelper.class.getSimpleName();
9092

9193
private static String clientId;
9294
public static final String SOUNDCLOUD_API_V2_URL = "https://api-v2.soundcloud.com/";
@@ -100,6 +102,7 @@ private SoundcloudParsingHelper() {
100102

101103
public static synchronized String clientId() throws ExtractionException, IOException {
102104
if (!isNullOrEmpty(clientId)) {
105+
ExtractorLogger.d(TAG, "Returning clientId=" + clientId);
103106
return clientId;
104107
}
105108

@@ -121,9 +124,11 @@ public static synchronized String clientId() throws ExtractionException, IOExcep
121124
final String srcUrl = element.attr("src");
122125
if (!isNullOrEmpty(srcUrl)) {
123126
try {
127+
ExtractorLogger.d(TAG, "Searching for clientId in " + srcUrl);
124128
clientId = Parser.matchGroup1(clientIdPattern, dl.get(srcUrl, headers)
125129
.validateResponseCode()
126130
.responseBody());
131+
ExtractorLogger.d(TAG, "Found clientId=" + clientId);
127132
return clientId;
128133
} catch (final RegexException ignored) {
129134
// Ignore it and proceed to try searching other script
@@ -159,6 +164,7 @@ public static DateWrapper parseDate(final String uploadDate) throws ParsingExcep
159164
// CHECKSTYLE:ON
160165
public static JsonObject resolveFor(@Nonnull final Downloader downloader, final String url)
161166
throws IOException, ExtractionException {
167+
ExtractorLogger.d(TAG, "resolveFor(" + url + ")");
162168
final String apiUrl = SOUNDCLOUD_API_V2_URL + "resolve"
163169
+ "?url=" + Utils.encodeUrlUtf8(url)
164170
+ "&client_id=" + clientId();

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
3636
import org.schabi.newpipe.extractor.stream.StreamType;
3737
import org.schabi.newpipe.extractor.stream.VideoStream;
38+
import org.schabi.newpipe.extractor.utils.ExtractorLogger;
3839
import org.schabi.newpipe.extractor.utils.Utils;
3940

4041
import java.io.IOException;
@@ -46,6 +47,7 @@
4647
import javax.annotation.Nullable;
4748

4849
public class SoundcloudStreamExtractor extends StreamExtractor {
50+
public static final String TAG = SoundcloudStreamExtractor.class.getSimpleName();
4951
private JsonObject track;
5052
private boolean isAvailable = true;
5153

@@ -57,9 +59,12 @@ public SoundcloudStreamExtractor(final StreamingService service,
5759
@Override
5860
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException,
5961
ExtractionException {
60-
track = SoundcloudParsingHelper.resolveFor(downloader, getUrl());
62+
final var url = getUrl();
63+
ExtractorLogger.d(TAG, "onFetchPage(" + url + ")");
64+
track = SoundcloudParsingHelper.resolveFor(downloader, url);
6165

6266
final String policy = track.getString("policy", "");
67+
ExtractorLogger.d(TAG, "policy is: " + policy);
6368
if (!policy.equals("ALLOW") && !policy.equals("MONETIZE")) {
6469
isAvailable = false;
6570

@@ -164,6 +169,7 @@ public List<AudioStream> getAudioStreams() throws ExtractionException {
164169
// For playing the track, it is only necessary to have a streamable track.
165170
// If this is not the case, this track might not be published yet.
166171
if (!track.getBoolean("streamable") || !isAvailable) {
172+
ExtractorLogger.d(TAG, "Not streamable track: " + getUrl());
167173
return audioStreams;
168174
}
169175

@@ -172,6 +178,7 @@ public List<AudioStream> getAudioStreams() throws ExtractionException {
172178
.getArray("transcodings");
173179
if (!isNullOrEmpty(transcodings)) {
174180
// Get information about what stream formats are available
181+
ExtractorLogger.d(TAG, "Extracting audio streams for " + getName());
175182
extractAudioStreams(transcodings, audioStreams);
176183
}
177184
} catch (final NullPointerException e) {

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ private static void extractStreams(final StreamInfo streamInfo,
186186
// Either audio or video has to be available, otherwise we didn't get a stream (since
187187
// videoOnly are optional, they don't count).
188188
if ((streamInfo.videoStreams.isEmpty()) && (streamInfo.audioStreams.isEmpty())) {
189+
final var errors = streamInfo.getErrors();
190+
final var url = streamInfo.getOriginalUrl();
191+
final var name = streamInfo.getName();
192+
if (errors.isEmpty()) {
193+
ExtractorLogger.e(TAG, "Error extracting " + name + " " + url
194+
+ "\nCould not get any stream and didn't catch any errors");
195+
} else {
196+
errors.forEach(m -> ExtractorLogger.e(TAG,
197+
"Error for " + streamInfo.getOriginalUrl(),
198+
m));
199+
}
200+
189201
throw new StreamExtractException(
190202
"Could not get any stream. See error variable to get further details.");
191203
}

0 commit comments

Comments
 (0)