use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.
the class PodcastService method refreshEpisodes.
private void refreshEpisodes(PodcastChannel channel, List<Element> episodeElements) {
List<PodcastEpisode> episodes = new ArrayList<PodcastEpisode>();
for (Element episodeElement : episodeElements) {
String title = episodeElement.getChildTextTrim("title");
String duration = getITunesElement(episodeElement, "duration");
String description = episodeElement.getChildTextTrim("description");
if (StringUtils.isBlank(description)) {
description = getITunesElement(episodeElement, "summary");
}
title = StringUtil.removeMarkup(title);
description = StringUtil.removeMarkup(description);
Element enclosure = episodeElement.getChild("enclosure");
if (enclosure == null) {
LOG.info("No enclosure found for episode " + title);
continue;
}
String url = enclosure.getAttributeValue("url");
url = sanitizeUrl(url);
if (url == null) {
LOG.info("No enclosure URL found for episode " + title);
continue;
}
if (getEpisodeByUrl(url) == null) {
Long length = null;
try {
length = new Long(enclosure.getAttributeValue("length"));
} catch (Exception x) {
LOG.warn("Failed to parse enclosure length.", x);
}
Date date = parseDate(episodeElement.getChildTextTrim("pubDate"));
PodcastEpisode episode = new PodcastEpisode(null, channel.getId(), url, null, title, description, date, duration, length, 0L, PodcastStatus.NEW, null);
episodes.add(episode);
LOG.info("Created Podcast episode " + title);
}
}
// Sort episode in reverse chronological order (newest first)
Collections.sort(episodes, new Comparator<PodcastEpisode>() {
public int compare(PodcastEpisode a, PodcastEpisode b) {
long timeA = a.getPublishDate() == null ? 0L : a.getPublishDate().getTime();
long timeB = b.getPublishDate() == null ? 0L : b.getPublishDate().getTime();
if (timeA < timeB) {
return 1;
}
if (timeA > timeB) {
return -1;
}
return 0;
}
});
// Create episodes in database, skipping the proper number of episodes.
int downloadCount = settingsService.getPodcastEpisodeDownloadCount();
if (downloadCount == -1) {
downloadCount = Integer.MAX_VALUE;
}
for (int i = 0; i < episodes.size(); i++) {
PodcastEpisode episode = episodes.get(i);
if (i >= downloadCount) {
episode.setStatus(PodcastStatus.SKIPPED);
}
podcastDao.createEpisode(episode);
}
}
use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.
the class PodcastService method init.
public synchronized void init() {
try {
// Clean up partial downloads.
for (PodcastChannel channel : getAllChannels()) {
for (PodcastEpisode episode : getEpisodes(channel.getId())) {
if (episode.getStatus() == PodcastStatus.DOWNLOADING) {
deleteEpisode(episode.getId(), false);
LOG.info("Deleted Podcast episode '" + episode.getTitle() + "' since download was interrupted.");
}
}
}
schedule();
} catch (Throwable x) {
LOG.error("Failed to initialize PodcastService: " + x, x);
}
}
use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.
the class PodcastDaoTestCase method testGetEpisodes.
@Test
public void testGetEpisodes() {
int channelId = createChannel();
PodcastEpisode a = new PodcastEpisode(null, channelId, "a", null, null, null, new Date(3000), null, null, null, PodcastStatus.NEW, null);
PodcastEpisode b = new PodcastEpisode(null, channelId, "b", null, null, null, new Date(1000), null, null, null, PodcastStatus.NEW, "error");
PodcastEpisode c = new PodcastEpisode(null, channelId, "c", null, null, null, new Date(2000), null, null, null, PodcastStatus.NEW, null);
PodcastEpisode d = new PodcastEpisode(null, channelId, "c", null, null, null, null, null, null, null, PodcastStatus.NEW, "");
podcastDao.createEpisode(a);
podcastDao.createEpisode(b);
podcastDao.createEpisode(c);
podcastDao.createEpisode(d);
List<PodcastEpisode> episodes = podcastDao.getEpisodes(channelId);
assertEquals("Error in getEpisodes().", 4, episodes.size());
assertEpisodeEquals(a, episodes.get(0));
assertEpisodeEquals(c, episodes.get(1));
assertEpisodeEquals(b, episodes.get(2));
assertEpisodeEquals(d, episodes.get(3));
}
use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.
the class PodcastDaoTestCase method testGetEpisode.
@Test
public void testGetEpisode() {
assertNull("Error in getEpisode()", podcastDao.getEpisode(23));
int channelId = createChannel();
PodcastEpisode episode = new PodcastEpisode(null, channelId, "http://bar", "path", "title", "description", new Date(), "12:34", 3276213L, 2341234L, PodcastStatus.NEW, "error");
podcastDao.createEpisode(episode);
int episodeId = podcastDao.getEpisodes(channelId).get(0).getId();
PodcastEpisode newEpisode = podcastDao.getEpisode(episodeId);
assertEpisodeEquals(episode, newEpisode);
}
use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.
the class PodcastDaoTestCase method testDeleteEpisode.
@Test
public void testDeleteEpisode() {
int channelId = createChannel();
assertEquals("Wrong number of episodes.", 0, podcastDao.getEpisodes(channelId).size());
PodcastEpisode episode = new PodcastEpisode(null, channelId, "http://bar", null, null, null, null, null, null, null, PodcastStatus.NEW, null);
podcastDao.createEpisode(episode);
assertEquals("Wrong number of episodes.", 1, podcastDao.getEpisodes(channelId).size());
podcastDao.createEpisode(episode);
assertEquals("Wrong number of episodes.", 2, podcastDao.getEpisodes(channelId).size());
podcastDao.deleteEpisode(podcastDao.getEpisodes(channelId).get(0).getId());
assertEquals("Wrong number of episodes.", 1, podcastDao.getEpisodes(channelId).size());
podcastDao.deleteEpisode(podcastDao.getEpisodes(channelId).get(0).getId());
assertEquals("Wrong number of episodes.", 0, podcastDao.getEpisodes(channelId).size());
}
Aggregations