use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.
the class PodcastService method deleteEpisode.
/**
* Deletes the Podcast episode with the given ID.
*
* @param episodeId The Podcast episode ID.
* @param logicalDelete Whether to perform a logical delete by setting the
* episode status to {@link PodcastStatus#DELETED}.
*/
public void deleteEpisode(int episodeId, boolean logicalDelete) {
PodcastEpisode episode = podcastDao.getEpisode(episodeId);
if (episode == null) {
return;
}
// Delete file.
if (episode.getPath() != null) {
File file = new File(episode.getPath());
if (file.exists()) {
file.delete();
// TODO: Delete directory if empty?
}
}
if (logicalDelete) {
episode.setStatus(PodcastStatus.DELETED);
episode.setErrorMessage(null);
podcastDao.updateEpisode(episode);
} else {
podcastDao.deleteEpisode(episodeId);
}
}
use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.
the class PodcastService method getEpisodeByUrl.
private PodcastEpisode getEpisodeByUrl(String url) {
PodcastEpisode episode = podcastDao.getEpisodeByUrl(url);
if (episode == null) {
return null;
}
List<PodcastEpisode> episodes = Arrays.asList(episode);
episodes = filterAllowed(episodes);
addMediaFileIdToEpisodes(episodes);
return episodes.isEmpty() ? null : episodes.get(0);
}
use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.
the class PodcastService method doRefreshChannel.
@SuppressWarnings({ "unchecked" })
private void doRefreshChannel(PodcastChannel channel, boolean downloadEpisodes) {
InputStream in = null;
try (CloseableHttpClient client = HttpClients.createDefault()) {
channel.setStatus(PodcastStatus.DOWNLOADING);
channel.setErrorMessage(null);
podcastDao.updateChannel(channel);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(// 2 minutes
2 * 60 * 1000).setSocketTimeout(// 10 minutes
10 * 60 * 1000).build();
HttpGet method = new HttpGet(channel.getUrl());
method.setConfig(requestConfig);
try (CloseableHttpResponse response = client.execute(method)) {
in = response.getEntity().getContent();
Document document = new SAXBuilder().build(in);
Element channelElement = document.getRootElement().getChild("channel");
channel.setTitle(StringUtil.removeMarkup(channelElement.getChildTextTrim("title")));
channel.setDescription(StringUtil.removeMarkup(channelElement.getChildTextTrim("description")));
channel.setImageUrl(getChannelImageUrl(channelElement));
channel.setStatus(PodcastStatus.COMPLETED);
channel.setErrorMessage(null);
podcastDao.updateChannel(channel);
downloadImage(channel);
refreshEpisodes(channel, channelElement.getChildren("item"));
}
} catch (Exception x) {
LOG.warn("Failed to get/parse RSS file for Podcast channel " + channel.getUrl(), x);
channel.setStatus(PodcastStatus.ERROR);
channel.setErrorMessage(getErrorMessage(x));
podcastDao.updateChannel(channel);
} finally {
IOUtils.closeQuietly(in);
}
if (downloadEpisodes) {
for (final PodcastEpisode episode : getEpisodes(channel.getId())) {
if (episode.getStatus() == PodcastStatus.NEW && episode.getUrl() != null) {
downloadEpisode(episode);
}
}
}
}
use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.
the class PodcastService method deleteObsoleteEpisodes.
private synchronized void deleteObsoleteEpisodes(PodcastChannel channel) {
int episodeCount = settingsService.getPodcastEpisodeRetentionCount();
if (episodeCount == -1) {
return;
}
List<PodcastEpisode> episodes = getEpisodes(channel.getId());
// Don't do anything if other episodes of the same channel is currently downloading.
for (PodcastEpisode episode : episodes) {
if (episode.getStatus() == PodcastStatus.DOWNLOADING) {
return;
}
}
// Reverse array to get chronological order (oldest episodes first).
Collections.reverse(episodes);
int episodesToDelete = Math.max(0, episodes.size() - episodeCount);
for (int i = 0; i < episodesToDelete; i++) {
deleteEpisode(episodes.get(i).getId(), true);
LOG.info("Deleted old Podcast episode " + episodes.get(i).getUrl());
}
}
use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.
the class PodcastService method getEpisode.
public PodcastEpisode getEpisode(int episodeId, boolean includeDeleted) {
PodcastEpisode episode = podcastDao.getEpisode(episodeId);
if (episode == null) {
return null;
}
if (episode.getStatus() == PodcastStatus.DELETED && !includeDeleted) {
return null;
}
addMediaFileIdToEpisodes(Arrays.asList(episode));
return episode;
}
Aggregations