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.
This commit is contained in:
XiangRongLin 2020-12-15 15:19:01 +01:00
parent 7c40fb8bf7
commit e6e8e39def
2 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,30 @@
package org.schabi.newpipe.downloader;
import org.schabi.newpipe.extractor.downloader.Downloader;
import java.io.IOException;
public class DownloaderFactory {
private final static DownloaderType DEFAULT_DOWNLOADER = DownloaderType.REAL;
public Downloader getDownloader(String path) throws IOException {
DownloaderType type;
try {
type = DownloaderType.valueOf(System.getProperty("downloader"));
} catch (Exception e) {
type = DEFAULT_DOWNLOADER;
}
switch (type) {
case REAL:
return DownloaderTestImpl.getInstance();
case MOCK:
return new MockDownloader(path);
case RECORDING:
return new RecordingDownloader(path);
default:
throw new UnsupportedOperationException("Unknown downloader type: " + type.toString());
}
}
}

View file

@ -0,0 +1,5 @@
package org.schabi.newpipe.downloader;
public enum DownloaderType {
REAL, MOCK, RECORDING
}