use of org.libresonic.player.domain.MediaFile in project libresonic by Libresonic.
the class PlaylistService method getFilesInPlaylist.
public List<MediaFile> getFilesInPlaylist(int id, boolean includeNotPresent) {
List<MediaFile> files = mediaFileDao.getFilesInPlaylist(id);
if (includeNotPresent) {
return files;
}
List<MediaFile> presentFiles = new ArrayList<MediaFile>(files.size());
for (MediaFile file : files) {
if (file.isPresent()) {
presentFiles.add(file);
}
}
return presentFiles;
}
use of org.libresonic.player.domain.MediaFile in project libresonic by Libresonic.
the class PodcastService method getNewestEpisodes.
/**
* Returns the N newest episodes.
*
* @return Possibly empty list of the newest Podcast episodes, sorted in
* reverse chronological order (newest episode first).
*/
public List<PodcastEpisode> getNewestEpisodes(int count) {
List<PodcastEpisode> episodes = addMediaFileIdToEpisodes(podcastDao.getNewestEpisodes(count));
return Lists.newArrayList(Iterables.filter(episodes, new Predicate<PodcastEpisode>() {
@Override
public boolean apply(PodcastEpisode episode) {
Integer mediaFileId = episode.getMediaFileId();
if (mediaFileId == null) {
return false;
}
MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId);
return mediaFile != null && mediaFile.isPresent();
}
}));
}
use of org.libresonic.player.domain.MediaFile in project libresonic by Libresonic.
the class SonosService method reorderContainer.
@Override
public ReorderContainerResult reorderContainer(String id, String from, int to, String updateId) {
if (id.startsWith(ID_PLAYLIST_PREFIX)) {
int playlistId = Integer.parseInt(id.replace(ID_PLAYLIST_PREFIX, ""));
Playlist playlist = playlistService.getPlaylist(playlistId);
if (playlist != null && playlist.getUsername().equals(getUsername())) {
SortedMap<Integer, MediaFile> indexToSong = new ConcurrentSkipListMap<Integer, MediaFile>();
List<MediaFile> songs = playlistService.getFilesInPlaylist(playlistId);
for (int i = 0; i < songs.size(); i++) {
indexToSong.put(i, songs.get(i));
}
List<MediaFile> movedSongs = new ArrayList<MediaFile>();
for (Integer i : parsePlaylistIndices(from)) {
movedSongs.add(indexToSong.remove(i));
}
List<MediaFile> updatedSongs = new ArrayList<MediaFile>();
updatedSongs.addAll(indexToSong.headMap(to).values());
updatedSongs.addAll(movedSongs);
updatedSongs.addAll(indexToSong.tailMap(to).values());
playlistService.setFilesInPlaylist(playlistId, updatedSongs);
}
}
return new ReorderContainerResult();
}
use of org.libresonic.player.domain.MediaFile in project libresonic by Libresonic.
the class SonosService method removeFromContainer.
@Override
public RemoveFromContainerResult removeFromContainer(String id, String indices, String updateId) {
if (id.startsWith(ID_PLAYLIST_PREFIX)) {
int playlistId = Integer.parseInt(id.replace(ID_PLAYLIST_PREFIX, ""));
Playlist playlist = playlistService.getPlaylist(playlistId);
if (playlist != null && playlist.getUsername().equals(getUsername())) {
SortedSet<Integer> indicesToRemove = parsePlaylistIndices(indices);
List<MediaFile> songs = playlistService.getFilesInPlaylist(playlistId);
List<MediaFile> updatedSongs = new ArrayList<MediaFile>();
for (int i = 0; i < songs.size(); i++) {
if (!indicesToRemove.contains(i)) {
updatedSongs.add(songs.get(i));
}
}
playlistService.setFilesInPlaylist(playlistId, updatedSongs);
}
}
return new RemoveFromContainerResult();
}
use of org.libresonic.player.domain.MediaFile in project libresonic by Libresonic.
the class SonosService method getExtendedMetadata.
@Override
public GetExtendedMetadataResponse getExtendedMetadata(GetExtendedMetadata parameters) {
LOG.debug("getExtendedMetadata: " + parameters.getId());
int id = Integer.parseInt(parameters.getId());
MediaFile mediaFile = mediaFileService.getMediaFile(id);
AbstractMedia abstractMedia = sonosHelper.forMediaFile(mediaFile, getUsername(), getRequest());
ExtendedMetadata extendedMetadata = new ExtendedMetadata();
if (abstractMedia instanceof MediaCollection) {
extendedMetadata.setMediaCollection((MediaCollection) abstractMedia);
} else {
extendedMetadata.setMediaMetadata((MediaMetadata) abstractMedia);
}
RelatedBrowse relatedBrowse = new RelatedBrowse();
relatedBrowse.setType("RELATED_ARTISTS");
relatedBrowse.setId(ID_SIMILAR_ARTISTS_PREFIX + id);
extendedMetadata.getRelatedBrowse().add(relatedBrowse);
GetExtendedMetadataResponse response = new GetExtendedMetadataResponse();
response.setGetExtendedMetadataResult(extendedMetadata);
return response;
}
Aggregations