mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-28 16:00:33 +05:30
Fix compilation + Cleanup
This commit is contained in:
parent
4f16112d6d
commit
d718f50e34
@ -7,7 +7,9 @@ import org.schabi.newpipe.extractor.downloader.Request;
|
|||||||
import org.schabi.newpipe.extractor.downloader.Response;
|
import org.schabi.newpipe.extractor.downloader.Response;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UncheckedIOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -27,10 +29,11 @@ class MockDownloader extends Downloader {
|
|||||||
public MockDownloader(@Nonnull final String path) {
|
public MockDownloader(@Nonnull final String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.mocks = new HashMap<>();
|
this.mocks = new HashMap<>();
|
||||||
|
|
||||||
try (final var directoryStream = Files.newDirectoryStream(Paths.get(path),
|
try (final var directoryStream = Files.newDirectoryStream(Paths.get(path),
|
||||||
entry -> entry.getFileName().toString()
|
entry -> entry.getFileName().toString()
|
||||||
.startsWith(RecordingDownloader.FILE_NAME_PREFIX))) {
|
.startsWith(RecordingDownloader.FILE_NAME_PREFIX))) {
|
||||||
for (final var entry : directoryStream) {
|
for (final Path entry : directoryStream) {
|
||||||
try (final var reader = Files.newBufferedReader(entry)) {
|
try (final var reader = Files.newBufferedReader(entry)) {
|
||||||
final var response = new GsonBuilder()
|
final var response = new GsonBuilder()
|
||||||
.create()
|
.create()
|
||||||
@ -38,6 +41,8 @@ class MockDownloader extends Downloader {
|
|||||||
mocks.put(response.getRequest(), response.getResponse());
|
mocks.put(response.getRequest(), response.getResponse());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (final IOException ioe) {
|
||||||
|
throw new UncheckedIOException(ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -40,7 +41,7 @@ class RecordingDownloader extends Downloader {
|
|||||||
"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
|
"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
|
||||||
|
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
private final String path;
|
private final Path path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the folder described by {@code stringPath} if it does not exist.
|
* Creates the folder described by {@code stringPath} if it does not exist.
|
||||||
@ -48,20 +49,22 @@ class RecordingDownloader extends Downloader {
|
|||||||
* @param stringPath Path to the folder where the json files will be saved to.
|
* @param stringPath Path to the folder where the json files will be saved to.
|
||||||
*/
|
*/
|
||||||
public RecordingDownloader(final String stringPath) {
|
public RecordingDownloader(final String stringPath) {
|
||||||
this.path = stringPath;
|
this.path = Paths.get(stringPath);
|
||||||
final var path = Paths.get(stringPath);
|
|
||||||
if (Files.exists(path)) {
|
if (Files.exists(path)) {
|
||||||
try (final var directoryStream = Files.newDirectoryStream(path,
|
try (final var directoryStream = Files.newDirectoryStream(path,
|
||||||
entry -> entry.getFileName().toString()
|
entry -> entry.getFileName().toString()
|
||||||
.startsWith(RecordingDownloader.FILE_NAME_PREFIX))) {
|
.startsWith(RecordingDownloader.FILE_NAME_PREFIX))) {
|
||||||
for (final var entry : directoryStream) {
|
for (final Path entry : directoryStream) {
|
||||||
Files.delete(entry);
|
Files.delete(entry);
|
||||||
}
|
}
|
||||||
|
} catch (final IOException ioe) {
|
||||||
|
throw new UncheckedIOException(ioe);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(path);
|
Files.createDirectories(path);
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +83,7 @@ class RecordingDownloader extends Downloader {
|
|||||||
response.latestUrl()
|
response.latestUrl()
|
||||||
);
|
);
|
||||||
|
|
||||||
final var outputPath = Paths.get(path).resolve(FILE_NAME_PREFIX + index + ".json");
|
final Path outputPath = path.resolve(FILE_NAME_PREFIX + index + ".json");
|
||||||
index++;
|
index++;
|
||||||
try (final var writer = Files.newBufferedWriter(outputPath)) {
|
try (final var writer = Files.newBufferedWriter(outputPath)) {
|
||||||
new GsonBuilder()
|
new GsonBuilder()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user