use of org.moire.ultrasonic.domain.MusicDirectory in project ultrasonic by ultrasonic.
the class RESTMusicService method getSongsByGenre.
@Override
public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception {
if (genre == null) {
throw new IllegalArgumentException("Genre is null");
}
updateProgressListener(progressListener, R.string.parser_reading);
Response<GetSongsByGenreResponse> response = subsonicAPIClient.getApi().getSongsByGenre(genre, count, offset, null).execute();
checkResponseSuccessful(response);
MusicDirectory result = new MusicDirectory();
result.addAll(APIMusicDirectoryConverter.toDomainEntityList(response.body().getSongsList()));
return result;
}
use of org.moire.ultrasonic.domain.MusicDirectory in project ultrasonic by ultrasonic.
the class RESTMusicService method getPodcastEpisodes.
@Override
public MusicDirectory getPodcastEpisodes(String podcastChannelId, Context context, ProgressListener progressListener) throws Exception {
if (podcastChannelId == null) {
throw new IllegalArgumentException("Podcast channel id is null!");
}
updateProgressListener(progressListener, R.string.parser_reading);
Response<GetPodcastsResponse> response = subsonicAPIClient.getApi().getPodcasts(true, podcastChannelId).execute();
checkResponseSuccessful(response);
List<MusicDirectoryChild> podcastEntries = response.body().getPodcastChannels().get(0).getEpisodeList();
MusicDirectory musicDirectory = new MusicDirectory();
for (MusicDirectoryChild podcastEntry : podcastEntries) {
if (!"skipped".equals(podcastEntry.getStatus()) && !"error".equals(podcastEntry.getStatus())) {
MusicDirectory.Entry entry = APIMusicDirectoryConverter.toDomainEntity(podcastEntry);
entry.setTrack(null);
musicDirectory.addChild(entry);
}
}
return musicDirectory;
}
use of org.moire.ultrasonic.domain.MusicDirectory in project ultrasonic by ultrasonic.
the class ShufflePlayBuffer method refill.
private void refill() {
// Check if active server has changed.
clearBufferIfNecessary();
if (buffer.size() > REFILL_THRESHOLD || (!Util.isNetworkConnected(context) && !Util.isOffline(context))) {
return;
}
try {
MusicService service = MusicServiceFactory.getMusicService(context);
int n = CAPACITY - buffer.size();
MusicDirectory songs = service.getRandomSongs(n, context, null);
synchronized (buffer) {
buffer.addAll(songs.getChildren());
Log.i(TAG, String.format("Refilled shuffle play buffer with %d songs.", songs.getChildren().size()));
}
} catch (Exception x) {
Log.w(TAG, "Failed to refill shuffle play buffer.", x);
}
}
use of org.moire.ultrasonic.domain.MusicDirectory in project ultrasonic by ultrasonic.
the class RESTMusicService method savePlaylist.
private void savePlaylist(String name, Context context, MusicDirectory playlist) throws IOException {
File playlistFile = FileUtil.getPlaylistFile(Util.getServerName(context), name);
FileWriter fw = new FileWriter(playlistFile);
BufferedWriter bw = new BufferedWriter(fw);
try {
fw.write("#EXTM3U\n");
for (MusicDirectory.Entry e : playlist.getChildren()) {
String filePath = FileUtil.getSongFile(context, e).getAbsolutePath();
if (!new File(filePath).exists()) {
String ext = FileUtil.getExtension(filePath);
String base = FileUtil.getBaseName(filePath);
filePath = base + ".complete." + ext;
}
fw.write(filePath + '\n');
}
} catch (IOException e) {
Log.w(TAG, "Failed to save playlist: " + name);
throw e;
} finally {
bw.close();
fw.close();
}
}
use of org.moire.ultrasonic.domain.MusicDirectory in project ultrasonic by ultrasonic.
the class RESTMusicService method getPlaylist.
@Override
public MusicDirectory getPlaylist(String id, String name, Context context, ProgressListener progressListener) throws Exception {
if (id == null) {
throw new IllegalArgumentException("id param is null!");
}
updateProgressListener(progressListener, R.string.parser_reading);
Response<GetPlaylistResponse> response = subsonicAPIClient.getApi().getPlaylist(id).execute();
checkResponseSuccessful(response);
MusicDirectory playlist = APIPlaylistConverter.toMusicDirectoryDomainEntity(response.body().getPlaylist());
savePlaylist(name, context, playlist);
return playlist;
}
Aggregations