Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made YouTube service proxyable/pluggable and add support for invidious #833

Draft
wants to merge 21 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.schabi.newpipe.extractor;

import org.schabi.newpipe.extractor.instance.Instance;

public interface InstanceBasedStreamingService<I extends Instance> {
I getInstance();

void setInstance(I instance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@
/**
* A list of supported services.
*/
@SuppressWarnings({"ConstantName", "InnerAssignment"}) // keep unusual names and inner assignments
@SuppressWarnings("ConstantName") // keep unusual names
public final class ServiceList {
private ServiceList() {
//no instance
}

public static final YoutubeService YouTube;
public static final SoundcloudService SoundCloud;
public static final MediaCCCService MediaCCC;
public static final PeertubeService PeerTube;
public static final BandcampService Bandcamp;
public static final YoutubeService YouTube = new YoutubeService(0);
public static final SoundcloudService SoundCloud = new SoundcloudService(1);
public static final MediaCCCService MediaCCC = new MediaCCCService(2);
public static final PeertubeService PeerTube = new PeertubeService(3);
public static final BandcampService Bandcamp = new BandcampService(4);

/**
* When creating a new service, put this service in the end of this list,
* and give it the next free id.
*/
private static final List<StreamingService> SERVICES = Collections.unmodifiableList(
Arrays.asList(
YouTube = new YoutubeService(0),
SoundCloud = new SoundcloudService(1),
MediaCCC = new MediaCCCService(2),
PeerTube = new PeertubeService(3),
Bandcamp = new BandcampService(4)
YouTube,
SoundCloud,
MediaCCC,
PeerTube,
Bandcamp
));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
import org.schabi.newpipe.extractor.utils.Utils;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;

import javax.annotation.Nullable;

/*
* Copyright (C) Christian Schabesberger 2018 <[email protected]>
* StreamingService.java is part of NewPipe.
Expand Down Expand Up @@ -97,13 +98,14 @@ public enum LinkType {
* If you Implement one do not set id within your implementation of this extractor, instead
* set the id when you put the extractor into {@link ServiceList}
* All other parameters can be set directly from the overriding constructor.
* @param id the number of the service to identify him within the NewPipe frontend
* @param name the name of the service
*
* @param id the number of the service to identify him within the NewPipe frontend
* @param name the name of the service
* @param capabilities the type of media this service can handle
*/
public StreamingService(final int id,
final String name,
final List<ServiceInfo.MediaCapability> capabilities) {
protected StreamingService(final int id,
final String name,
final List<ServiceInfo.MediaCapability> capabilities) {
this.serviceId = id;
this.serviceInfo = new ServiceInfo(name, capabilities);
}
Expand Down Expand Up @@ -192,9 +194,10 @@ public FeedExtractor getFeedExtractor(final String url) throws ExtractionExcepti

/**
* Must create a new instance of a KioskList implementation.
*
* @return a new KioskList instance
*/
public abstract KioskList getKioskList() throws ExtractionException;
public abstract KioskList getKioskList();

/**
* Must create a new instance of a ChannelExtractor implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,29 @@ public ChannelExtractor(final StreamingService service, final ListLinkHandler li
}

public abstract String getAvatarUrl() throws ParsingException;

public abstract String getBannerUrl() throws ParsingException;

public abstract String getFeedUrl() throws ParsingException;

public abstract long getSubscriberCount() throws ParsingException;

public abstract String getDescription() throws ParsingException;
public abstract String getParentChannelName() throws ParsingException;
public abstract String getParentChannelUrl() throws ParsingException;
public abstract String getParentChannelAvatarUrl() throws ParsingException;
public abstract boolean isVerified() throws ParsingException;

public String getParentChannelName() throws ParsingException {
return null;
}

public String getParentChannelUrl() throws ParsingException {
return null;
}

public String getParentChannelAvatarUrl() throws ParsingException {
return null;
}

public boolean isVerified() throws ParsingException {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ public interface ChannelInfoItemExtractor extends InfoItemExtractor {

long getStreamCount() throws ParsingException;

boolean isVerified() throws ParsingException;
default boolean isVerified() throws ParsingException {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeCommentsInfoItemExtractor;
import org.schabi.newpipe.extractor.services.youtube.youtube.extractors.YoutubeCommentsInfoItemExtractor;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.utils.Utils;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.schabi.newpipe.extractor.instance;

import org.schabi.newpipe.extractor.utils.Utils;

import java.net.URI;
import java.util.Objects;

import javax.annotation.Nonnull;

public abstract class AbstractInstance implements Instance {

protected final String url;
protected String name;

protected AbstractInstance(final String url, final String name) {
this.url = removeTrailingSlashes(Objects.requireNonNull(url));
this.name = name;
}

@Nonnull
@Override
public String getName() {
return name;
}

@Nonnull
@Override
public String getUrl() {
return url;
}

public void setName(final String name) {
this.name = Objects.requireNonNull(name);
}

@Override
public void fetchMetadata() {
// Default: Do nothing
}

public static String removeTrailingSlashes(final String input) {
return input.replaceAll("/*$", "");
}

public static String tryExtractDomainFromUrl(final String url, final String fallback) {
Objects.requireNonNull(url);
try {
return Utils.removeMAndWWWFromHost(new URI(url).getHost());
} catch (final Exception ignored) {
return fallback;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.schabi.newpipe.extractor.instance;

import javax.annotation.Nonnull;

public interface Instance {

/**
* The name of the instance.
* <br/>
* Note: May only be available after {@link #fetchMetadata()} was called
*
* @return the instance-name
*/
String getName();

/**
* The base url of this instance.
* <br/>
* Note that the url is returned without trailing slashes.
*
* @return base url
*/
@Nonnull
String getUrl();


/**
* Fetch instance metadata.
*
* @throws InstanceMetaDataFetchException
*/
void fetchMetadata();

/**
* Returns the service name, e.g. "Invidious" for an invidious instance.
* @return service name or <code>null</code> if the name of the streamingservice should be used
*/
default String getServiceName() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.schabi.newpipe.extractor.instance;

/**
* Thrown when an {@link Instance} couldn't be validated.
*/
public class InstanceMetaDataFetchException extends RuntimeException {
public InstanceMetaDataFetchException(final String message) {
super(message);
}

public InstanceMetaDataFetchException(final String message, final Throwable cause) {
super(message, cause);
}

public InstanceMetaDataFetchException(final Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.schabi.newpipe.extractor.kiosk;

import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;

import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.StreamingService;
Expand All @@ -8,13 +10,13 @@
import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.localization.Localization;

import javax.annotation.Nullable;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
import javax.annotation.Nullable;

public class KioskList {

Expand All @@ -26,7 +28,8 @@ KioskExtractor createNewKiosk(StreamingService streamingService,
}

private final StreamingService service;
private final HashMap<String, KioskEntry> kioskList = new HashMap<>();
// Use a linked hash map to keep track of the order
private final HashMap<String, KioskEntry> kioskList = new LinkedHashMap<>();
private String defaultKiosk = null;

@Nullable
Expand All @@ -50,10 +53,9 @@ public KioskList(final StreamingService service) {

public void addKioskEntry(final KioskExtractorFactory extractorFactory,
final ListLinkHandlerFactory handlerFactory,
final String id)
throws Exception {
final String id) {
if (kioskList.get(id) != null) {
throw new Exception("Kiosk with type " + id + " already exists.");
throw new IllegalArgumentException("Kiosk with type " + id + " already exists.");
}
kioskList.put(id, new KioskEntry(extractorFactory, handlerFactory));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.schabi.newpipe.extractor.playlist;

import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;

import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
Expand All @@ -8,18 +10,23 @@

import javax.annotation.Nonnull;

import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;

public abstract class PlaylistExtractor extends ListExtractor<StreamInfoItem> {

public PlaylistExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
super(service, linkHandler);
}

public abstract String getUploaderUrl() throws ParsingException;

public abstract String getUploaderName() throws ParsingException;
public abstract String getUploaderAvatarUrl() throws ParsingException;
public abstract boolean isUploaderVerified() throws ParsingException;

public String getUploaderAvatarUrl() throws ParsingException {
return EMPTY_STRING;
}

public boolean isUploaderVerified() throws ParsingException {
return false;
}

public abstract long getStreamCount() throws ParsingException;

Expand Down
Loading