Search in sources :

Example 26 with MediaFile

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

the class PlaylistService method getFilesInPlaylist.

public List<MediaFile> getFilesInPlaylist(int id, boolean includeNotPresent) {
    List<MediaFile> files = mediaFileDao.getFilesInPlaylist(id);
    if (includeNotPresent) {
        return files;
    }
    List<MediaFile> presentFiles = new ArrayList<MediaFile>(files.size());
    for (MediaFile file : files) {
        if (file.isPresent()) {
            presentFiles.add(file);
        }
    }
    return presentFiles;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile)

Example 27 with MediaFile

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

the class PodcastService method getNewestEpisodes.

/**
     * Returns the N newest episodes.
     *
     * @return Possibly empty list of the newest Podcast episodes, sorted in
     *         reverse chronological order (newest episode first).
     */
public List<PodcastEpisode> getNewestEpisodes(int count) {
    List<PodcastEpisode> episodes = addMediaFileIdToEpisodes(podcastDao.getNewestEpisodes(count));
    return Lists.newArrayList(Iterables.filter(episodes, new Predicate<PodcastEpisode>() {

        @Override
        public boolean apply(PodcastEpisode episode) {
            Integer mediaFileId = episode.getMediaFileId();
            if (mediaFileId == null) {
                return false;
            }
            MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId);
            return mediaFile != null && mediaFile.isPresent();
        }
    }));
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) PodcastEpisode(org.libresonic.player.domain.PodcastEpisode) Predicate(com.google.common.base.Predicate)

Example 28 with MediaFile

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

the class SonosService method reorderContainer.

@Override
public ReorderContainerResult reorderContainer(String id, String from, int to, String updateId) {
    if (id.startsWith(ID_PLAYLIST_PREFIX)) {
        int playlistId = Integer.parseInt(id.replace(ID_PLAYLIST_PREFIX, ""));
        Playlist playlist = playlistService.getPlaylist(playlistId);
        if (playlist != null && playlist.getUsername().equals(getUsername())) {
            SortedMap<Integer, MediaFile> indexToSong = new ConcurrentSkipListMap<Integer, MediaFile>();
            List<MediaFile> songs = playlistService.getFilesInPlaylist(playlistId);
            for (int i = 0; i < songs.size(); i++) {
                indexToSong.put(i, songs.get(i));
            }
            List<MediaFile> movedSongs = new ArrayList<MediaFile>();
            for (Integer i : parsePlaylistIndices(from)) {
                movedSongs.add(indexToSong.remove(i));
            }
            List<MediaFile> updatedSongs = new ArrayList<MediaFile>();
            updatedSongs.addAll(indexToSong.headMap(to).values());
            updatedSongs.addAll(movedSongs);
            updatedSongs.addAll(indexToSong.tailMap(to).values());
            playlistService.setFilesInPlaylist(playlistId, updatedSongs);
        }
    }
    return new ReorderContainerResult();
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Playlist(org.libresonic.player.domain.Playlist) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 29 with MediaFile

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

the class SonosService method removeFromContainer.

@Override
public RemoveFromContainerResult removeFromContainer(String id, String indices, String updateId) {
    if (id.startsWith(ID_PLAYLIST_PREFIX)) {
        int playlistId = Integer.parseInt(id.replace(ID_PLAYLIST_PREFIX, ""));
        Playlist playlist = playlistService.getPlaylist(playlistId);
        if (playlist != null && playlist.getUsername().equals(getUsername())) {
            SortedSet<Integer> indicesToRemove = parsePlaylistIndices(indices);
            List<MediaFile> songs = playlistService.getFilesInPlaylist(playlistId);
            List<MediaFile> updatedSongs = new ArrayList<MediaFile>();
            for (int i = 0; i < songs.size(); i++) {
                if (!indicesToRemove.contains(i)) {
                    updatedSongs.add(songs.get(i));
                }
            }
            playlistService.setFilesInPlaylist(playlistId, updatedSongs);
        }
    }
    return new RemoveFromContainerResult();
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Playlist(org.libresonic.player.domain.Playlist)

Example 30 with MediaFile

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

the class SonosService method getExtendedMetadata.

@Override
public GetExtendedMetadataResponse getExtendedMetadata(GetExtendedMetadata parameters) {
    LOG.debug("getExtendedMetadata: " + parameters.getId());
    int id = Integer.parseInt(parameters.getId());
    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    AbstractMedia abstractMedia = sonosHelper.forMediaFile(mediaFile, getUsername(), getRequest());
    ExtendedMetadata extendedMetadata = new ExtendedMetadata();
    if (abstractMedia instanceof MediaCollection) {
        extendedMetadata.setMediaCollection((MediaCollection) abstractMedia);
    } else {
        extendedMetadata.setMediaMetadata((MediaMetadata) abstractMedia);
    }
    RelatedBrowse relatedBrowse = new RelatedBrowse();
    relatedBrowse.setType("RELATED_ARTISTS");
    relatedBrowse.setId(ID_SIMILAR_ARTISTS_PREFIX + id);
    extendedMetadata.getRelatedBrowse().add(relatedBrowse);
    GetExtendedMetadataResponse response = new GetExtendedMetadataResponse();
    response.setGetExtendedMetadataResult(extendedMetadata);
    return response;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile)

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