Search in sources :

Example 6 with MediaFile

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

the class MultiService method getTopSongs.

private List<TopSong> getTopSongs(MediaFile mediaFile, int limit) {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    String username = securityService.getCurrentUsername(request);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<TopSong> result = new ArrayList<TopSong>();
    List<MediaFile> files = lastFmService.getTopSongs(mediaFile, limit, musicFolders);
    mediaFileService.populateStarredDate(files, username);
    for (MediaFile file : files) {
        result.add(new TopSong(file.getId(), file.getTitle(), file.getArtist(), file.getAlbumName(), file.getDurationString(), file.getStarredDate() != null));
    }
    return result;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaFile(org.libresonic.player.domain.MediaFile) ArrayList(java.util.ArrayList) MusicFolder(org.libresonic.player.domain.MusicFolder)

Example 7 with MediaFile

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

the class MultiService method getArtistInfo.

public ArtistInfo getArtistInfo(int mediaFileId, int maxSimilarArtists, int maxTopSongs) {
    MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId);
    List<SimilarArtist> similarArtists = getSimilarArtists(mediaFileId, maxSimilarArtists);
    ArtistBio artistBio = lastFmService.getArtistBio(mediaFile);
    List<TopSong> topSongs = getTopSongs(mediaFile, maxTopSongs);
    return new ArtistInfo(similarArtists, artistBio, topSongs);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) ArtistBio(org.libresonic.player.domain.ArtistBio)

Example 8 with MediaFile

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

the class PlaylistService method createPlaylistForStarredSongs.

public int createPlaylistForStarredSongs() {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    Locale locale = localeResolver.resolveLocale(request);
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale);
    Date now = new Date();
    Playlist playlist = new Playlist();
    String username = securityService.getCurrentUsername(request);
    playlist.setUsername(username);
    playlist.setCreated(now);
    playlist.setChanged(now);
    playlist.setShared(false);
    ResourceBundle bundle = ResourceBundle.getBundle("org.libresonic.player.i18n.ResourceBundle", locale);
    playlist.setName(bundle.getString("top.starred") + " " + dateFormat.format(now));
    playlistService.createPlaylist(playlist);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> songs = mediaFileDao.getStarredFiles(0, Integer.MAX_VALUE, username, musicFolders);
    playlistService.setFilesInPlaylist(playlist.getId(), songs);
    return playlist.getId();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaFile(org.libresonic.player.domain.MediaFile) Playlist(org.libresonic.player.domain.Playlist) DateFormat(java.text.DateFormat) MusicFolder(org.libresonic.player.domain.MusicFolder)

Example 9 with MediaFile

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

the class PlaylistService method appendToPlaylist.

public void appendToPlaylist(int playlistId, List<Integer> mediaFileIds) {
    List<MediaFile> files = playlistService.getFilesInPlaylist(playlistId, true);
    for (Integer mediaFileId : mediaFileIds) {
        MediaFile file = mediaFileService.getMediaFile(mediaFileId);
        if (file != null) {
            files.add(file);
        }
    }
    playlistService.setFilesInPlaylist(playlistId, files);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile)

Example 10 with MediaFile

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

the class PlaylistService method down.

public PlaylistInfo down(int id, int index) {
    List<MediaFile> files = playlistService.getFilesInPlaylist(id, true);
    if (index < files.size() - 1) {
        MediaFile file = files.remove(index);
        files.add(index + 1, file);
        playlistService.setFilesInPlaylist(id, files);
    }
    return getPlaylist(id);
}
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