Search in sources :

Example 11 with MusicDirectory

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;
}
Also used : GetSongsByGenreResponse(org.moire.ultrasonic.api.subsonic.response.GetSongsByGenreResponse) MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory)

Example 12 with MusicDirectory

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;
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) GetPodcastsResponse(org.moire.ultrasonic.api.subsonic.response.GetPodcastsResponse) MusicDirectoryChild(org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild)

Example 13 with 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);
    }
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) MusicService(org.moire.ultrasonic.service.MusicService)

Example 14 with MusicDirectory

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();
    }
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 15 with MusicDirectory

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;
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) GetPlaylistResponse(org.moire.ultrasonic.api.subsonic.response.GetPlaylistResponse)

Aggregations

MusicDirectory (org.moire.ultrasonic.domain.MusicDirectory)23 MusicService (org.moire.ultrasonic.service.MusicService)8 LinkedList (java.util.LinkedList)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Intent (android.content.Intent)2 View (android.view.View)2 AbsListView (android.widget.AbsListView)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 PullToRefreshListView (com.handmark.pulltorefresh.library.PullToRefreshListView)2 Collection (java.util.Collection)2 Share (org.moire.ultrasonic.domain.Share)2 AlbumView (org.moire.ultrasonic.view.AlbumView)2 SongView (org.moire.ultrasonic.view.SongView)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1