use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method createShare.
@RequestMapping(value = "/rest/createShare", method = { RequestMethod.GET, RequestMethod.POST })
public void createShare(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
User user = securityService.getCurrentUser(request);
if (!user.isShareRole()) {
error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to share media.");
return;
}
List<MediaFile> files = new ArrayList<MediaFile>();
for (int id : getRequiredIntParameters(request, "id")) {
files.add(mediaFileService.getMediaFile(id));
}
Share share = shareService.createShare(request, files);
share.setDescription(request.getParameter("description"));
long expires = getLongParameter(request, "expires", 0L);
if (expires != 0) {
share.setExpires(new Date(expires));
}
shareService.updateShare(share);
Shares result = new Shares();
org.libresonic.restapi.Share s = createJaxbShare(request, share);
result.getShare().add(s);
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
for (MediaFile mediaFile : shareService.getSharedFiles(share.getId(), musicFolders)) {
s.getEntry().add(createJaxbChild(player, mediaFile, username));
}
Response res = createResponse();
res.setShares(result);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method search.
@RequestMapping(value = "/rest/search", method = { RequestMethod.GET, RequestMethod.POST })
public void search(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
String any = request.getParameter("any");
String artist = request.getParameter("artist");
String album = request.getParameter("album");
String title = request.getParameter("title");
StringBuilder query = new StringBuilder();
if (any != null) {
query.append(any).append(" ");
}
if (artist != null) {
query.append(artist).append(" ");
}
if (album != null) {
query.append(album).append(" ");
}
if (title != null) {
query.append(title);
}
SearchCriteria criteria = new SearchCriteria();
criteria.setQuery(query.toString().trim());
criteria.setCount(getIntParameter(request, "count", 20));
criteria.setOffset(getIntParameter(request, "offset", 0));
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
SearchResult result = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
org.libresonic.restapi.SearchResult searchResult = new org.libresonic.restapi.SearchResult();
searchResult.setOffset(result.getOffset());
searchResult.setTotalHits(result.getTotalHits());
for (MediaFile mediaFile : result.getMediaFiles()) {
searchResult.getMatch().add(createJaxbChild(player, mediaFile, username));
}
Response res = createResponse();
res.setSearchResult(searchResult);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method getSongsByGenre.
@RequestMapping(value = "/rest/getSongsByGenre", method = { RequestMethod.GET, RequestMethod.POST })
public void getSongsByGenre(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
Songs songs = new Songs();
String genre = getRequiredStringParameter(request, "genre");
int offset = getIntParameter(request, "offset", 0);
int count = getIntParameter(request, "count", 10);
count = Math.max(0, Math.min(count, 500));
Integer musicFolderId = getIntParameter(request, "musicFolderId");
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
for (MediaFile mediaFile : mediaFileDao.getSongsByGenre(genre, offset, count, musicFolders)) {
songs.getSong().add(createJaxbChild(player, mediaFile, username));
}
Response res = createResponse();
res.setSongsByGenre(songs);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method getRandomSongs.
@RequestMapping(value = "/rest/getRandomSongs", method = { RequestMethod.GET, RequestMethod.POST })
public void getRandomSongs(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
int size = getIntParameter(request, "size", 10);
size = Math.max(0, Math.min(size, 500));
String genre = getStringParameter(request, "genre");
Integer fromYear = getIntParameter(request, "fromYear");
Integer toYear = getIntParameter(request, "toYear");
Integer musicFolderId = getIntParameter(request, "musicFolderId");
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
RandomSearchCriteria criteria = new RandomSearchCriteria(size, genre, fromYear, toYear, musicFolders);
Songs result = new Songs();
for (MediaFile mediaFile : searchService.getRandomSongs(criteria)) {
result.getSong().add(createJaxbChild(player, mediaFile, username));
}
Response res = createResponse();
res.setRandomSongs(result);
jaxbWriter.writeResponse(request, response, res);
}
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);
}
Aggregations