From 8755c25349c1497448acce64342a641ec07cfca0 Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Wed, 26 Dec 2018 11:08:39 +0530 Subject: [PATCH] format date of comment published. changed default instance --- .../services/peertube/PeertubeInstance.java | 2 +- .../PeertubeCommentsInfoItemExtractor.java | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeInstance.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeInstance.java index e08477509..2bedc07cf 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeInstance.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeInstance.java @@ -18,7 +18,7 @@ public class PeertubeInstance { private final String url; private String name; - public static final PeertubeInstance defaultInstance = new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"); + public static final PeertubeInstance defaultInstance = new PeertubeInstance("https://framatube.org", "FramaTube"); public PeertubeInstance(String url) throws IOException { this.url = url; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java index ea65aae3c..1e6df7708 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java @@ -1,5 +1,10 @@ package org.schabi.newpipe.extractor.services.peertube.extractors; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Locale; + import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -42,7 +47,8 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac @Override public String getPublishedTime() throws ParsingException { - return JsonUtils.getString(item, "createdAt"); + String date = JsonUtils.getString(item, "createdAt"); + return getFormattedDate(date); } @Override @@ -84,5 +90,15 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac String host = JsonUtils.getString(item, "account.host"); return PeertubeChannelLinkHandlerFactory.getInstance().fromId(name + "@" + host).getUrl(); } + + private String getFormattedDate(String date) { + DateFormat sourceDf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + DateFormat targetDf = new SimpleDateFormat("dd-MM-yyyy hh:mm a", Locale.ENGLISH); + try { + return targetDf.format(sourceDf.parse(date)); + } catch (ParseException e) { + return date; + } + } }