kopia lustrzana https://github.com/TeamNewPipe/NewPipeExtractor
Avoid potential NPEs in Soundcloud extractors
rodzic
59e78c2ba4
commit
f38b72ce7d
|
@ -23,6 +23,7 @@ import org.schabi.newpipe.extractor.downloader.Response;
|
|||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelInfoItemExtractor;
|
||||
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudPlaylistInfoItemExtractor;
|
||||
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudLikesInfoItemExtractor;
|
||||
|
@ -39,8 +40,7 @@ import javax.annotation.Nullable;
|
|||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.Instant;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -133,18 +133,16 @@ public final class SoundcloudParsingHelper {
|
|||
throw new ExtractionException("Couldn't extract client id");
|
||||
}
|
||||
|
||||
public static OffsetDateTime parseDateFrom(final String textualUploadDate)
|
||||
@Nullable
|
||||
public static DateWrapper parseDateFrom(@Nullable final String uploadDate)
|
||||
throws ParsingException {
|
||||
if (uploadDate == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return OffsetDateTime.parse(textualUploadDate);
|
||||
} catch (final DateTimeParseException e1) {
|
||||
try {
|
||||
return OffsetDateTime.parse(textualUploadDate, DateTimeFormatter
|
||||
.ofPattern("yyyy/MM/dd HH:mm:ss +0000"));
|
||||
} catch (final DateTimeParseException e2) {
|
||||
throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\""
|
||||
+ ", " + e1.getMessage(), e2);
|
||||
}
|
||||
return new DateWrapper(Instant.parse(uploadDate));
|
||||
} catch (final DateTimeParseException e) {
|
||||
throw new ParsingException("Could not parse date: \"" + uploadDate + "\"", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class SoundcloudCommentsInfoItemExtractor implements CommentsInfoItemExtr
|
|||
@Nullable
|
||||
@Override
|
||||
public DateWrapper getUploadDate() throws ParsingException {
|
||||
return new DateWrapper(parseDateFrom(getTextualUploadDate()));
|
||||
return parseDateFrom(getTextualUploadDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -88,18 +88,16 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
|
|||
return track.getString("title");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTextualUploadDate() {
|
||||
return track.getString("created_at")
|
||||
.replace("T", " ")
|
||||
.replace("Z", "");
|
||||
return track.getString("created_at");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Nullable
|
||||
@Override
|
||||
public DateWrapper getUploadDate() throws ParsingException {
|
||||
return new DateWrapper(parseDateFrom(track.getString("created_at")));
|
||||
return parseDateFrom(getTextualUploadDate());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -68,7 +68,7 @@ public class SoundcloudStreamInfoItemExtractor implements StreamInfoItemExtracto
|
|||
|
||||
@Override
|
||||
public DateWrapper getUploadDate() throws ParsingException {
|
||||
return new DateWrapper(parseDateFrom(getTextualUploadDate()));
|
||||
return parseDateFrom(getTextualUploadDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -63,7 +63,7 @@ public class SoundcloudStreamExtractorTest {
|
|||
@Override public long expectedTimestamp() { return TIMESTAMP; }
|
||||
@Override public long expectedViewCountAtLeast() { return 43000; }
|
||||
@Nullable @Override public String expectedUploadDate() { return "2019-05-16 16:28:45.000"; }
|
||||
@Nullable @Override public String expectedTextualUploadDate() { return "2019-05-16 16:28:45"; }
|
||||
@Nullable @Override public String expectedTextualUploadDate() { return "2019-05-16T16:28:45Z"; }
|
||||
@Override public long expectedLikeCountAtLeast() { return 600; }
|
||||
@Override public long expectedDislikeCountAtLeast() { return -1; }
|
||||
@Override public boolean expectedHasAudioStreams() { return false; }
|
||||
|
@ -127,7 +127,7 @@ public class SoundcloudStreamExtractorTest {
|
|||
@Override public long expectedTimestamp() { return TIMESTAMP; }
|
||||
@Override public long expectedViewCountAtLeast() { return 386000; }
|
||||
@Nullable @Override public String expectedUploadDate() { return "2016-11-11 01:16:37.000"; }
|
||||
@Nullable @Override public String expectedTextualUploadDate() { return "2016-11-11 01:16:37"; }
|
||||
@Nullable @Override public String expectedTextualUploadDate() { return "2016-11-11T01:16:37Z"; }
|
||||
@Override public long expectedLikeCountAtLeast() { return 7350; }
|
||||
@Override public long expectedDislikeCountAtLeast() { return -1; }
|
||||
@Override public boolean expectedHasAudioStreams() { return false; }
|
||||
|
@ -168,7 +168,7 @@ public class SoundcloudStreamExtractorTest {
|
|||
@Override public long expectedTimestamp() { return TIMESTAMP; }
|
||||
@Override public long expectedViewCountAtLeast() { return 15000; }
|
||||
@Nullable @Override public String expectedUploadDate() { return "2022-10-03 18:49:49.000"; }
|
||||
@Nullable @Override public String expectedTextualUploadDate() { return "2022-10-03 18:49:49"; }
|
||||
@Nullable @Override public String expectedTextualUploadDate() { return "2022-10-03T18:49:49Z"; }
|
||||
@Override public long expectedLikeCountAtLeast() { return 10; }
|
||||
@Override public long expectedDislikeCountAtLeast() { return -1; }
|
||||
@Override public boolean expectedHasRelatedItems() { return false; }
|
||||
|
|
Ładowanie…
Reference in New Issue