Skip to content

Commit f9ffe2f

Browse files
committed
Made YT proxyable
* allows usage of YouTubeLike services, e.g. invidious * simplified some classes/code * Added support for invidious * Some credits go to @B0pol's PR #555 for that ;)
1 parent 34f9d3f commit f9ffe2f

File tree

132 files changed

+3796
-1619
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+3796
-1619
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
import org.schabi.newpipe.extractor.instance.Instance;
4+
5+
public interface InstanceBasedStreamingService<I extends Instance> {
6+
I getInstance();
7+
8+
void setInstance(I instance);
9+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* A list of supported services.
3333
*/
34-
@SuppressWarnings({"ConstantName", "InnerAssignment"}) // keep unusual names and inner assignments
34+
// keep unusual names and inner assignments
3535
public final class ServiceList {
3636
private ServiceList() {
3737
//no instance

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
2424
import org.schabi.newpipe.extractor.utils.Utils;
2525

26-
import javax.annotation.Nullable;
2726
import java.util.Collections;
2827
import java.util.List;
2928

29+
import javax.annotation.Nullable;
30+
3031
/*
3132
* Copyright (C) Christian Schabesberger 2018 <[email protected]>
3233
* StreamingService.java is part of NewPipe.
@@ -97,13 +98,14 @@ public enum LinkType {
9798
* If you Implement one do not set id within your implementation of this extractor, instead
9899
* set the id when you put the extractor into {@link ServiceList}
99100
* All other parameters can be set directly from the overriding constructor.
100-
* @param id the number of the service to identify him within the NewPipe frontend
101-
* @param name the name of the service
101+
*
102+
* @param id the number of the service to identify him within the NewPipe frontend
103+
* @param name the name of the service
102104
* @param capabilities the type of media this service can handle
103105
*/
104-
public StreamingService(final int id,
105-
final String name,
106-
final List<ServiceInfo.MediaCapability> capabilities) {
106+
protected StreamingService(final int id,
107+
final String name,
108+
final List<ServiceInfo.MediaCapability> capabilities) {
107109
this.serviceId = id;
108110
this.serviceInfo = new ServiceInfo(name, capabilities);
109111
}
@@ -192,9 +194,10 @@ public FeedExtractor getFeedExtractor(final String url) throws ExtractionExcepti
192194

193195
/**
194196
* Must create a new instance of a KioskList implementation.
197+
*
195198
* @return a new KioskList instance
196199
*/
197-
public abstract KioskList getKioskList() throws ExtractionException;
200+
public abstract KioskList getKioskList();
198201

199202
/**
200203
* Must create a new instance of a ChannelExtractor implementation.

extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,29 @@ public ChannelExtractor(final StreamingService service, final ListLinkHandler li
3535
}
3636

3737
public abstract String getAvatarUrl() throws ParsingException;
38+
3839
public abstract String getBannerUrl() throws ParsingException;
40+
3941
public abstract String getFeedUrl() throws ParsingException;
42+
4043
public abstract long getSubscriberCount() throws ParsingException;
44+
4145
public abstract String getDescription() throws ParsingException;
42-
public abstract String getParentChannelName() throws ParsingException;
43-
public abstract String getParentChannelUrl() throws ParsingException;
44-
public abstract String getParentChannelAvatarUrl() throws ParsingException;
45-
public abstract boolean isVerified() throws ParsingException;
46+
47+
public String getParentChannelName() throws ParsingException {
48+
return null;
49+
}
50+
51+
public String getParentChannelUrl() throws ParsingException {
52+
return null;
53+
}
54+
55+
public String getParentChannelAvatarUrl() throws ParsingException {
56+
return null;
57+
}
58+
59+
public boolean isVerified() throws ParsingException {
60+
return false;
61+
}
4662

4763
}

extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemExtractor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ public interface ChannelInfoItemExtractor extends InfoItemExtractor {
3030

3131
long getStreamCount() throws ParsingException;
3232

33-
boolean isVerified() throws ParsingException;
33+
default boolean isVerified() throws ParsingException {
34+
return false;
35+
}
3436
}

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.schabi.newpipe.extractor.Page;
55
import org.schabi.newpipe.extractor.exceptions.ParsingException;
66
import org.schabi.newpipe.extractor.localization.DateWrapper;
7-
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeCommentsInfoItemExtractor;
7+
import org.schabi.newpipe.extractor.services.youtube.youtube.extractors.YoutubeCommentsInfoItemExtractor;
88
import org.schabi.newpipe.extractor.stream.StreamExtractor;
99
import org.schabi.newpipe.extractor.utils.Utils;
1010

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.schabi.newpipe.extractor.instance;
2+
3+
import org.schabi.newpipe.extractor.utils.Utils;
4+
5+
import java.net.URI;
6+
import java.util.Objects;
7+
8+
import javax.annotation.Nonnull;
9+
10+
public abstract class AbstractInstance implements Instance {
11+
12+
protected Boolean valid = null;
13+
14+
protected final String url;
15+
protected String name;
16+
17+
protected AbstractInstance(final String url, final String name) {
18+
this.url = removeTrailingSlashes(Objects.requireNonNull(url));
19+
this.name = name;
20+
}
21+
22+
@Nonnull
23+
@Override
24+
public String getName() {
25+
return name;
26+
}
27+
28+
@Nonnull
29+
@Override
30+
public String getUrl() {
31+
return url;
32+
}
33+
34+
public void setName(final String name) {
35+
this.name = Objects.requireNonNull(name);
36+
}
37+
38+
@Override
39+
public void fetchMetadata() {
40+
// Default: Do nothing
41+
}
42+
43+
public static String removeTrailingSlashes(final String input) {
44+
return input.replaceAll("/*$", "");
45+
}
46+
47+
public static String tryExtractDomainFromUrl(final String url, final String fallback) {
48+
Objects.requireNonNull(url);
49+
try {
50+
return Utils.removeMAndWWWFromHost(new URI(url).getHost());
51+
} catch (final Exception ignored) {
52+
return fallback;
53+
}
54+
}
55+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.schabi.newpipe.extractor.instance;
2+
3+
import javax.annotation.Nonnull;
4+
5+
public interface Instance {
6+
7+
/**
8+
* The name of the instance.
9+
* <br/>
10+
* Note: May only be available after {@link #fetchMetadata()} was called
11+
*
12+
* @return the instance-name
13+
*/
14+
String getName();
15+
16+
/**
17+
* The base url of this instance.
18+
* <br/>
19+
* Note that the url is returned without trailing slashes.
20+
* Use {@link #getUrlWithTrailingSlash()} if you want a trailing slash.
21+
*
22+
* @return base url
23+
*/
24+
@Nonnull
25+
String getUrl();
26+
27+
default String getUrlWithTrailingSlash() {
28+
return getUrl() + "/";
29+
}
30+
31+
32+
/**
33+
* Fetch instance metadata.
34+
*
35+
* @throws InstanceMetaDataFetchException
36+
*/
37+
void fetchMetadata();
38+
39+
/**
40+
* Returns the service name, e.g. "Invidious" for an invidious instance.
41+
* @return service name or <code>null</code> if the name of the streamingservice should be used
42+
*/
43+
default String getServiceName() {
44+
return null;
45+
}
46+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.schabi.newpipe.extractor.instance;
2+
3+
public class InstanceMetaDataFetchException extends RuntimeException {
4+
public InstanceMetaDataFetchException(final String message) {
5+
super(message);
6+
}
7+
8+
public InstanceMetaDataFetchException(final String message, final Throwable cause) {
9+
super(message, cause);
10+
}
11+
12+
public InstanceMetaDataFetchException(final Throwable cause) {
13+
super(cause);
14+
}
15+
}

extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ public KioskList(final StreamingService service) {
5050

5151
public void addKioskEntry(final KioskExtractorFactory extractorFactory,
5252
final ListLinkHandlerFactory handlerFactory,
53-
final String id)
54-
throws Exception {
53+
final String id) {
5554
if (kioskList.get(id) != null) {
56-
throw new Exception("Kiosk with type " + id + " already exists.");
55+
throw new IllegalArgumentException("Kiosk with type " + id + " already exists.");
5756
}
5857
kioskList.put(id, new KioskEntry(extractorFactory, handlerFactory));
5958
}

0 commit comments

Comments
 (0)