Search in sources :

Example 16 with PodcastEpisode

use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.

the class RESTController method getPodcasts.

@RequestMapping(value = "/rest/getPodcasts", method = { RequestMethod.GET, RequestMethod.POST })
public void getPodcasts(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    boolean includeEpisodes = getBooleanParameter(request, "includeEpisodes", true);
    Integer channelId = getIntParameter(request, "id");
    Podcasts result = new Podcasts();
    for (PodcastChannel channel : podcastService.getAllChannels()) {
        if (channelId == null || channelId.equals(channel.getId())) {
            org.libresonic.restapi.PodcastChannel c = new org.libresonic.restapi.PodcastChannel();
            result.getChannel().add(c);
            c.setId(String.valueOf(channel.getId()));
            c.setUrl(channel.getUrl());
            c.setStatus(PodcastStatus.valueOf(channel.getStatus().name()));
            c.setTitle(channel.getTitle());
            c.setDescription(channel.getDescription());
            c.setCoverArt(CoverArtController.PODCAST_COVERART_PREFIX + channel.getId());
            c.setOriginalImageUrl(channel.getImageUrl());
            c.setErrorMessage(channel.getErrorMessage());
            if (includeEpisodes) {
                List<PodcastEpisode> episodes = podcastService.getEpisodes(channel.getId());
                for (PodcastEpisode episode : episodes) {
                    c.getEpisode().add(createJaxbPodcastEpisode(player, username, episode));
                }
            }
        }
    }
    Response res = createResponse();
    res.setPodcasts(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : org.libresonic.restapi(org.libresonic.restapi) PodcastChannel(org.libresonic.player.domain.PodcastChannel) PodcastEpisode(org.libresonic.player.domain.PodcastEpisode) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with PodcastEpisode

use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.

the class RESTController method getNewestPodcasts.

@RequestMapping(value = "/rest/getNewestPodcasts", method = { RequestMethod.GET, RequestMethod.POST })
public void getNewestPodcasts(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    int count = getIntParameter(request, "count", 20);
    NewestPodcasts result = new NewestPodcasts();
    for (PodcastEpisode episode : podcastService.getNewestEpisodes(count)) {
        result.getEpisode().add(createJaxbPodcastEpisode(player, username, episode));
    }
    Response res = createResponse();
    res.setNewestPodcasts(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) PodcastEpisode(org.libresonic.player.domain.PodcastEpisode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with PodcastEpisode

use of org.libresonic.player.domain.PodcastEpisode in project libresonic by Libresonic.

the class RESTController method downloadPodcastEpisode.

@RequestMapping(value = "/rest/downloadPodcastEpisode", method = { RequestMethod.GET, RequestMethod.POST })
public void downloadPodcastEpisode(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    User user = securityService.getCurrentUser(request);
    if (!user.isPodcastRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to administrate podcasts.");
        return;
    }
    int id = getRequiredIntParameter(request, "id");
    PodcastEpisode episode = podcastService.getEpisode(id, true);
    if (episode == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Podcast episode " + id + " not found.");
        return;
    }
    podcastService.downloadEpisode(episode);
    writeEmptyResponse(request, response);
}
Also used : User(org.libresonic.player.domain.User) PodcastEpisode(org.libresonic.player.domain.PodcastEpisode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PodcastEpisode (org.libresonic.player.domain.PodcastEpisode)18 Test (org.junit.Test)6 Date (java.util.Date)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Element (org.jdom.Element)2 MediaFile (org.libresonic.player.domain.MediaFile)2 PodcastChannel (org.libresonic.player.domain.PodcastChannel)2 Predicate (com.google.common.base.Predicate)1 File (java.io.File)1 InputStream (java.io.InputStream)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 Document (org.jdom.Document)1 SAXBuilder (org.jdom.input.SAXBuilder)1 User (org.libresonic.player.domain.User)1 org.libresonic.restapi (org.libresonic.restapi)1