Search in sources :

Example 11 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.

the class AlbumsFragment method enqueueAlbum.

/**
 * Enqueues the album selected by the user
 * @param index Index of the selected album
 */
private void enqueueAlbum(int index) {
    MPDAlbum album = (MPDAlbum) mAlbumsAdapter.getItem(index);
    // support group commands and therefore do not provide artist tags for albums)
    if (mArtist != null && !mArtist.getArtistName().isEmpty() && album.getArtistName().isEmpty()) {
        album.setArtistName(mArtist.getArtistName());
        album.setArtistSortName(mArtist.getArtistName());
    }
    MPDQueryHandler.addArtistAlbum(album.getName(), album.getArtistName(), album.getMBID());
}
Also used : MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)

Example 12 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.

the class MPDInterface method getAlbums.

/**
 * Get a list of all albums available in the database.
 *
 * @return List of MPDAlbum
 */
public List<MPDAlbum> getAlbums() throws MPDException {
    List<MPDAlbum> albums;
    synchronized (this) {
        // Get a list of albums. Check if server is new enough for MB and AlbumArtist filtering
        mConnection.sendMPDCommand(MPDCommands.MPD_COMMAND_REQUEST_ALBUMS(mConnection.getServerCapabilities()));
        // Remove empty albums at beginning of the list
        albums = MPDResponseParser.parseMPDAlbums(mConnection);
    }
    ListIterator<MPDAlbum> albumIterator = albums.listIterator();
    while (albumIterator.hasNext()) {
        MPDAlbum album = albumIterator.next();
        if (album.getName().isEmpty()) {
            albumIterator.remove();
        } else {
            break;
        }
    }
    return albums;
}
Also used : MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)

Example 13 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.

the class MPDInterface method getAlbumsInPath.

/**
 * Get a list of all albums available in the database.
 *
 * @return List of MPDAlbum
 */
public List<MPDAlbum> getAlbumsInPath(String path) throws MPDException {
    List<MPDAlbum> albums;
    synchronized (this) {
        // Get a list of albums. Check if server is new enough for MB and AlbumArtist filtering
        mConnection.sendMPDCommand(MPDCommands.MPD_COMMAND_REQUEST_ALBUMS_FOR_PATH(path, mConnection.getServerCapabilities()));
        // Remove empty albums at beginning of the list
        albums = MPDResponseParser.parseMPDAlbums(mConnection);
    }
    ListIterator<MPDAlbum> albumIterator = albums.listIterator();
    while (albumIterator.hasNext()) {
        MPDAlbum album = albumIterator.next();
        if (album.getName().isEmpty()) {
            albumIterator.remove();
        } else {
            break;
        }
    }
    return albums;
}
Also used : MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)

Example 14 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.

the class MPDResponseParser method parseMPDAlbums.

/**
 * Parses the return of MPD when a list of albums was requested.
 *
 * @return List of MPDAlbum objects
 * @throws MPDException if an error from MPD was received during reading
 */
static ArrayList<MPDAlbum> parseMPDAlbums(final MPDConnection connection) throws MPDException {
    ArrayList<MPDAlbum> albumList = new ArrayList<>();
    if (!connection.isConnected()) {
        return albumList;
    }
    /* Parse the MPD response and create a list of MPD albums */
    String albumName;
    MPDAlbum tempAlbum = null;
    String responseString = connection.readLine();
    while (responseString != null && !responseString.startsWith("OK")) {
        /* Check if the response is an album */
        if (responseString.startsWith(MPDResponses.MPD_RESPONSE_ALBUM_NAME)) {
            /* We found an album, add it to the list. */
            if (null != tempAlbum) {
                albumList.add(tempAlbum);
            }
            albumName = responseString.substring(MPDResponses.MPD_RESPONSE_ALBUM_NAME.length());
            tempAlbum = new MPDAlbum(albumName);
        }
        if (tempAlbum != null) {
            if (responseString.startsWith(MPDResponses.MPD_RESPONSE_ALBUM_MBID)) {
                tempAlbum.setMBID(responseString.substring(MPDResponses.MPD_RESPONSE_ALBUM_MBID.length()));
            } else if (responseString.startsWith(MPDResponses.MPD_RESPONSE_ALBUMARTIST_NAME)) {
                /* Check if the responseString is a album artist. */
                tempAlbum.setArtistName(responseString.substring(MPDResponses.MPD_RESPONSE_ALBUMARTIST_NAME.length()));
            } else if (responseString.startsWith(MPDResponses.MPD_RESPONSE_ALBUMARTIST_SORT_NAME)) {
                /* Check if the responseString is a album artist. */
                tempAlbum.setArtistSortName(responseString.substring(MPDResponses.MPD_RESPONSE_ALBUMARTIST_SORT_NAME.length()));
            } else if (responseString.startsWith(MPDResponses.MPD_RESPONSE_DATE)) {
                // Try to parse Date
                String dateString = responseString.substring(MPDResponses.MPD_RESPONSE_DATE.length());
                SimpleDateFormat format = new SimpleDateFormat("yyyy");
                try {
                    tempAlbum.setDate(format.parse(dateString));
                } catch (ParseException e) {
                    Log.w(TAG, "Error parsing date: " + dateString);
                }
            }
        }
        responseString = connection.readLine();
    }
    /* Because of the loop structure the last album has to be added because no
        "ALBUM:" is sent anymore.
         */
    if (null != tempAlbum) {
        albumList.add(tempAlbum);
    }
    // Sort the albums for later sectioning.
    Collections.sort(albumList);
    return albumList;
}
Also used : MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 15 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.

the class AsyncLoader method doInBackground.

/**
 * Asynchronous task in parallel to the GUI thread.
 * @param params Input parameter containing all the necessary informaton to fetch the image.
 * @return Bitmap loaded from the database.
 */
@Override
protected Bitmap doInBackground(CoverViewHolder... params) {
    // Save the time when loading started for later duration calculation
    mStartTime = System.currentTimeMillis();
    mCover = params[0];
    Bitmap image = null;
    // Check if model item is artist or album
    if (mCover.modelItem instanceof MPDArtist) {
        MPDArtist artist = (MPDArtist) mCover.modelItem;
        try {
            // Check if image is available. If it is not yet fetched it will throw an exception
            // If it was already searched for and not found, this will be null.
            image = mCover.artworkManager.getArtistImage(artist, mCover.imageDimension.first, mCover.imageDimension.second, false);
        } catch (ImageNotFoundException e) {
            // Check if fetching for this item is already ongoing
            if (!artist.getFetching()) {
                // If not set it as ongoing and request the image fetch.
                mCover.artworkManager.fetchArtistImage(artist);
                artist.setFetching(true);
            }
        }
    } else if (mCover.modelItem instanceof MPDAlbum) {
        MPDAlbum album = (MPDAlbum) mCover.modelItem;
        try {
            // Check if image is available. If it is not yet fetched it will throw an exception.
            // If it was already searched for and not found, this will be null.
            image = mCover.artworkManager.getAlbumImage(album, mCover.imageDimension.first, mCover.imageDimension.second, false);
        } catch (ImageNotFoundException e) {
            // Check if fetching for this item is already ongoing
            if (!album.getFetching()) {
                // If not set it as ongoing and request the image fetch.
                mCover.artworkManager.fetchAlbumImage(album);
                album.setFetching(true);
            }
        }
    } else if (mCover.modelItem instanceof MPDTrack) {
        MPDTrack track = (MPDTrack) mCover.modelItem;
        try {
            // Check if image is available. If it is not yet fetched it will throw an exception.
            // If it was already searched for and not found, this will be null.
            image = mCover.artworkManager.getAlbumImageForTrack(track, mCover.imageDimension.first, mCover.imageDimension.second, false);
        } catch (ImageNotFoundException e) {
            // Check if fetching for this item is already ongoing
            if (!track.getFetching()) {
                // If not set it as ongoing and request the image fetch.
                mCover.artworkManager.fetchAlbumImage(track);
                track.setFetching(true);
            }
        }
    }
    return image;
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) Bitmap(android.graphics.Bitmap) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) ImageNotFoundException(org.gateshipone.malp.application.artworkdatabase.ImageNotFoundException)

Aggregations

MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)15 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)5 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)5 Bitmap (android.graphics.Bitmap)3 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)3 VolleyError (com.android.volley.VolleyError)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TrackAlbumFetchError (org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError)2 MPDResponseAlbumList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList)2 MPDResponseArtistList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList)2 MPDResponseFileList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 BitmapFactory (android.graphics.BitmapFactory)1 ConnectivityManager (android.net.ConnectivityManager)1 NetworkInfo (android.net.NetworkInfo)1