forked from TeamNewPipe/NewPipeExtractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* allows usage of YouTubeLike services, e.g. invidious * simplified some classes/code * Added support for invidious * Some credits go to @B0pol's PR TeamNewPipe#555 for that ;)
- Loading branch information
Showing
132 changed files
with
3,796 additions
and
1,619 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
extractor/src/main/java/org/schabi/newpipe/extractor/InstanceBasedStreamingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
extractor/src/main/java/org/schabi/newpipe/extractor/instance/AbstractInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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 Boolean valid = null; | ||
|
||
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; | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
extractor/src/main/java/org/schabi/newpipe/extractor/instance/Instance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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. | ||
* Use {@link #getUrlWithTrailingSlash()} if you want a trailing slash. | ||
* | ||
* @return base url | ||
*/ | ||
@Nonnull | ||
String getUrl(); | ||
|
||
default String getUrlWithTrailingSlash() { | ||
return 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; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...r/src/main/java/org/schabi/newpipe/extractor/instance/InstanceMetaDataFetchException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.schabi.newpipe.extractor.instance; | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.