use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method getRelativePath.
private String getRelativePath(MediaFile musicFile) {
String filePath = musicFile.getPath();
// Convert slashes.
filePath = filePath.replace('\\', '/');
String filePathLower = filePath.toLowerCase();
List<MusicFolder> musicFolders = settingsService.getAllMusicFolders(false, true);
for (MusicFolder musicFolder : musicFolders) {
String folderPath = musicFolder.getPath().getPath();
folderPath = folderPath.replace('\\', '/');
String folderPathLower = folderPath.toLowerCase();
if (!folderPathLower.endsWith("/")) {
folderPathLower += "/";
}
if (filePathLower.startsWith(folderPathLower)) {
String relativePath = filePath.substring(folderPath.length());
return relativePath.startsWith("/") ? relativePath.substring(1) : relativePath;
}
}
return null;
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class ShareSettingsController method getShareInfos.
private List<ShareInfo> getShareInfos(HttpServletRequest request) {
List<ShareInfo> result = new ArrayList<ShareInfo>();
User user = securityService.getCurrentUser(request);
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
for (Share share : shareService.getSharesForUser(user)) {
List<MediaFile> files = shareService.getSharedFiles(share.getId(), musicFolders);
if (!files.isEmpty()) {
MediaFile file = files.get(0);
result.add(new ShareInfo(shareService.getShareUrl(request, share), share, file.isDirectory() ? file : mediaFileService.getParentOf(file)));
}
}
return result;
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method getStarred2.
@RequestMapping(value = "/rest/getStarred2", method = { RequestMethod.GET, RequestMethod.POST })
public void getStarred2(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
Integer musicFolderId = getIntParameter(request, "musicFolderId");
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
Starred2 result = new Starred2();
for (Artist artist : artistDao.getStarredArtists(0, Integer.MAX_VALUE, username, musicFolders)) {
result.getArtist().add(createJaxbArtist(new ArtistID3(), artist, username));
}
for (Album album : albumDao.getStarredAlbums(0, Integer.MAX_VALUE, username, musicFolders)) {
result.getAlbum().add(createJaxbAlbum(new AlbumID3(), album, username));
}
for (MediaFile song : mediaFileDao.getStarredFiles(0, Integer.MAX_VALUE, username, musicFolders)) {
result.getSong().add(createJaxbChild(player, song, username));
}
Response res = createResponse();
res.setStarred2(result);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method search2.
@RequestMapping(value = "/rest/search2", method = { RequestMethod.GET, RequestMethod.POST })
public void search2(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
Integer musicFolderId = getIntParameter(request, "musicFolderId");
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
SearchResult2 searchResult = new SearchResult2();
String query = request.getParameter("query");
SearchCriteria criteria = new SearchCriteria();
criteria.setQuery(StringUtils.trimToEmpty(query));
criteria.setCount(getIntParameter(request, "artistCount", 20));
criteria.setOffset(getIntParameter(request, "artistOffset", 0));
SearchResult artists = searchService.search(criteria, musicFolders, SearchService.IndexType.ARTIST);
for (MediaFile mediaFile : artists.getMediaFiles()) {
searchResult.getArtist().add(createJaxbArtist(mediaFile, username));
}
criteria.setCount(getIntParameter(request, "albumCount", 20));
criteria.setOffset(getIntParameter(request, "albumOffset", 0));
SearchResult albums = searchService.search(criteria, musicFolders, SearchService.IndexType.ALBUM);
for (MediaFile mediaFile : albums.getMediaFiles()) {
searchResult.getAlbum().add(createJaxbChild(player, mediaFile, username));
}
criteria.setCount(getIntParameter(request, "songCount", 20));
criteria.setOffset(getIntParameter(request, "songOffset", 0));
SearchResult songs = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
for (MediaFile mediaFile : songs.getMediaFiles()) {
searchResult.getSong().add(createJaxbChild(player, mediaFile, username));
}
Response res = createResponse();
res.setSearchResult2(searchResult);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method getArtist.
@RequestMapping(value = "/rest/getArtist", method = { RequestMethod.GET, RequestMethod.POST })
public void getArtist(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
String username = securityService.getCurrentUsername(request);
int id = getRequiredIntParameter(request, "id");
Artist artist = artistDao.getArtist(id);
if (artist == null) {
error(request, response, ErrorCode.NOT_FOUND, "Artist not found.");
return;
}
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
ArtistWithAlbumsID3 result = createJaxbArtist(new ArtistWithAlbumsID3(), artist, username);
for (Album album : albumDao.getAlbumsForArtist(artist.getName(), musicFolders)) {
result.getAlbum().add(createJaxbAlbum(new AlbumID3(), album, username));
}
Response res = createResponse();
res.setArtist(result);
jaxbWriter.writeResponse(request, response, res);
}
Aggregations