Skip to content

Commit c1d39f6

Browse files
authored
Merge branch 'dev' into yt-webm-opus
2 parents 3c6e93c + 0c6e2c8 commit c1d39f6

280 files changed

Lines changed: 5292 additions & 3462 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ If you're using Gradle, you could add NewPipe Extractor as a dependency with the
1313
1. Add `maven { url 'https://jitpack.io' }` to the `repositories` in your `build.gradle`.
1414
2. Add `compile 'com.github.TeamNewPipe:NewPipeExtractor:v0.11.0'`the `dependencies` in your `build.gradle`. Replace `v0.11.0` with the latest release.
1515

16+
### Testing changes
17+
18+
To test changes quickly you can build the library locally. Using the local Maven repository is a good approach, here's a gist of how to use it:
19+
20+
1. Add `mavenLocal()` in your project `repositories` list (usually as the first entry to give priority above the others).
21+
2. It's _recommended_ that you change the `version` of this library (e.g. `LOCAL_SNAPSHOT`).
22+
3. Run gradle's `ìnstall` task to deploy this library to your local repository (using the wrapper, present in the root of this project: `./gradlew install`)
23+
4. Change the dependency version used in your project to match the one you chose in step 2 (`implementation 'com.github.TeamNewPipe:NewPipeExtractor:LOCAL_SNAPSHOT'`)
24+
25+
> Tip for Android Studio users: After you make changes and run the `install` task, use the menu option `File → "Sync with File System"` to refresh the library in your project.
26+
1627
## Supported sites
1728

1829
The following sites are currently supported:

build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
allprojects {
22
apply plugin: 'java-library'
3+
apply plugin: 'maven'
4+
35
sourceCompatibility = 1.7
46
targetCompatibility = 1.7
57

68
version 'v0.13.0'
9+
group 'com.github.TeamNewPipe'
710

811
repositories {
912
jcenter()
1013
}
1114
}
1215

16+
dependencies {
17+
implementation project(':extractor')
18+
implementation project(':timeago-parser')
19+
}
20+
1321
subprojects {
1422
task sourcesJar(type: Jar, dependsOn: classes) {
1523
classifier = 'sources'

extractor/.attach_pid31246

Whitespace-only changes.

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

Lines changed: 0 additions & 44 deletions
This file was deleted.

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

Lines changed: 0 additions & 37 deletions
This file was deleted.

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

Lines changed: 0 additions & 70 deletions
This file was deleted.

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.schabi.newpipe.extractor;
22

3+
import org.schabi.newpipe.extractor.downloader.Downloader;
34
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
45
import org.schabi.newpipe.extractor.exceptions.ParsingException;
56
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
6-
import org.schabi.newpipe.extractor.utils.Localization;
7+
import org.schabi.newpipe.extractor.localization.ContentCountry;
8+
import org.schabi.newpipe.extractor.localization.Localization;
9+
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
710

811
import javax.annotation.Nonnull;
912
import javax.annotation.Nullable;
@@ -16,21 +19,20 @@ public abstract class Extractor{
1619
* Useful for getting other things from a service (like the url handlers for cleaning/accepting/get id from urls).
1720
*/
1821
private final StreamingService service;
19-
2022
private final LinkHandler linkHandler;
21-
private final Localization localization;
2223

23-
@Nullable
24+
@Nullable private Localization forcedLocalization = null;
25+
@Nullable private ContentCountry forcedContentCountry = null;
26+
2427
private boolean pageFetched = false;
2528
private final Downloader downloader;
2629

27-
public Extractor(final StreamingService service, final LinkHandler linkHandler, final Localization localization) {
30+
public Extractor(final StreamingService service, final LinkHandler linkHandler) {
2831
if(service == null) throw new NullPointerException("service is null");
2932
if(linkHandler == null) throw new NullPointerException("LinkHandler is null");
3033
this.service = service;
3134
this.linkHandler = linkHandler;
3235
this.downloader = NewPipe.getDownloader();
33-
this.localization = localization;
3436
if(downloader == null) throw new NullPointerException("downloader is null");
3537
}
3638

@@ -105,8 +107,30 @@ public Downloader getDownloader() {
105107
return downloader;
106108
}
107109

110+
/*//////////////////////////////////////////////////////////////////////////
111+
// Localization
112+
//////////////////////////////////////////////////////////////////////////*/
113+
114+
public void forceLocalization(Localization localization) {
115+
this.forcedLocalization = localization;
116+
}
117+
118+
public void forceContentCountry(ContentCountry contentCountry) {
119+
this.forcedContentCountry = contentCountry;
120+
}
121+
122+
@Nonnull
123+
public Localization getExtractorLocalization() {
124+
return forcedLocalization == null ? getService().getLocalization() : forcedLocalization;
125+
}
126+
127+
@Nonnull
128+
public ContentCountry getExtractorContentCountry() {
129+
return forcedContentCountry == null ? getService().getContentCountry() : forcedContentCountry;
130+
}
131+
108132
@Nonnull
109-
public Localization getLocalization() {
110-
return localization;
133+
public TimeAgoParser getTimeAgoParser() {
134+
return getService().getTimeAgoParser(getExtractorLocalization());
111135
}
112136
}

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

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

33
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
44
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
5-
import org.schabi.newpipe.extractor.utils.Localization;
65

76
import javax.annotation.Nonnull;
87
import java.io.IOException;
@@ -14,8 +13,8 @@
1413
*/
1514
public abstract class ListExtractor<R extends InfoItem> extends Extractor {
1615

17-
public ListExtractor(StreamingService service, ListLinkHandler linkHandler, Localization localization) {
18-
super(service, linkHandler, localization);
16+
public ListExtractor(StreamingService service, ListLinkHandler linkHandler) {
17+
super(service, linkHandler);
1918
}
2019

2120
/**

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

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,42 @@
2020
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2121
*/
2222

23+
import org.schabi.newpipe.extractor.downloader.Downloader;
2324
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
24-
import org.schabi.newpipe.extractor.utils.Localization;
25+
import org.schabi.newpipe.extractor.localization.ContentCountry;
26+
import org.schabi.newpipe.extractor.localization.Localization;
2527

28+
import javax.annotation.Nonnull;
29+
import javax.annotation.Nullable;
2630
import java.util.List;
2731

2832
/**
2933
* Provides access to streaming services supported by NewPipe.
3034
*/
3135
public class NewPipe {
32-
private static Downloader downloader = null;
33-
private static Localization localization = null;
36+
private static Downloader downloader;
37+
private static Localization preferredLocalization;
38+
private static ContentCountry preferredContentCountry;
3439

3540
private NewPipe() {
3641
}
3742

43+
public static void init(Downloader d) {
44+
downloader = d;
45+
preferredLocalization = Localization.DEFAULT;
46+
preferredContentCountry = ContentCountry.DEFAULT;
47+
}
48+
3849
public static void init(Downloader d, Localization l) {
3950
downloader = d;
40-
localization = l;
51+
preferredLocalization = l;
52+
preferredContentCountry = l.getCountryCode().isEmpty() ? ContentCountry.DEFAULT : new ContentCountry(l.getCountryCode());
53+
}
54+
55+
public static void init(Downloader d, Localization l, ContentCountry c) {
56+
downloader = d;
57+
preferredLocalization = l;
58+
preferredContentCountry = c;
4159
}
4260

4361
public static Downloader getDownloader() {
@@ -99,11 +117,41 @@ public static String getNameOfService(int id) {
99117
}
100118
}
101119

102-
public static void setLocalization(Localization localization) {
103-
NewPipe.localization = localization;
120+
/*//////////////////////////////////////////////////////////////////////////
121+
// Localization
122+
//////////////////////////////////////////////////////////////////////////*/
123+
124+
public static void setupLocalization(Localization preferredLocalization) {
125+
setupLocalization(preferredLocalization, null);
104126
}
105127

128+
public static void setupLocalization(Localization preferredLocalization, @Nullable ContentCountry preferredContentCountry) {
129+
NewPipe.preferredLocalization = preferredLocalization;
130+
131+
if (preferredContentCountry != null) {
132+
NewPipe.preferredContentCountry = preferredContentCountry;
133+
} else {
134+
NewPipe.preferredContentCountry = preferredLocalization.getCountryCode().isEmpty()
135+
? ContentCountry.DEFAULT
136+
: new ContentCountry(preferredLocalization.getCountryCode());
137+
}
138+
}
139+
140+
@Nonnull
106141
public static Localization getPreferredLocalization() {
107-
return localization;
142+
return preferredLocalization == null ? Localization.DEFAULT : preferredLocalization;
143+
}
144+
145+
public static void setPreferredLocalization(Localization preferredLocalization) {
146+
NewPipe.preferredLocalization = preferredLocalization;
147+
}
148+
149+
@Nonnull
150+
public static ContentCountry getPreferredContentCountry() {
151+
return preferredContentCountry == null ? ContentCountry.DEFAULT : preferredContentCountry;
152+
}
153+
154+
public static void setPreferredContentCountry(ContentCountry preferredContentCountry) {
155+
NewPipe.preferredContentCountry = preferredContentCountry;
108156
}
109157
}

0 commit comments

Comments
 (0)