public void run() { while (true) { try { // sleep a few seconds to make sure we dont kill stuff Thread.sleep(1000); if (destroyThread.get()) break; // try fetching next revision update using socket keepalive // approach // using the next revision-number will make itunes keepalive // until something happens // http://192.168.254.128:3689/ctrl-int/1/playstatusupdate?revision-number=1&session-id=1034286700 parseUpdate( RequestHelper.requestParsed( String.format( "%s/ctrl-int/1/playstatusupdate?revision-number=%d&session-id=%s", session.getRequestBase(), revision, session.sessionId), true)); } catch (Exception e) { Log.d( TAG, String.format( "Exception in keepalive thread, so killing try# %d", failures.get()), e); if (failures.incrementAndGet() > MAX_FAILURES) destroy(); } } Log.w(TAG, "Status KeepAlive Thread Killed!"); }
/** * Sets (activates or deactivates) the speakers as defined in the given list. * * @param speakers all speakers to read the active flag from */ public void setSpeakers(List<Speaker> speakers) { try { Log.d(TAG, "setSpeakers() requesting..."); String idsString = ""; boolean first = true; // The list of speakers to activate is a comma-separated string with // the hex versions of the speakers' IDs for (Speaker speaker : speakers) { if (speaker.isActive()) { if (!first) { idsString += ","; } else { first = false; } idsString += speaker.getIdAsHex(); } } String url = String.format( "%s/ctrl-int/1/setspeakers?speaker-id=%s&session-id=%s", session.getRequestBase(), idsString, session.sessionId); RequestHelper.request(url, false); } catch (Exception e) { Log.e(TAG, "Could not set speakers: ", e); } }
public ArtistSearchContainer getArtists() throws Exception { return RequestHelper.requestParsed( String.format( "%s/databases/%d/groups?meta=dmap.itemname,dmap.itemid,dmap.persistentid,daap.songartist,daap.groupalbumcount,daap.songartistid&type=music&group-type=artists&sort=album&include-sort-headers=1&query=('daap.songartist!:'+('com.apple.itunes.extended-media-kind:1','com.apple.itunes.extended-media-kind:32'))&session-id=%s", session.getRequestBase(), session.getDatabase().getItemId(), session.getSessionId()), false); }
/** * Helper to control a speakers's absolute volume. This uses the URL parameters <code> * setproperty?dmcp.volume=%d&include-speaker-id=%s</code> which results in iTunes controlling the * master volume and the selected speaker synchronously. * * @param speakerId ID of the speaker to control * @param absoluteVolume the volume to set absolutely * @throws Exception */ private void setAbsoluteVolume(long speakerId, int absoluteVolume) throws Exception { String url; url = String.format( "%s/ctrl-int/1/setproperty?dmcp.volume=%d&include-speaker-id=%s" + "&session-id=%s", session.getRequestBase(), absoluteVolume, speakerId, session.sessionId); RequestHelper.request(url, false); }
/** * Helper to control a speaker's relative volume. This relative volume is a value between 0 and * 100 describing the relative volume of a speaker in comparison to the master volume. For this * the URL parameters <code>%s/ctrl-int/1/setproperty?speaker-id=%s&dmcp.volume=%d</code> are * used. * * @param speakerId ID of the speaker to control * @param relativeVolume the relative volume to set * @throws Exception */ private void setRelativeVolume(long speakerId, int relativeVolume) throws Exception { String url; url = String.format( "%s/ctrl-int/1/setproperty?speaker-id=%s&dmcp.volume=%d" + "&session-id=%s", session.getRequestBase(), speakerId, relativeVolume, session.sessionId); RequestHelper.request(url, false); }
public AlbumSearchContainer getAllAlbums() throws Exception { // make partial album list request // http://192.168.254.128:3689/databases/36/groups?session-id=1034286700&meta=dmap.itemname,dmap.itemid,dmap.persistentid,daap.songartist&type=music&group-type=albums&sort=artist&include-sort-headers=1&index=0-50 return RequestHelper.requestParsed( String.format( "%s/databases/%d/groups?session-id=%s&meta=dmap.itemname,dmap.itemid,dmap.persistentid,daap.songartist&type=music&group-type=albums&sort=album&include-sort-headers=1", session.getRequestBase(), session.getDatabase().getItemId(), session.getSessionId()), false); }
public DatabaseBrowse getAllArtists() throws Exception { // request ALL artists for performance // /databases/%d/browse/artists?session-id=%s&include-sort-headers=1&index=%d-%d return RequestHelper.requestParsed( String.format( "%s/databases/%d/browse/artists?session-id=%s&include-sort-headers=1", session.getRequestBase(), session.getDatabase().getItemId(), session.getSessionId()), false, true); }
public ItemsContainer getUnknownQuery() throws Exception { return RequestHelper.requestParsed( String.format( "%s/databases/%d/containers/%s/items?meta=dmap.itemname,dmap.itemid,daap.songartist,daap.songalbumartist,daap.songalbum,com.apple.itunes.cloud-id,dmap.containeritemid,com.apple.itunes.has-video,com.apple.itunes.itms-songid,com.apple.itunes.extended-media-kind,dmap.downloadstatus,daap.songdisabled&type=music&sort=name&include-sort-headers=1&query=('com.apple.itunes.extended-media-kind:1','com.apple.itunes.extended-media-kind:32')&session-id=%s", session.getRequestBase(), session.getDatabase().getItemId(), session.getDatabase().getMasterContainer().getItemId(), session.getSessionId()), false); }
public ItemsContainer getPlaylistSongs(String playlistid) throws Exception { // http://192.168.254.128:3689/databases/36/containers/1234/items?session-id=2025037772&meta=dmap.itemname,dmap.itemid,daap.songartist,daap.songalbum,dmap.containeritemid,com.apple.tunes.has-video return RequestHelper.requestParsed( String.format( "%s/databases/%d/containers/%s/items?session-id=%s&meta=dmap.itemname,dmap.itemid,daap.songartst,daap.songalbum,daap.songtime,dmap.containeritemid,com.apple.tunes.has-video", session.getRequestBase(), session.getDatabase().getItemId(), playlistid, session.getSessionId()), false); }
public ItemsContainer getAllTracks() throws Exception { // make tracks list request // http://192.168.254.128:3689/databases/36/containers/113/items?session-id=1301749047&meta=dmap.itemname,dmap.itemid,daap.songartist,daap.songalbum,daap.songalbum,daap.songtime,daap.songtracknumber&type=music&sort=album&query='daap.songalbumid:11624070975347817354' return RequestHelper.requestParsed( String.format( "%s/databases/%d/containers/%d/items?session-id=%s&meta=dmap.itemname,dmap.itemid,daap.songartist,daap.songalbum,daap.songalbum,daap.songtime,daap.songuserrating,daap.songtracknumber&type=music&sort=album", session.getRequestBase(), session.getDatabase().getItemId(), session.getDatabase().getMasterContainer().getItemId(), session.getSessionId()), false); }
/** * Reads the list of available speakers * * @return list of available speakers */ public List<Speaker> getSpeakers(final List<Speaker> speakers) { try { Log.d(TAG, "getSpeakers() requesting..."); String temp = String.format( "%s/ctrl-int/1/getspeakers?session-id=%s", session.getRequestBase(), session.sessionId); byte[] raw = RequestHelper.request(temp, false); Response response = ResponseParser.performParse(raw); Response casp = response.getNested("casp"); if (casp != null) { speakers.clear(); } List<Response> mdclArray = casp.findArray("mdcl"); // Master volume is required to compute the speakers' absolute volume long masterVolume = getVolume(); for (Response mdcl : mdclArray) { Speaker speaker = new Speaker(); speaker.setName(mdcl.getString("minm")); long id = mdcl.getNumberLong("msma"); speaker.setId(id); Log.d(TAG, "Speaker = " + speaker.getName()); int relativeVolume = (int) mdcl.getNumberLong("cmvo"); boolean isActive = mdcl.containsKey("caia"); speaker.setActive(isActive); // mastervolume/100 * relativeVolume/100 * 100 int absoluteVolume = isActive ? (int) masterVolume * relativeVolume / 100 : 0; speaker.setAbsoluteVolume(absoluteVolume); speakers.add(speaker); } } catch (Exception e) { Log.e(TAG, "Could not get speakers: ", e); speakers.clear(); Speaker speaker = new Speaker(); speaker.setName("Computer"); speaker.setId(1); speaker.setActive(true); speaker.setAbsoluteVolume(50); speakers.add(speaker); } return speakers; }
public AlbumSearchContainer getAlbums(String artist) throws Exception { final String encodedArtist = RequestHelper.escapeUrlString(artist); // make albums request for this artist // http://192.168.254.128:3689/databases/36/groups?session-id=1034286700&meta=dmap.itemname,dmap.itemid,dmap.persistentid,daap.songartist&type=music&group-type=albums&sort=artist&include-sort-headers=1 return RequestHelper.requestParsed( String.format( "%s/databases/%d/groups?session-id=%s&meta=dmap.itemname,dmap.itemid,dmap.persistentid,daap.songartist&type=music&group-type=albums&sort=artist&include-sort-headers=1&query='daap.songartist:%s'", session.getRequestBase(), session.getDatabase().getItemId(), session.getSessionId(), encodedArtist), false); }
public SongUserRating getTrackRating(long trackId) throws Exception { // MonkeyTunes style would be with PlaylistSongs instead of DatabaseSongs final DatabaseItems databaseSongs = RequestHelper.requestParsed( String.format( "%s/databases/%d/items?session-id=%s&meta=daap.songuserrating&type=music&query='dmap.itemid:%d'", session.getRequestBase(), session.getDatabase().getItemId(), session.getSessionId(), trackId)); final ListingItem listingItem = databaseSongs.getListing().getSingleListingItemContainingClass(SongUserRating.class); return listingItem.getSpecificChunk(SongUserRating.class); }
public byte[] getAlbumArtworkAsRemote(long itemId, int imageWidth, int imageHeight, String hsgid) throws Exception { return RequestHelper.requestBitmap( String.format( "%s/databases/%d/groups/%d/extra_data/artwork?session-id=%s&mw=" + imageWidth + "&mh=" + imageHeight + "&group-type=albums", session.getRequestBase(), session.getDatabase().getItemId(), itemId, session.getSessionId())); }
public long getVolume() { try { // http://192.168.254.128:3689/ctrl-int/1/getproperty?properties=dmcp.volume&session-id=130883770 Response resp = RequestHelper.requestParsed( String.format( "%s/ctrl-int/1/getproperty?properties=dmcp.volume&session-id=%s", session.getRequestBase(), session.sessionId), false); return resp.getNested("cmgt").getNumberLong("cmvo"); } catch (Exception e) { Log.e(TAG, "Fetch Volume Exception:" + e.getMessage()); } return -1; }
/** * Performs a search of the DACP Server sending it search criteria and an index of how many items * to find. * * <p> * * @param listener the TagListener to capture records coming in for the UI * @param search the search criteria * @param start items to start with for paging (usually 0) * @param items the total items to return in this search * @return the count of records returned or -1 if nothing found * @throws Exception */ public ItemsContainer readSearch(String search, long start, long items) throws Exception { final String encodedSearch = RequestHelper.escapeUrlString(search); // return // RequestHelper.requestParsed(String.format("%s/databases/%d/containers/%d/items?session-id=%s&meta=dmap.itemname,dmap.itemid,dmap.persistentid,daap.songartist,daap.songalbum,daap.songtime,daap.songuserrating,daap.songtracknumber&type=music&sort=name&include-sort-headers=1&query=(('com.apple.itunes.mediakind:1','com.apple.itunes.mediakind:4','com.apple.itunes.mediakind:8')+('dmap.itemname:*%s*','daap.songartist:*%s*','daap.songalbum:*%s*'))&index=%d-%d", session.getRequestBase(), session.getDatabase().getItemId(), session.getDatabase().getMasterContainer().getItemId(), session.getSessionId(), encodedSearch, encodedSearch, encodedSearch, start, items), false); return RequestHelper.requestParsed( String.format( "%s/databases/%d/containers/%d/items?session-id=%s&meta=all&type=music&sort=name&include-sort-headers=1&query=(('com.apple.itunes.mediakind:1','com.apple.itunes.mediakind:4','com.apple.itunes.mediakind:8')+('dmap.itemname:*%s*','daap.songartist:*%s*','daap.songalbum:*%s*'))&index=%d-%d", session.getRequestBase(), session.getDatabase().getItemId(), session.getDatabase().getMasterContainer().getItemId(), session.getSessionId(), encodedSearch, encodedSearch, encodedSearch, start, items), false); }
public ItemsContainer getRadioPlaylist(String playlistid) throws Exception { // GET /databases/24691/containers/24699/items? // meta=dmap.itemname,dmap.itemid,daap.songartist,daap.songalbum, // dmap.containeritemid,com.apple.itunes.has-video,daap.songdisabled, // com.apple.itunes.mediakind,daap.songdescription // &type=music&session-id=345827905 return RequestHelper.requestParsed( String.format( "%s/databases/%d/containers/%s/items?" + "meta=dmap.itemname,dmap.itemid,daap.songartist,daap.songalbum," + "dmap.containeritemid,com.apple.itunes.has-video,daap.songdisabled," + "com.apple.itunes.mediakind,daap.songdescription" + "&type=music&session-id=%s", session.getRequestBase(), session.getRadioDatabase().getItemId(), playlistid, session.getSessionId()), false); }