Search in sources :

Example 11 with MediaFile

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

the class PodcastService method updateTags.

private void updateTags(File file, PodcastEpisode episode) {
    try {
        MediaFile mediaFile = mediaFileService.getMediaFile(file, false);
        if (StringUtils.isNotBlank(episode.getTitle())) {
            MetaDataParser parser = metaDataParserFactory.getParser(file);
            if (!parser.isEditingSupported()) {
                return;
            }
            MetaData metaData = parser.getRawMetaData(file);
            metaData.setTitle(episode.getTitle());
            parser.setMetaData(mediaFile, metaData);
            mediaFileService.refreshMediaFile(mediaFile);
        }
    } catch (Exception x) {
        LOG.warn("Failed to update tags for podcast " + episode.getUrl(), x);
    }
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) MetaData(org.libresonic.player.service.metadata.MetaData) MetaDataParser(org.libresonic.player.service.metadata.MetaDataParser)

Example 12 with MediaFile

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

the class RatingService method getHighestRatedAlbums.

/**
     * Returns the highest rated albums.
     *
     * @param offset      Number of albums to skip.
     * @param count       Maximum number of albums to return.
     * @param musicFolders Only return albums in these folders.
     * @return The highest rated albums.
     */
public List<MediaFile> getHighestRatedAlbums(int offset, int count, List<MusicFolder> musicFolders) {
    List<String> highestRated = ratingDao.getHighestRatedAlbums(offset, count, musicFolders);
    List<MediaFile> result = new ArrayList<MediaFile>();
    for (String path : highestRated) {
        File file = new File(path);
        if (FileUtil.exists(file) && securityService.isReadAllowed(file)) {
            result.add(mediaFileService.getMediaFile(path));
        }
    }
    return result;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) ArrayList(java.util.ArrayList) MediaFile(org.libresonic.player.domain.MediaFile) File(java.io.File)

Example 13 with MediaFile

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

the class SonosService method getMediaMetadata.

@Override
public GetMediaMetadataResponse getMediaMetadata(GetMediaMetadata parameters) {
    LOG.debug("getMediaMetadata: " + parameters.getId());
    GetMediaMetadataResponse response = new GetMediaMetadataResponse();
    // Return an empty response to avoid ugly log message.
    if (parameters.getId().startsWith(ID_PLAYLIST_PREFIX)) {
        return response;
    }
    int id = Integer.parseInt(parameters.getId());
    MediaFile song = mediaFileService.getMediaFile(id);
    response.setGetMediaMetadataResult(sonosHelper.forSong(song, getUsername(), getRequest()));
    return response;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile)

Example 14 with MediaFile

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

the class PodcastService method downloadImage.

private void downloadImage(PodcastChannel channel) {
    InputStream in = null;
    OutputStream out = null;
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        String imageUrl = channel.getImageUrl();
        if (imageUrl == null) {
            return;
        }
        File dir = getChannelDirectory(channel);
        MediaFile channelMediaFile = mediaFileService.getMediaFile(dir);
        File existingCoverArt = mediaFileService.getCoverArt(channelMediaFile);
        boolean imageFileExists = existingCoverArt != null && mediaFileService.getMediaFile(existingCoverArt) == null;
        if (imageFileExists) {
            return;
        }
        HttpGet method = new HttpGet(imageUrl);
        try (CloseableHttpResponse response = client.execute(method)) {
            in = response.getEntity().getContent();
            out = new FileOutputStream(new File(dir, "cover." + getCoverArtSuffix(response)));
            IOUtils.copy(in, out);
            mediaFileService.refreshMediaFile(channelMediaFile);
        }
    } catch (Exception x) {
        LOG.warn("Failed to download cover art for podcast channel '" + channel.getTitle() + "': " + x, x);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) HttpGet(org.apache.http.client.methods.HttpGet) FileOutputStream(java.io.FileOutputStream) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) MediaFile(org.libresonic.player.domain.MediaFile) File(java.io.File)

Example 15 with MediaFile

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

the class PodcastService method addMediaFileIdToChannels.

private List<PodcastChannel> addMediaFileIdToChannels(List<PodcastChannel> channels) {
    for (PodcastChannel channel : channels) {
        try {
            File dir = getChannelDirectory(channel);
            MediaFile mediaFile = mediaFileService.getMediaFile(dir);
            if (mediaFile != null) {
                channel.setMediaFileId(mediaFile.getId());
            }
        } catch (Exception x) {
            LOG.warn("Failed to resolve media file ID for podcast channel '" + channel.getTitle() + "': " + x, x);
        }
    }
    return channels;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) PodcastChannel(org.libresonic.player.domain.PodcastChannel) MediaFile(org.libresonic.player.domain.MediaFile) File(java.io.File)

Aggregations

MediaFile (org.libresonic.player.domain.MediaFile)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ModelAndView (org.springframework.web.servlet.ModelAndView)8 File (java.io.File)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 MusicFolder (org.libresonic.player.domain.MusicFolder)5 Playlist (org.libresonic.player.domain.Playlist)5 Player (org.libresonic.player.domain.Player)4 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 RedirectView (org.springframework.web.servlet.view.RedirectView)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 Test (org.junit.Test)2 Share (org.libresonic.player.domain.Share)2 TransferStatus (org.libresonic.player.domain.TransferStatus)2