From f78b10893909df383bd5db21b376667232735909 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Sun, 26 Aug 2018 16:32:22 +0200 Subject: [PATCH] Optionally parse podcast episode duration in seconds to [hh:]mm:ss --- .../airsonic/player/service/PodcastService.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/PodcastService.java b/airsonic-main/src/main/java/org/airsonic/player/service/PodcastService.java index c969cab4..d5fad1d6 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/PodcastService.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/PodcastService.java @@ -422,7 +422,7 @@ public class PodcastService { for (Element episodeElement : episodeElements) { String title = episodeElement.getChildTextTrim("title"); - String duration = getITunesElement(episodeElement, "duration"); + String duration = formatDuration(getITunesElement(episodeElement, "duration")); String description = episodeElement.getChildTextTrim("description"); if (StringUtils.isBlank(description)) { description = getITunesElement(episodeElement, "summary"); @@ -502,6 +502,19 @@ public class PodcastService { return null; } + private String formatDuration(String duration) { + if (duration == null) return null; + if (duration.matches("^\\d+$")) { + long seconds = Long.valueOf(duration); + if (seconds >= 3600) + return String.format("%02d:%02d:%02d", seconds / 3600, seconds / 60, seconds % 60); + else + return String.format("%02d:%02d", seconds / 60, seconds % 60); + } else { + return duration; + } + } + private String getITunesElement(Element element, String childName) { for (Namespace ns : ITUNES_NAMESPACES) { String value = element.getChildTextTrim(childName, ns);