Skip to content

Commit aecbd59

Browse files
Logging syntax changes
1 parent c8e8a00 commit aecbd59

File tree

4 files changed

+111
-107
lines changed

4 files changed

+111
-107
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private SoundcloudParsingHelper() {
102102

103103
public static synchronized String clientId() throws ExtractionException, IOException {
104104
if (!isNullOrEmpty(clientId)) {
105-
ExtractorLogger.d(TAG, "Returning clientId=" + clientId);
105+
ExtractorLogger.d(TAG, "Returning clientId={clientId}", clientId);
106106
return clientId;
107107
}
108108

@@ -124,11 +124,11 @@ public static synchronized String clientId() throws ExtractionException, IOExcep
124124
final String srcUrl = element.attr("src");
125125
if (!isNullOrEmpty(srcUrl)) {
126126
try {
127-
ExtractorLogger.d(TAG, "Searching for clientId in " + srcUrl);
127+
ExtractorLogger.d(TAG, "Searching for clientId in {srcUrl}", srcUrl);
128128
clientId = Parser.matchGroup1(clientIdPattern, dl.get(srcUrl, headers)
129129
.validateResponseCode()
130130
.responseBody());
131-
ExtractorLogger.d(TAG, "Found clientId=" + clientId);
131+
ExtractorLogger.d(TAG, "Found clientId={clientId}", clientId);
132132
return clientId;
133133
} catch (final RegexException ignored) {
134134
// Ignore it and proceed to try searching other script
@@ -164,7 +164,7 @@ public static DateWrapper parseDate(final String uploadDate) throws ParsingExcep
164164
// CHECKSTYLE:ON
165165
public static JsonObject resolveFor(@Nonnull final Downloader downloader, final String url)
166166
throws IOException, ExtractionException {
167-
ExtractorLogger.d(TAG, "resolveFor(" + url + ")");
167+
ExtractorLogger.d(TAG, "resolveFor({url})", url);
168168
final String apiUrl = SOUNDCLOUD_API_V2_URL + "resolve"
169169
+ "?url=" + Utils.encodeUrlUtf8(url)
170170
+ "&client_id=" + clientId();

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public SoundcloudStreamExtractor(final StreamingService service,
5959
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException,
6060
ExtractionException {
6161
final var url = getUrl();
62-
ExtractorLogger.d(TAG, "onFetchPage(" + url + ")");
62+
ExtractorLogger.d(TAG, "onFetchPage({url}", url);
6363
track = SoundcloudParsingHelper.resolveFor(downloader, url);
6464

6565
final String policy = track.getString("policy", "");
66-
ExtractorLogger.d(TAG, "policy is: " + policy);
66+
ExtractorLogger.d(TAG, "policy is: {policy}", policy);
6767
if (!policy.equals("ALLOW") && !policy.equals("MONETIZE")) {
6868
isAvailable = false;
6969

@@ -168,7 +168,7 @@ public List<AudioStream> getAudioStreams() throws ExtractionException {
168168
// For playing the track, it is only necessary to have a streamable track.
169169
// If this is not the case, this track might not be published yet.
170170
if (!track.getBoolean("streamable") || !isAvailable) {
171-
ExtractorLogger.d(TAG, "Not streamable track: " + getUrl());
171+
ExtractorLogger.d(TAG, "Not streamable track: {url}", getUrl());
172172
return audioStreams;
173173
}
174174

@@ -177,7 +177,7 @@ public List<AudioStream> getAudioStreams() throws ExtractionException {
177177
.getArray("transcodings");
178178
if (!isNullOrEmpty(transcodings)) {
179179
// Get information about what stream formats are available
180-
ExtractorLogger.d(TAG, "Extracting audio streams for " + getName());
180+
ExtractorLogger.d(TAG, "Extracting audio streams for {name}", getName());
181181
extractAudioStreams(transcodings, audioStreams);
182182
}
183183
} catch (final NullPointerException e) {
@@ -237,7 +237,7 @@ public String toString() {
237237
private StreamBuildResult buildBaseAudioStream(final JsonObject transcoding,
238238
final AudioStream.Builder builder)
239239
throws ExtractionException, IOException {
240-
ExtractorLogger.d(TAG, getName() + " Building base audio stream info");
240+
ExtractorLogger.d(TAG, "{name} Building base audio stream info", getName());
241241
final var preset = transcoding.getString("preset", ID_UNKNOWN);
242242
final MediaFormat mediaFormat;
243243
if (preset.contains("mp3")) {
@@ -266,7 +266,7 @@ private StreamBuildResult buildBaseAudioStream(final JsonObject transcoding,
266266

267267
private HlsAudioStream buildHlsAudioStream(final JsonObject transcoding)
268268
throws ExtractionException, IOException {
269-
ExtractorLogger.d(TAG, getName() + "Extracting hls audio stream");
269+
ExtractorLogger.d(TAG, "{name} Extracting hls audio stream", getName());
270270
final var builder = new HlsAudioStream.Builder();
271271
final StreamBuildResult buildResult = buildBaseAudioStream(transcoding, builder);
272272
if (buildResult == null) {
@@ -282,7 +282,7 @@ private HlsAudioStream buildHlsAudioStream(final JsonObject transcoding)
282282

283283
private AudioStream buildProgressiveAudioStream(final JsonObject transcoding)
284284
throws ExtractionException, IOException {
285-
ExtractorLogger.d(TAG, getName() + "Extracting progressive audio stream");
285+
ExtractorLogger.d(TAG, "{name} Extracting progressive audio stream", getName());
286286
final var builder = new AudioStream.Builder();
287287
final StreamBuildResult buildResult = buildBaseAudioStream(transcoding, builder);
288288
return buildResult == null ? null : builder.build();
@@ -317,8 +317,10 @@ private void extractAudioStreams(@Nonnull final JsonArray transcodings,
317317
: buildProgressiveAudioStream(transcoding);
318318
if (audioStream != null
319319
&& !Stream.containSimilarStream(audioStream, audioStreams)) {
320-
ExtractorLogger.d(TAG, audioStream.getFormat().getName() + " "
321-
+ getName() + " " + audioStream.getContent());
320+
ExtractorLogger.d(TAG, "{format} {trackName} {url}",
321+
audioStream.getFormat().getName(),
322+
getName(),
323+
audioStream.getContent());
322324
audioStreams.add(audioStream);
323325
}
324326
} catch (final ExtractionException | IOException e) {
Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,90 @@
1-
package org.schabi.newpipe.extractor.stream;
2-
3-
import com.grack.nanojson.JsonObject;
4-
import com.grack.nanojson.JsonParser;
5-
import com.grack.nanojson.JsonParserException;
6-
7-
import org.schabi.newpipe.extractor.MediaFormat;
8-
import org.schabi.newpipe.extractor.NewPipe;
9-
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
10-
import org.schabi.newpipe.extractor.exceptions.ParsingException;
11-
import org.schabi.newpipe.extractor.utils.ExtractorLogger;
12-
import org.schabi.newpipe.extractor.utils.Parser;
13-
14-
import java.io.IOException;
15-
import java.util.regex.Pattern;
16-
17-
import javax.annotation.Nonnull;
18-
19-
public final class SoundcloudHlsUtils {
20-
private static final String TAG = HlsAudioStream.class.getSimpleName();
21-
private static final Pattern MP3_HLS_PATTERN =
22-
Pattern.compile("https://cf-hls-media\\.sndcdn.com/playlist/"
23-
+ "([a-zA-Z0-9]+)\\.128\\.mp3/playlist\\.m3u8");
24-
private static final Pattern AAC_HLS_PATTERN =
25-
Pattern.compile("https://playback\\.media-streaming\\.soundcloud\\.cloud/"
26-
+ "([a-zA-Z0-9]+)/aac_160k/[a-f0-9\\-]+/playlist\\.m3u8");
27-
private static final Pattern OPUS_HLS_PATTERN =
28-
Pattern.compile("https://cf-hls-opus-media\\.sndcdn\\.com/"
29-
+ "playlist/([a-zA-Z0-9]+)\\.64\\.opus/playlist\\.m3u8");
30-
31-
private SoundcloudHlsUtils() { }
32-
33-
/**
34-
* Calls the API endpoint url for this stream to get the url for retrieving the
35-
* actual byte data for playback (returns the m3u8 playlist url for HLS streams,
36-
* and the url to get the full binary track for progressives streams)<p>
37-
*
38-
* NOTE: this returns a different url every time! (for SoundCloud)
39-
* @param apiStreamUrl The url to call to get the actual stream data url
40-
* @return The url for playing the audio (e.g. playlist.m3u8)
41-
* @throws IOException If there's a problem calling the endpoint
42-
* @throws ExtractionException for the same reason
43-
*/
44-
public static String getStreamContentUrl(final String apiStreamUrl)
45-
throws IOException, ExtractionException {
46-
ExtractorLogger.d(TAG, "Fetching content url for " + apiStreamUrl);
47-
final String response = NewPipe.getDownloader()
48-
.get(apiStreamUrl)
49-
.validateResponseCode()
50-
.responseBody();
51-
final JsonObject urlObject;
52-
try {
53-
urlObject = JsonParser.object().from(response);
54-
} catch (final JsonParserException e) {
55-
// TODO: Improve error message.
56-
throw new ParsingException("Could not parse stream content from URL ("
57-
+ response + ")", e);
58-
}
59-
60-
return urlObject.getString("url");
61-
}
62-
63-
@Nonnull
64-
public static String extractHlsPlaylistId(final String hlsPlaylistUrl,
65-
final MediaFormat mediaFormat)
66-
throws ExtractionException {
67-
switch (mediaFormat) {
68-
case MP3: return extractHlsMp3PlaylistId(hlsPlaylistUrl);
69-
case M4A: return extractHlsAacPlaylistId(hlsPlaylistUrl);
70-
case OPUS: return extractHlsOpusPlaylistId(hlsPlaylistUrl);
71-
default:
72-
throw new IllegalArgumentException("Unsupported media format: " + mediaFormat);
73-
}
74-
}
75-
76-
private static String extractHlsMp3PlaylistId(final String hlsPlaylistUrl)
77-
throws ExtractionException {
78-
return Parser.matchGroup1(MP3_HLS_PATTERN, hlsPlaylistUrl);
79-
}
80-
81-
private static String extractHlsAacPlaylistId(final String hlsPlaylistUrl)
82-
throws ExtractionException {
83-
return Parser.matchGroup1(AAC_HLS_PATTERN, hlsPlaylistUrl);
84-
}
85-
86-
private static String extractHlsOpusPlaylistId(final String hlsPlaylistUrl)
87-
throws ExtractionException {
88-
return Parser.matchGroup1(OPUS_HLS_PATTERN, hlsPlaylistUrl);
89-
}
90-
}
1+
package org.schabi.newpipe.extractor.stream;
2+
3+
import com.grack.nanojson.JsonObject;
4+
import com.grack.nanojson.JsonParser;
5+
import com.grack.nanojson.JsonParserException;
6+
7+
import org.schabi.newpipe.extractor.MediaFormat;
8+
import org.schabi.newpipe.extractor.NewPipe;
9+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
10+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
11+
import org.schabi.newpipe.extractor.utils.ExtractorLogger;
12+
import org.schabi.newpipe.extractor.utils.Parser;
13+
14+
import java.io.IOException;
15+
import java.util.regex.Pattern;
16+
17+
import javax.annotation.Nonnull;
18+
19+
public final class SoundcloudHlsUtils {
20+
private static final String TAG = HlsAudioStream.class.getSimpleName();
21+
private static final Pattern MP3_HLS_PATTERN =
22+
Pattern.compile("https://cf-hls-media\\.sndcdn.com/playlist/"
23+
+ "([a-zA-Z0-9]+)\\.128\\.mp3/playlist\\.m3u8");
24+
private static final Pattern AAC_HLS_PATTERN =
25+
Pattern.compile("https://playback\\.media-streaming\\.soundcloud\\.cloud/"
26+
+ "([a-zA-Z0-9]+)/aac_160k/[a-f0-9\\-]+/playlist\\.m3u8");
27+
private static final Pattern OPUS_HLS_PATTERN =
28+
Pattern.compile("https://cf-hls-opus-media\\.sndcdn\\.com/"
29+
+ "playlist/([a-zA-Z0-9]+)\\.64\\.opus/playlist\\.m3u8");
30+
31+
private SoundcloudHlsUtils() { }
32+
33+
/**
34+
* Calls the API endpoint url for this stream to get the url for retrieving the
35+
* actual byte data for playback (returns the m3u8 playlist url for HLS streams,
36+
* and the url to get the full binary track for progressives streams)<p>
37+
*
38+
* NOTE: this returns a different url every time! (for SoundCloud)
39+
* @param apiStreamUrl The url to call to get the actual stream data url
40+
* @return The url for playing the audio (e.g. playlist.m3u8)
41+
* @throws IOException If there's a problem calling the endpoint
42+
* @throws ExtractionException for the same reason
43+
*/
44+
public static String getStreamContentUrl(final String apiStreamUrl)
45+
throws IOException, ExtractionException {
46+
ExtractorLogger.d(TAG, "Fetching content url for {url}", apiStreamUrl);
47+
final String response = NewPipe.getDownloader()
48+
.get(apiStreamUrl)
49+
.validateResponseCode()
50+
.responseBody();
51+
final JsonObject urlObject;
52+
try {
53+
urlObject = JsonParser.object().from(response);
54+
} catch (final JsonParserException e) {
55+
// TODO: Improve error message.
56+
throw new ParsingException("Could not parse stream content from URL ("
57+
+ response + ")", e);
58+
}
59+
60+
return urlObject.getString("url");
61+
}
62+
63+
@Nonnull
64+
public static String extractHlsPlaylistId(final String hlsPlaylistUrl,
65+
final MediaFormat mediaFormat)
66+
throws ExtractionException {
67+
switch (mediaFormat) {
68+
case MP3: return extractHlsMp3PlaylistId(hlsPlaylistUrl);
69+
case M4A: return extractHlsAacPlaylistId(hlsPlaylistUrl);
70+
case OPUS: return extractHlsOpusPlaylistId(hlsPlaylistUrl);
71+
default:
72+
throw new IllegalArgumentException("Unsupported media format: " + mediaFormat);
73+
}
74+
}
75+
76+
private static String extractHlsMp3PlaylistId(final String hlsPlaylistUrl)
77+
throws ExtractionException {
78+
return Parser.matchGroup1(MP3_HLS_PATTERN, hlsPlaylistUrl);
79+
}
80+
81+
private static String extractHlsAacPlaylistId(final String hlsPlaylistUrl)
82+
throws ExtractionException {
83+
return Parser.matchGroup1(AAC_HLS_PATTERN, hlsPlaylistUrl);
84+
}
85+
86+
private static String extractHlsOpusPlaylistId(final String hlsPlaylistUrl)
87+
throws ExtractionException {
88+
return Parser.matchGroup1(OPUS_HLS_PATTERN, hlsPlaylistUrl);
89+
}
90+
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,14 @@ private static void extractStreams(final StreamInfo streamInfo,
190190
final var url = streamInfo.getOriginalUrl();
191191
final var name = streamInfo.getName();
192192
if (errors.isEmpty()) {
193-
ExtractorLogger.e(TAG, "Error extracting " + name + " " + url
194-
+ "\nCould not get any stream and didn't catch any errors");
193+
ExtractorLogger.e(TAG, "Error extracting {name} {url} \n"
194+
+ "Could not get any stream and didn't catch any errors",
195+
name, url);
195196
} else {
196197
errors.forEach(m -> ExtractorLogger.e(TAG,
197-
"Error for " + streamInfo.getOriginalUrl(),
198-
m));
198+
m,
199+
"Error for {url}",
200+
url));
199201
}
200202

201203
throw new StreamExtractException(

0 commit comments

Comments
 (0)