Skip to content

Commit cadda5e

Browse files
Refactor PeerTube date parsing method
1 parent 6bc9d32 commit cadda5e

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeParsingHelper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.schabi.newpipe.extractor.Page;
1111
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
1212
import org.schabi.newpipe.extractor.exceptions.ParsingException;
13+
import org.schabi.newpipe.extractor.localization.DateWrapper;
1314
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeChannelInfoItemExtractor;
1415
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubePlaylistInfoItemExtractor;
1516
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeSepiaStreamInfoItemExtractor;
@@ -46,9 +47,10 @@ public static void validate(final JsonObject json) throws ContentNotAvailableExc
4647
}
4748
}
4849

49-
public static Instant parseInstantFrom(final String textualUploadDate) throws ParsingException {
50+
public static DateWrapper parseDateWrapper(final String textualUploadDate)
51+
throws ParsingException {
5052
try {
51-
return Instant.parse(textualUploadDate);
53+
return new DateWrapper(Instant.parse(textualUploadDate));
5254
} catch (final DateTimeParseException e) {
5355
throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e);
5456
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import static org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeCommentsExtractor.CHILDREN;
2525
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getAvatarsFromOwnerAccountOrVideoChannelObject;
26-
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.parseInstantFrom;
26+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.parseDateWrapper;
2727

2828
public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtractor {
2929
@Nonnull
@@ -73,7 +73,7 @@ public String getTextualUploadDate() throws ParsingException {
7373

7474
@Override
7575
public DateWrapper getUploadDate() throws ParsingException {
76-
return new DateWrapper(parseInstantFrom(getTextualUploadDate()));
76+
return parseDateWrapper(getTextualUploadDate());
7777
}
7878

7979
@Nonnull

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.schabi.newpipe.extractor.services.peertube.extractors;
22

3-
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getAvatarsFromOwnerAccountOrVideoChannelObject;
4-
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getThumbnailsFromPlaylistOrVideoItem;
3+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.*;
54
import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE;
65
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
76

@@ -80,12 +79,7 @@ public String getTextualUploadDate() throws ParsingException {
8079
@Override
8180
public DateWrapper getUploadDate() throws ParsingException {
8281
final String textualUploadDate = getTextualUploadDate();
83-
84-
if (textualUploadDate == null) {
85-
return null;
86-
}
87-
88-
return new DateWrapper(PeertubeParsingHelper.parseInstantFrom(textualUploadDate));
82+
return textualUploadDate == null ? null : parseDateWrapper(textualUploadDate);
8983
}
9084

9185
@Nonnull

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamInfoItemExtractor.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getAvatarsFromOwnerAccountOrVideoChannelObject;
1616
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getThumbnailsFromPlaylistOrVideoItem;
17-
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.parseInstantFrom;
17+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.parseDateWrapper;
1818

1919
public class PeertubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
2020

@@ -86,12 +86,7 @@ public String getTextualUploadDate() throws ParsingException {
8686
@Override
8787
public DateWrapper getUploadDate() throws ParsingException {
8888
final String textualUploadDate = getTextualUploadDate();
89-
90-
if (textualUploadDate == null) {
91-
return null;
92-
}
93-
94-
return new DateWrapper(parseInstantFrom(textualUploadDate));
89+
return textualUploadDate == null ? null : parseDateWrapper(textualUploadDate);
9590
}
9691

9792
@Override

0 commit comments

Comments
 (0)