Search in sources :

Example 1 with Bookmark

use of org.libresonic.player.domain.Bookmark 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;
}
Also used : Artist(org.libresonic.player.domain.Artist) Bookmark(org.libresonic.player.domain.Bookmark)

Example 2 with Bookmark

use of org.libresonic.player.domain.Bookmark in project libresonic by Libresonic.

the class RESTController method createBookmark.

@RequestMapping(value = "/rest/createBookmark", method = { RequestMethod.GET, RequestMethod.POST })
public void createBookmark(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);
    int mediaFileId = getRequiredIntParameter(request, "id");
    long position = getRequiredLongParameter(request, "position");
    String comment = request.getParameter("comment");
    Date now = new Date();
    Bookmark bookmark = new Bookmark(0, mediaFileId, position, username, comment, now, now);
    bookmarkDao.createOrUpdateBookmark(bookmark);
    refreshBookmarkCache();
    writeEmptyResponse(request, response);
}
Also used : Bookmark(org.libresonic.player.domain.Bookmark) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Bookmark

use of org.libresonic.player.domain.Bookmark in project libresonic by Libresonic.

the class RESTController method getBookmarks.

@RequestMapping(value = "/rest/getBookmarks", method = { RequestMethod.GET, RequestMethod.POST })
public void getBookmarks(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    Bookmarks result = new Bookmarks();
    for (Bookmark bookmark : bookmarkDao.getBookmarks(username)) {
        org.libresonic.restapi.Bookmark b = new org.libresonic.restapi.Bookmark();
        result.getBookmark().add(b);
        b.setPosition(bookmark.getPositionMillis());
        b.setUsername(bookmark.getUsername());
        b.setComment(bookmark.getComment());
        b.setCreated(jaxbWriter.convertDate(bookmark.getCreated()));
        b.setChanged(jaxbWriter.convertDate(bookmark.getChanged()));
        MediaFile mediaFile = mediaFileService.getMediaFile(bookmark.getMediaFileId());
        b.setEntry(createJaxbChild(player, mediaFile, username));
    }
    Response res = createResponse();
    res.setBookmarks(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Bookmark(org.libresonic.player.domain.Bookmark) org.libresonic.restapi(org.libresonic.restapi) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Bookmark (org.libresonic.player.domain.Bookmark)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Artist (org.libresonic.player.domain.Artist)1 org.libresonic.restapi (org.libresonic.restapi)1