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);
}
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);
}
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;
}
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;
}
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();
}
Aggregations