2020-12-15 15:19:01 +01:00
|
|
|
package org.schabi.newpipe.downloader;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class DownloaderFactory {
|
|
|
|
|
2021-01-10 20:27:34 +01:00
|
|
|
public final static String RESOURCE_PATH = "src/test/resources/org/schabi/newpipe/extractor/";
|
|
|
|
|
2020-12-15 15:19:01 +01:00
|
|
|
private final static DownloaderType DEFAULT_DOWNLOADER = DownloaderType.REAL;
|
|
|
|
|
2021-01-10 20:39:22 +01:00
|
|
|
/**
|
2021-01-12 09:37:48 +01:00
|
|
|
* <p>
|
|
|
|
* Returns a implementation of a downloader.
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* If the system property "downloader" is set and is one of {@link DownloaderType},
|
|
|
|
* then a downloader of that type is returned.
|
|
|
|
* It can be passed in with gradle by adding the argument -Ddownloader=abcd,
|
|
|
|
* where abcd is one of {@link DownloaderType}
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* Otherwise it falls back to {@link DownloaderFactory#DEFAULT_DOWNLOADER}.
|
|
|
|
* Change this during development on the local machine to use a different downloader.
|
|
|
|
* </p>
|
|
|
|
*
|
2021-01-10 20:39:22 +01:00
|
|
|
* @param path The path to the folder where mocks are saved/retrieved.
|
|
|
|
* Preferably starting with {@link DownloaderFactory#RESOURCE_PATH}
|
|
|
|
*/
|
2020-12-15 15:19:01 +01:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|