Search in sources :

Example 6 with MusicFolder

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

the class RESTController method getTopSongs.

@RequestMapping(value = "/rest/getTopSongs", method = { RequestMethod.GET, RequestMethod.POST })
public void getTopSongs(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);
    String artist = getRequiredStringParameter(request, "artist");
    int count = getIntParameter(request, "count", 50);
    TopSongs result = new TopSongs();
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> topSongs = lastFmService.getTopSongs(artist, count, musicFolders);
    Player player = playerService.getPlayer(request, response);
    for (MediaFile topSong : topSongs) {
        result.getSong().add(createJaxbChild(player, topSong, username));
    }
    Response res = createResponse();
    res.setTopSongs(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with MusicFolder

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

the class RESTController method getSimilarSongs.

@RequestMapping(value = "/rest/getSimilarSongs", method = { RequestMethod.GET, RequestMethod.POST })
public void getSimilarSongs(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);
    int id = getRequiredIntParameter(request, "id");
    int count = getIntParameter(request, "count", 50);
    SimilarSongs result = new SimilarSongs();
    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    if (mediaFile == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Media file not found.");
        return;
    }
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> similarSongs = lastFmService.getSimilarSongs(mediaFile, count, musicFolders);
    Player player = playerService.getPlayer(request, response);
    for (MediaFile similarSong : similarSongs) {
        result.getSong().add(createJaxbChild(player, similarSong, username));
    }
    Response res = createResponse();
    res.setSimilarSongs(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with MusicFolder

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

the class UserSettingsController method getAllowedMusicFolderIds.

private List<Integer> getAllowedMusicFolderIds(User user) {
    List<Integer> result = new ArrayList<Integer>();
    List<MusicFolder> allowedMusicFolders = user == null ? settingsService.getAllMusicFolders() : settingsService.getMusicFoldersForUser(user.getUsername());
    for (MusicFolder musicFolder : allowedMusicFolders) {
        result.add(musicFolder.getId());
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) MusicFolder(org.libresonic.player.domain.MusicFolder)

Example 9 with MusicFolder

use of org.libresonic.player.domain.MusicFolder 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 10 with MusicFolder

use of org.libresonic.player.domain.MusicFolder 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)

Aggregations

MusicFolder (org.libresonic.player.domain.MusicFolder)37 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 HttpServletResponse (javax.servlet.http.HttpServletResponse)21 Artist (org.libresonic.player.domain.Artist)7 File (java.io.File)6 org.libresonic.restapi (org.libresonic.restapi)6 Date (java.util.Date)5 MediaFile (org.libresonic.player.domain.MediaFile)5 User (org.libresonic.player.domain.User)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 SearchResult (org.libresonic.player.domain.SearchResult)3 Share (org.libresonic.player.domain.Share)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 FileOutputStream (java.io.FileOutputStream)1 DateFormat (java.text.DateFormat)1 HashMap (java.util.HashMap)1 MusicFolderSettingsCommand (org.libresonic.player.command.MusicFolderSettingsCommand)1 Player (org.libresonic.player.domain.Player)1