Skip to content

Commit 3a252d0

Browse files
authored
Merge pull request #1403 from absurdlylongusername/add-extractor-logging
Add logging to extractor
2 parents 912a989 + 30416f4 commit 3a252d0

11 files changed

Lines changed: 551 additions & 1 deletion

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.schabi.newpipe.extractor.localization.ContentCountry;
88
import org.schabi.newpipe.extractor.localization.Localization;
99
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
10+
import org.schabi.newpipe.extractor.utils.ExtractorLogger;
1011

1112
import javax.annotation.Nonnull;
1213
import javax.annotation.Nullable;
@@ -15,6 +16,8 @@
1516
import java.util.Objects;
1617

1718
public abstract class Extractor {
19+
private final String TAG = getClass().getSimpleName() + "@" + hashCode();
20+
1821
/**
1922
* {@link StreamingService} currently related to this extractor.<br>
2023
* Useful for getting other things from a service (like the url handlers for
@@ -54,7 +57,9 @@ public LinkHandler getLinkHandler() {
5457
* @throws ExtractionException if the pages content is not understood
5558
*/
5659
public void fetchPage() throws IOException, ExtractionException {
60+
ExtractorLogger.d(TAG, "base fetchPage called");
5761
if (pageFetched) {
62+
ExtractorLogger.d(TAG, "Page already fetched; returning");
5863
return;
5964
}
6065
onFetchPage(downloader);
@@ -151,4 +156,9 @@ public ContentCountry getExtractorContentCountry() {
151156
public TimeAgoParser getTimeAgoParser() {
152157
return getService().getTimeAgoParser(getExtractorLocalization());
153158
}
159+
160+
@Override
161+
public String toString() {
162+
return getClass().getSimpleName();
163+
}
154164
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
44
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
5+
import org.schabi.newpipe.extractor.utils.ExtractorLogger;
56

67
import java.io.Serializable;
78
import java.util.ArrayList;
@@ -10,6 +11,7 @@
1011

1112
public abstract class Info implements Serializable {
1213

14+
private static final String TAG = "Info";
1315
private final int serviceId;
1416
/**
1517
* Id of this Info object <br>
@@ -52,6 +54,7 @@ public Info(final int serviceId,
5254
this.url = url;
5355
this.originalUrl = originalUrl;
5456
this.name = name;
57+
ExtractorLogger.d(TAG, "Base Created {}", this);
5558
}
5659

5760
public Info(final int serviceId, final LinkHandler linkHandler, final String name) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
2525
import org.schabi.newpipe.extractor.localization.ContentCountry;
2626
import org.schabi.newpipe.extractor.localization.Localization;
27+
import org.schabi.newpipe.extractor.utils.ExtractorLogger;
2728

2829
import java.util.List;
2930

@@ -34,6 +35,7 @@
3435
* Provides access to streaming services supported by NewPipe.
3536
*/
3637
public final class NewPipe {
38+
private static final String TAG = NewPipe.class.getSimpleName();
3739
private static Downloader downloader;
3840
private static Localization preferredLocalization;
3941
private static ContentCountry preferredContentCountry;
@@ -42,15 +44,19 @@ private NewPipe() {
4244
}
4345

4446
public static void init(final Downloader d) {
47+
ExtractorLogger.d(TAG, "Default init called");
4548
init(d, Localization.DEFAULT);
4649
}
4750

4851
public static void init(final Downloader d, final Localization l) {
52+
ExtractorLogger.d(TAG, "Default init called with localization={}");
4953
init(d, l, l.getCountryCode().isEmpty()
5054
? ContentCountry.DEFAULT : new ContentCountry(l.getCountryCode()));
5155
}
5256

5357
public static void init(final Downloader d, final Localization l, final ContentCountry c) {
58+
ExtractorLogger.d(TAG, "Initializing with downloader={}, localization={}, country={}",
59+
d, l, c);
5460
downloader = d;
5561
preferredLocalization = l;
5662
preferredContentCountry = c;

extractor/src/main/java/org/schabi/newpipe/extractor/downloader/Downloader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,9 @@ public Response postWithContentTypeJson(final String url,
243243
*/
244244
public abstract Response execute(@Nonnull Request request)
245245
throws IOException, ReCaptchaException;
246+
247+
@Override
248+
public String toString() {
249+
return getClass().getSimpleName();
250+
}
246251
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
3232
import org.schabi.newpipe.extractor.localization.DateWrapper;
3333
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
34+
import org.schabi.newpipe.extractor.utils.ExtractorLogger;
3435

3536
import java.io.IOException;
3637
import java.util.List;
@@ -44,7 +45,7 @@
4445
* Info object for opened contents, i.e. the content ready to play.
4546
*/
4647
public class StreamInfo extends Info {
47-
48+
private static final String TAG = StreamInfo.class.getSimpleName();
4849
public static class StreamExtractException extends ExtractionException {
4950
StreamExtractException(final String message) {
5051
super(message);
@@ -61,19 +62,36 @@ public StreamInfo(final int serviceId,
6162
super(serviceId, id, url, originalUrl, name);
6263
this.streamType = streamType;
6364
this.ageLimit = ageLimit;
65+
ExtractorLogger.d(TAG, "Created {}", this);
66+
}
67+
68+
@Override
69+
public String toString() {
70+
return TAG + "["
71+
+ "serviceId=" + getServiceId()
72+
+ ", url='" + getUrl() + '\''
73+
+ ", originalUrl='" + getOriginalUrl() + '\''
74+
+ ", id='" + getId() + '\''
75+
+ ", name='" + getName() + '\''
76+
+ ", streamType=" + streamType
77+
+ ", ageLimit=" + ageLimit
78+
+ ']';
6479
}
6580

6681
public static StreamInfo getInfo(final String url) throws IOException, ExtractionException {
82+
ExtractorLogger.d(TAG, "getInfo({url})", url);
6783
return getInfo(NewPipe.getServiceByUrl(url), url);
6884
}
6985

7086
public static StreamInfo getInfo(@Nonnull final StreamingService service,
7187
final String url) throws IOException, ExtractionException {
88+
ExtractorLogger.d(TAG, "getInfo({service},{url})", service, url);
7289
return getInfo(service.getStreamExtractor(url));
7390
}
7491

7592
public static StreamInfo getInfo(@Nonnull final StreamExtractor extractor)
7693
throws ExtractionException, IOException {
94+
ExtractorLogger.d(TAG, "getInfo({extractor})", extractor);
7795
extractor.fetchPage();
7896
final StreamInfo streamInfo;
7997
try {

0 commit comments

Comments
 (0)