Search in sources :

Example 31 with MediaFile

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

the class MediaFileTestCase method doTestGetDurationAsString.

private void doTestGetDurationAsString(int seconds, String expected) {
    MediaFile mediaFile = new MediaFile();
    mediaFile.setDurationSeconds(seconds);
    assertEquals("Error in getDurationString().", expected, mediaFile.getDurationString());
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile)

Example 32 with MediaFile

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

the class SetMusicFileInfoController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    String action = request.getParameter("action");
    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    if ("comment".equals(action)) {
        mediaFile.setComment(StringUtil.toHtml(request.getParameter("comment")));
        mediaFileService.updateMediaFile(mediaFile);
    }
    String url = "main.view?id=" + id;
    return new ModelAndView(new RedirectView(url));
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with MediaFile

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

the class ShareSettingsController method getShareInfos.

private List<ShareInfo> getShareInfos(HttpServletRequest request) {
    List<ShareInfo> result = new ArrayList<ShareInfo>();
    User user = securityService.getCurrentUser(request);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
    for (Share share : shareService.getSharesForUser(user)) {
        List<MediaFile> files = shareService.getSharedFiles(share.getId(), musicFolders);
        if (!files.isEmpty()) {
            MediaFile file = files.get(0);
            result.add(new ShareInfo(shareService.getShareUrl(request, share), share, file.isDirectory() ? file : mediaFileService.getParentOf(file)));
        }
    }
    return result;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) User(org.libresonic.player.domain.User) MusicFolder(org.libresonic.player.domain.MusicFolder) Share(org.libresonic.player.domain.Share)

Example 34 with MediaFile

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

the class NowPlayingController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Player player = playerService.getPlayer(request, response);
    List<TransferStatus> statuses = statusService.getStreamStatusesForPlayer(player);
    MediaFile current = statuses.isEmpty() ? null : mediaFileService.getMediaFile(statuses.get(0).getFile());
    MediaFile dir = current == null ? null : mediaFileService.getParentOf(current);
    String url;
    if (dir != null && !mediaFileService.isRoot(dir)) {
        url = "main.view?id=" + dir.getId();
    } else {
        url = "home.view";
    }
    return new ModelAndView(new RedirectView(url));
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Player(org.libresonic.player.domain.Player) TransferStatus(org.libresonic.player.domain.TransferStatus) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with MediaFile

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

the class PodcastController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String url = request.getRequestURL().toString();
    String username = securityService.getCurrentUsername(request);
    List<Playlist> playlists = playlistService.getReadablePlaylistsForUser(username);
    List<Podcast> podcasts = new ArrayList<>();
    for (Playlist playlist : playlists) {
        List<MediaFile> songs = playlistService.getFilesInPlaylist(playlist.getId());
        if (songs.isEmpty()) {
            continue;
        }
        long length = 0L;
        for (MediaFile song : songs) {
            length += song.getFileSize();
        }
        String publishDate = RSS_DATE_FORMAT.format(playlist.getCreated());
        // Resolve content type.
        String suffix = songs.get(0).getFormat();
        String type = StringUtil.getMimeType(suffix);
        String enclosureUrl = url + "/stream?playlist=" + playlist.getId();
        podcasts.add(new Podcast(playlist.getName(), publishDate, enclosureUrl, length, type));
    }
    Map<String, Object> map = new HashMap<>();
    map.put("url", url);
    map.put("podcasts", podcasts);
    return new ModelAndView("podcast", "model", map);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) ModelAndView(org.springframework.web.servlet.ModelAndView) Playlist(org.libresonic.player.domain.Playlist) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MediaFile (org.libresonic.player.domain.MediaFile)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ModelAndView (org.springframework.web.servlet.ModelAndView)8 File (java.io.File)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 MusicFolder (org.libresonic.player.domain.MusicFolder)5 Playlist (org.libresonic.player.domain.Playlist)5 Player (org.libresonic.player.domain.Player)4 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 RedirectView (org.springframework.web.servlet.view.RedirectView)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 Test (org.junit.Test)2 Share (org.libresonic.player.domain.Share)2 TransferStatus (org.libresonic.player.domain.TransferStatus)2