use of org.libresonic.player.domain.MediaFile in project libresonic by Libresonic.
the class MediaFileTestCase method doTestGetDurationAsString.
private void doTestGetDurationAsString(int seconds, String expected) {
MediaFile mediaFile = new MediaFile();
mediaFile.setDurationSeconds(seconds);
assertEquals("Error in getDurationString().", expected, mediaFile.getDurationString());
}
use of org.libresonic.player.domain.MediaFile in project libresonic by Libresonic.
the class SetMusicFileInfoController method handleRequestInternal.
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
String action = request.getParameter("action");
MediaFile mediaFile = mediaFileService.getMediaFile(id);
if ("comment".equals(action)) {
mediaFile.setComment(StringUtil.toHtml(request.getParameter("comment")));
mediaFileService.updateMediaFile(mediaFile);
}
String url = "main.view?id=" + id;
return new ModelAndView(new RedirectView(url));
}
use of org.libresonic.player.domain.MediaFile 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.MediaFile in project libresonic by Libresonic.
the class NowPlayingController method handleRequestInternal.
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Player player = playerService.getPlayer(request, response);
List<TransferStatus> statuses = statusService.getStreamStatusesForPlayer(player);
MediaFile current = statuses.isEmpty() ? null : mediaFileService.getMediaFile(statuses.get(0).getFile());
MediaFile dir = current == null ? null : mediaFileService.getParentOf(current);
String url;
if (dir != null && !mediaFileService.isRoot(dir)) {
url = "main.view?id=" + dir.getId();
} else {
url = "home.view";
}
return new ModelAndView(new RedirectView(url));
}
use of org.libresonic.player.domain.MediaFile in project libresonic by Libresonic.
the class PodcastController method handleRequestInternal.
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String url = request.getRequestURL().toString();
String username = securityService.getCurrentUsername(request);
List<Playlist> playlists = playlistService.getReadablePlaylistsForUser(username);
List<Podcast> podcasts = new ArrayList<>();
for (Playlist playlist : playlists) {
List<MediaFile> songs = playlistService.getFilesInPlaylist(playlist.getId());
if (songs.isEmpty()) {
continue;
}
long length = 0L;
for (MediaFile song : songs) {
length += song.getFileSize();
}
String publishDate = RSS_DATE_FORMAT.format(playlist.getCreated());
// Resolve content type.
String suffix = songs.get(0).getFormat();
String type = StringUtil.getMimeType(suffix);
String enclosureUrl = url + "/stream?playlist=" + playlist.getId();
podcasts.add(new Podcast(playlist.getName(), publishDate, enclosureUrl, length, type));
}
Map<String, Object> map = new HashMap<>();
map.put("url", url);
map.put("podcasts", podcasts);
return new ModelAndView("podcast", "model", map);
}
Aggregations