use of org.libresonic.player.domain.Artist in project libresonic by Libresonic.
the class RESTController method starOrUnstar.
private void starOrUnstar(HttpServletRequest request, HttpServletResponse response, boolean star) throws Exception {
request = wrapRequest(request);
String username = securityService.getCurrentUser(request).getUsername();
for (int id : getIntParameters(request, "id")) {
MediaFile mediaFile = mediaFileDao.getMediaFile(id);
if (mediaFile == null) {
error(request, response, ErrorCode.NOT_FOUND, "Media file not found: " + id);
return;
}
if (star) {
mediaFileDao.starMediaFile(id, username);
} else {
mediaFileDao.unstarMediaFile(id, username);
}
}
for (int albumId : getIntParameters(request, "albumId")) {
Album album = albumDao.getAlbum(albumId);
if (album == null) {
error(request, response, ErrorCode.NOT_FOUND, "Album not found: " + albumId);
return;
}
if (star) {
albumDao.starAlbum(albumId, username);
} else {
albumDao.unstarAlbum(albumId, username);
}
}
for (int artistId : getIntParameters(request, "artistId")) {
Artist artist = artistDao.getArtist(artistId);
if (artist == null) {
error(request, response, ErrorCode.NOT_FOUND, "Artist not found: " + artistId);
return;
}
if (star) {
artistDao.starArtist(artistId, username);
} else {
artistDao.unstarArtist(artistId, username);
}
}
writeEmptyResponse(request, response);
}
use of org.libresonic.player.domain.Artist in project libresonic by Libresonic.
the class RESTController method getIndexes.
@RequestMapping(value = "/rest/getIndexes", method = { RequestMethod.GET, RequestMethod.POST })
public void getIndexes(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Response res = createResponse();
String username = securityService.getCurrentUser(request).getUsername();
long ifModifiedSince = getLongParameter(request, "ifModifiedSince", 0L);
long lastModified = leftController.getLastModified(request);
if (lastModified <= ifModifiedSince) {
jaxbWriter.writeResponse(request, response, res);
return;
}
Indexes indexes = new Indexes();
indexes.setLastModified(lastModified);
indexes.setIgnoredArticles(settingsService.getIgnoredArticles());
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
Integer musicFolderId = getIntParameter(request, "musicFolderId");
if (musicFolderId != null) {
for (MusicFolder musicFolder : musicFolders) {
if (musicFolderId.equals(musicFolder.getId())) {
musicFolders = Collections.singletonList(musicFolder);
break;
}
}
}
for (MediaFile shortcut : musicIndexService.getShortcuts(musicFolders)) {
indexes.getShortcut().add(createJaxbArtist(shortcut, username));
}
MusicFolderContent musicFolderContent = musicIndexService.getMusicFolderContent(musicFolders, false);
for (Map.Entry<MusicIndex, List<MusicIndex.SortableArtistWithMediaFiles>> entry : musicFolderContent.getIndexedArtists().entrySet()) {
Index index = new Index();
indexes.getIndex().add(index);
index.setName(entry.getKey().getIndex());
for (MusicIndex.SortableArtistWithMediaFiles artist : entry.getValue()) {
for (MediaFile mediaFile : artist.getMediaFiles()) {
if (mediaFile.isDirectory()) {
Date starredDate = mediaFileDao.getMediaFileStarredDate(mediaFile.getId(), username);
org.libresonic.restapi.Artist a = new org.libresonic.restapi.Artist();
index.getArtist().add(a);
a.setId(String.valueOf(mediaFile.getId()));
a.setName(artist.getName());
a.setStarred(jaxbWriter.convertDate(starredDate));
if (mediaFile.isAlbum()) {
a.setAverageRating(ratingService.getAverageRating(mediaFile));
a.setUserRating(ratingService.getRatingForUser(username, mediaFile));
}
}
}
}
}
// Add children
Player player = playerService.getPlayer(request, response);
for (MediaFile singleSong : musicFolderContent.getSingleSongs()) {
indexes.getChild().add(createJaxbChild(player, singleSong, username));
}
res.setIndexes(indexes);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.Artist in project libresonic by Libresonic.
the class RESTController method createJaxbChild.
private <T extends Child> T createJaxbChild(T child, Player player, MediaFile mediaFile, String username) {
MediaFile parent = mediaFileService.getParentOf(mediaFile);
child.setId(String.valueOf(mediaFile.getId()));
try {
if (!mediaFileService.isRoot(parent)) {
child.setParent(String.valueOf(parent.getId()));
}
} catch (SecurityException x) {
// Ignored.
}
child.setTitle(mediaFile.getName());
child.setAlbum(mediaFile.getAlbumName());
child.setArtist(mediaFile.getArtist());
child.setIsDir(mediaFile.isDirectory());
child.setCoverArt(findCoverArt(mediaFile, parent));
child.setYear(mediaFile.getYear());
child.setGenre(mediaFile.getGenre());
child.setCreated(jaxbWriter.convertDate(mediaFile.getCreated()));
child.setStarred(jaxbWriter.convertDate(mediaFileDao.getMediaFileStarredDate(mediaFile.getId(), username)));
child.setUserRating(ratingService.getRatingForUser(username, mediaFile));
child.setAverageRating(ratingService.getAverageRating(mediaFile));
if (mediaFile.isFile()) {
child.setDuration(mediaFile.getDurationSeconds());
child.setBitRate(mediaFile.getBitRate());
child.setTrack(mediaFile.getTrackNumber());
child.setDiscNumber(mediaFile.getDiscNumber());
child.setSize(mediaFile.getFileSize());
String suffix = mediaFile.getFormat();
child.setSuffix(suffix);
child.setContentType(StringUtil.getMimeType(suffix));
child.setIsVideo(mediaFile.isVideo());
child.setPath(getRelativePath(mediaFile));
Bookmark bookmark = bookmarkCache.get(new BookmarkKey(username, mediaFile.getId()));
if (bookmark != null) {
child.setBookmarkPosition(bookmark.getPositionMillis());
}
if (mediaFile.getAlbumArtist() != null && mediaFile.getAlbumName() != null) {
Album album = albumDao.getAlbum(mediaFile.getAlbumArtist(), mediaFile.getAlbumName());
if (album != null) {
child.setAlbumId(String.valueOf(album.getId()));
}
}
if (mediaFile.getArtist() != null) {
Artist artist = artistDao.getArtist(mediaFile.getArtist());
if (artist != null) {
child.setArtistId(String.valueOf(artist.getId()));
}
}
switch(mediaFile.getMediaType()) {
case MUSIC:
child.setType(MediaType.MUSIC);
break;
case PODCAST:
child.setType(MediaType.PODCAST);
break;
case AUDIOBOOK:
child.setType(MediaType.AUDIOBOOK);
break;
case VIDEO:
child.setType(MediaType.VIDEO);
child.setOriginalWidth(mediaFile.getWidth());
child.setOriginalHeight(mediaFile.getHeight());
break;
default:
break;
}
if (transcodingService.isTranscodingRequired(mediaFile, player)) {
String transcodedSuffix = transcodingService.getSuffix(player, mediaFile, null);
child.setTranscodedSuffix(transcodedSuffix);
child.setTranscodedContentType(StringUtil.getMimeType(transcodedSuffix));
}
}
return child;
}
use of org.libresonic.player.domain.Artist in project libresonic by Libresonic.
the class RESTController method getArtists.
@RequestMapping(value = "/rest/getArtists", method = { RequestMethod.GET, RequestMethod.POST })
public void getArtists(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
String username = securityService.getCurrentUsername(request);
ArtistsID3 result = new ArtistsID3();
result.setIgnoredArticles(settingsService.getIgnoredArticles());
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
List<Artist> artists = artistDao.getAlphabetialArtists(0, Integer.MAX_VALUE, musicFolders);
SortedMap<MusicIndex, List<MusicIndex.SortableArtistWithArtist>> indexedArtists = musicIndexService.getIndexedArtists(artists);
for (Map.Entry<MusicIndex, List<MusicIndex.SortableArtistWithArtist>> entry : indexedArtists.entrySet()) {
IndexID3 index = new IndexID3();
result.getIndex().add(index);
index.setName(entry.getKey().getIndex());
for (MusicIndex.SortableArtistWithArtist sortableArtist : entry.getValue()) {
index.getArtist().add(createJaxbArtist(new ArtistID3(), sortableArtist.getArtist(), username));
}
}
Response res = createResponse();
res.setArtists(result);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.Artist in project libresonic by Libresonic.
the class MediaScannerServiceTestCase method testScanLibrary.
/**
* Tests the MediaScannerService by scanning the test media library into an empty database.
*/
@Test
public void testScanLibrary() {
MusicFolderTestData.getTestMusicFolders().forEach(musicFolderDao::createMusicFolder);
settingsService.clearMusicFolderCache();
Timer globalTimer = metrics.timer(MetricRegistry.name(MediaScannerServiceTestCase.class, "Timer.global"));
Timer.Context globalTimerContext = globalTimer.time();
TestCaseUtils.execScan(mediaScannerService);
globalTimerContext.stop();
System.out.println("--- Report of records count per table ---");
Map<String, Integer> records = TestCaseUtils.recordsInAllTables(daoHelper);
records.keySet().forEach(tableName -> System.out.println(tableName + " : " + records.get(tableName).toString()));
System.out.println("--- *********************** ---");
// Music Folder Music must have 3 children
List<MediaFile> listeMusicChildren = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusicFolderPath());
Assert.assertEquals(3, listeMusicChildren.size());
// Music Folder Music2 must have 1 children
List<MediaFile> listeMusic2Children = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusic2FolderPath());
Assert.assertEquals(1, listeMusic2Children.size());
System.out.println("--- List of all artists ---");
System.out.println("artistName#albumCount");
List<Artist> allArtists = artistDao.getAlphabetialArtists(0, 0, musicFolderDao.getAllMusicFolders());
allArtists.forEach(artist -> System.out.println(artist.getName() + "#" + artist.getAlbumCount()));
System.out.println("--- *********************** ---");
System.out.println("--- List of all albums ---");
System.out.println("name#artist");
List<Album> allAlbums = albumDao.getAlphabetialAlbums(0, 0, true, musicFolderDao.getAllMusicFolders());
allAlbums.forEach(album -> System.out.println(album.getName() + "#" + album.getArtist()));
Assert.assertEquals(5, allAlbums.size());
System.out.println("--- *********************** ---");
List<MediaFile> listeSongs = mediaFileDao.getSongsByGenre("Baroque Instrumental", 0, 0, musicFolderDao.getAllMusicFolders());
Assert.assertEquals(2, listeSongs.size());
// display out metrics report
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
reporter.report();
System.out.print("End");
}
Aggregations