Optionally parse podcast episode duration in seconds to [hh:]mm:ss

master
Carlos Galindo 6 years ago
parent 8ba0bc88f0
commit f78b108939
No known key found for this signature in database
GPG Key ID: 83E68706DEE119A3
  1. 15
      airsonic-main/src/main/java/org/airsonic/player/service/PodcastService.java

@ -422,7 +422,7 @@ public class PodcastService {
for (Element episodeElement : episodeElements) { for (Element episodeElement : episodeElements) {
String title = episodeElement.getChildTextTrim("title"); String title = episodeElement.getChildTextTrim("title");
String duration = getITunesElement(episodeElement, "duration"); String duration = formatDuration(getITunesElement(episodeElement, "duration"));
String description = episodeElement.getChildTextTrim("description"); String description = episodeElement.getChildTextTrim("description");
if (StringUtils.isBlank(description)) { if (StringUtils.isBlank(description)) {
description = getITunesElement(episodeElement, "summary"); description = getITunesElement(episodeElement, "summary");
@ -502,6 +502,19 @@ public class PodcastService {
return null; 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) { private String getITunesElement(Element element, String childName) {
for (Namespace ns : ITUNES_NAMESPACES) { for (Namespace ns : ITUNES_NAMESPACES) {
String value = element.getChildTextTrim(childName, ns); String value = element.getChildTextTrim(childName, ns);

Loading…
Cancel
Save