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);
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations