Skip to content

Commit e6e8e39

Browse files
committed
Add DownloaderFactory to return a specific downloader based on 2 variables.
If the system property 'downloader' is set that use that specific downloader. This is used from gradle by appending `-Ddownloader=ABCD to the command. ABCD is one of DownloaderType. The other variable is the static property `DEFAULT_DOWNLOADER` in DownloaderFactory, which can be easily changed as needed inside the IDE according to development needs`. Normal workflow would be to first use the recording downloader and afterwards only use mocks, if the requests are always staying the same.
1 parent 7c40fb8 commit e6e8e39

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.schabi.newpipe.downloader;
2+
3+
import org.schabi.newpipe.extractor.downloader.Downloader;
4+
5+
import java.io.IOException;
6+
7+
public class DownloaderFactory {
8+
9+
private final static DownloaderType DEFAULT_DOWNLOADER = DownloaderType.REAL;
10+
11+
public Downloader getDownloader(String path) throws IOException {
12+
DownloaderType type;
13+
try {
14+
type = DownloaderType.valueOf(System.getProperty("downloader"));
15+
} catch (Exception e) {
16+
type = DEFAULT_DOWNLOADER;
17+
}
18+
19+
switch (type) {
20+
case REAL:
21+
return DownloaderTestImpl.getInstance();
22+
case MOCK:
23+
return new MockDownloader(path);
24+
case RECORDING:
25+
return new RecordingDownloader(path);
26+
default:
27+
throw new UnsupportedOperationException("Unknown downloader type: " + type.toString());
28+
}
29+
}
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.schabi.newpipe.downloader;
2+
3+
public enum DownloaderType {
4+
REAL, MOCK, RECORDING
5+
}

0 commit comments

Comments
 (0)