public async Task <bool> PlaySong(Song song, PlayQueueMode mode = PlayQueueMode.Replace) { DACPRequest request; if (Server.SupportsPlayQueue) { object songID; if (Server.IsAppleTV) { songID = song.PersistentID; } else { songID = song.ID; } request = Database.GetPlayQueueEditRequest("add", DACPQueryPredicate.Is("dmap.itemid", songID), mode, "album"); request.QueryParameters["queuefilter"] = string.Format("album:{0}", PersistentID); } else { var songs = await GetSongsAsync(); int index = songs.FindIndex(s => s.ID == song.ID); if (index < 0) { return(false); } request = Database.GetCueSongRequest(ItemQuery, "album", index); } try { await Server.SubmitRequestAsync(request).ConfigureAwait(false); } catch { return(false); } return(true); }
public Task <IDACPList> GetGenreArtistsAsync(string genreName) { var query = DACPQueryCollection.And(DACPQueryPredicate.Is("daap.songgenre", genreName), DACPQueryPredicate.IsNotEmpty("daap.songartist"), MediaKindQuery); DACPRequest request = GetGroupsRequest(query, true, "artists"); return(Server.GetAlphaGroupedListAsync(request, n => new Artist(this, n))); }
public Task <IDACPList> GetUnwatchedMoviesAsync() { var query = DACPQueryCollection.And(DACPQueryPredicate.Is("daap.songuserplaycount", 0), MediaKindQuery); DACPRequest request = GetItemsRequest(query, "name", true); return(Server.GetAlphaGroupedListAsync(request, n => new Movie(this, n))); }
public async Task <bool> PlayItem(DACPItem item, PlayQueueMode mode = PlayQueueMode.Replace) { DACPRequest request; if (Server.SupportsPlayQueue) { request = Database.GetPlayQueueEditRequest("add", DACPQueryPredicate.Is("dmap.itemid", item.ID), mode, "name"); request.QueryParameters["queuefilter"] = string.Format("genre:{0}", Uri.EscapeDataString(DACPUtility.EscapeSingleQuotes(Name))); } else { var items = await GetItemsAsync(); int index = items.FindIndex(i => i.ID == item.ID); if (index < 0) { return(false); } request = Database.GetCueSongRequest(DACPQueryCollection.And(GenreQuery, Container.MediaKindQuery), "name", index); } try { await Server.SubmitRequestAsync(request).ConfigureAwait(false); } catch { return(false); } return(true); }
public Task <IDACPList> GetGenreSongsAsync(string genreName) { var query = DACPQueryCollection.And(DACPQueryPredicate.Is("daap.songgenre", genreName), MediaKindQuery); DACPRequest request = GetItemsRequest(query, "name", true); return(Server.GetAlphaGroupedListAsync(request, n => new Song(this, n))); }
protected async Task <bool> UpdateCurrentSongUserRatingAsync() { // Make sure we have all the values we need if (CurrentDatabaseID == 0 || CurrentContainerID == 0 || CurrentItemID == 0 || CurrentAlbumPersistentID == 0) { ClearCurrentSongUserRating(); return(true); } // Make sure this is for the main DB if (!ShowUserRating || MainDatabase == null || CurrentDatabaseID != MainDatabase.ID) { ClearCurrentSongUserRating(); return(true); } // If we're requesting the rating for a new song, clear out the old value if (CurrentItemID != _ratingUpdatedForSongID) { ClearCurrentSongUserRating(); } DACPRequest request = new DACPRequest("/databases/{0}/containers/{1}/items", CurrentDatabaseID, CurrentContainerID); request.QueryParameters["meta"] = "dmap.itemid,dmap.containeritemid,daap.songuserrating"; request.QueryParameters["type"] = "music"; request.QueryParameters["sort"] = "album"; var query = DACPQueryCollection.And(DACPQueryPredicate.Is("daap.songalbumid", CurrentAlbumPersistentID), DACPQueryPredicate.Is("dmap.itemid", CurrentItemID)); request.QueryParameters["query"] = query.ToString(); try { var response = await SubmitRequestAsync(request).ConfigureAwait(false); var mlcl = response.Nodes.First(n => n.Key == "mlcl"); var songNodes = DACPUtility.GetResponseNodes(mlcl.Value); foreach (var songData in songNodes) { var nodes = DACPNodeDictionary.Parse(songData.Value); var id = nodes.GetInt("miid"); if (id != CurrentItemID) { continue; } var rating = nodes.GetByte("asur"); SetCurrentSongUserRatingFromServer(rating); break; } } catch { ClearCurrentSongUserRating(); return(false); } return(true); }
public async Task <bool> PlayQueue(PlayQueueMode mode = PlayQueueMode.Replace) { var query = DACPQueryPredicate.Is("dmap.itemid", ID); DACPRequest request = Database.GetPlayQueueEditRequest("add", query, mode); try { await Server.SubmitRequestAsync(request).ConfigureAwait(false); } catch { return(false); } return(true); }
private DACPRequest GetPlaySpecRequest() { DACPRequest request = new DACPRequest("/ctrl-int/1/playspec"); request.QueryParameters["database-spec"] = DACPQueryPredicate.Is("dmap.persistentid", "0x" + Database.PersistentID.ToString("x16")).ToString(); request.QueryParameters["container-spec"] = DACPQueryPredicate.Is("dmap.persistentid", "0x" + PersistentID.ToString("x16")).ToString(); return(request); }
public async Task <bool> Play() { DACPRequest request = new DACPRequest("/ctrl-int/1/playspec"); request.QueryParameters["database-spec"] = DACPQueryPredicate.Is("dmap.itemid", "0x" + Database.ID.ToString("x")).ToString(); request.QueryParameters["container-spec"] = DACPQueryPredicate.Is("dmap.itemid", "0x" + ID.ToString("x")).ToString(); try { await Server.SubmitRequestAsync(request).ConfigureAwait(false); } catch { return(false); } return(true); }
public async Task <bool> PlaySong(Song song) { try { int index = IndexOf(song); DACPQueryElement query = DACPQueryCollection.And(DACPQueryPredicate.Is("dmap.itemname", _searchString), Database.MusicContainer.MediaKindQuery); DACPRequest request = Database.GetCueSongRequest(query, "name", index); await Database.Server.SubmitRequestAsync(request).ConfigureAwait(false); } catch { return(false); } return(true); }
public async Task <List <Audiobook> > SearchAudiobooksAsync(string searchString, CancellationToken cancellationToken) { DACPQueryElement query = DACPQueryCollection.And(DACPQueryPredicate.Is("daap.songalbum", searchString), MediaKindQuery); DACPRequest request = GetGroupsRequest(query, false, "albums"); request.CancellationToken = cancellationToken; try { var response = await Server.SubmitRequestAsync(request).ConfigureAwait(false); return(DACPUtility.GetItemsFromNodes(response.Nodes, n => new Audiobook(this, n)).ToList()); } catch { return(null); } }
public async Task <List <Song> > SearchSongsAsync(string searchString, CancellationToken cancellationToken) { DACPQueryElement query = DACPQueryCollection.And(DACPQueryPredicate.Is("dmap.itemname", searchString), MediaKindQuery); DACPRequest request = GetItemsRequest(query, "name", false); request.CancellationToken = cancellationToken; try { var response = await Server.SubmitRequestAsync(request).ConfigureAwait(false); return(DACPUtility.GetItemsFromNodes(response.Nodes, n => new Song(this, n)).ToList()); } catch { return(null); } }
protected async Task <bool> SetUserRatingAsync(int rating, int songID) { DACPRequest request = new DACPRequest("/ctrl-int/1/setproperty"); request.QueryParameters["dacp.userrating"] = rating.ToString(); request.QueryParameters["database-spec"] = DACPQueryPredicate.Is("dmap.persistentid", "0x" + CurrentDatabaseID.ToString("x16")).ToString(); request.QueryParameters["item-spec"] = DACPQueryPredicate.Is("dmap.itemid", "0x" + songID.ToString("x")).ToString(); try { await SubmitRequestAsync(request).ConfigureAwait(false); } catch { return(false); } return(true); }
public async Task <bool> SendiTunesRadioNeverPlayThisSongAsync() { if (!IsCurrentlyPlayingiTunesRadio) { return(false); } DACPRequest request = new DACPRequest("/ctrl-int/1/setproperty"); request.QueryParameters["com.apple.itunes.liked-state"] = "3"; request.QueryParameters["database-spec"] = DACPQueryPredicate.Is("dmap.itemid", "0x" + CurrentDatabaseID.ToString("x")).ToString(); request.QueryParameters["item-spec"] = DACPQueryPredicate.Is("dmap.itemid", "0x" + CurrentItemID.ToString("x")).ToString(); try { await SubmitRequestAsync(request); } catch { return(false); } return(true); }
public async Task <bool> ShuffleAllSongsAsync() { DACPRequest request; if (Server.SupportsPlayQueue) { request = Database.GetPlayQueueEditRequest("add", DACPQueryPredicate.Is("dmap.itemid", ID), PlayQueueMode.Shuffle, "name"); request.QueryParameters["query-modifier"] = "containers"; } else { request = Database.GetCueShuffleRequest(MediaKindQuery, "artist"); } try { await Server.SubmitRequestAsync(request).ConfigureAwait(false); } catch { return(false); } return(true); }
public async Task <bool> PlayItem(DACPItem item, PlayQueueMode mode = PlayQueueMode.Replace) { DACPRequest request; if (Server.SupportsPlayQueue) { var query = DACPQueryPredicate.Is("dmap.containeritemid", item.ContainerItemID); request = Database.GetPlayQueueEditRequest("add", query, mode, "physical"); request.QueryParameters["queuefilter"] = string.Format("playlist:{0}", ID); } else { request = GetPlaySpecRequest(); request.QueryParameters["container-item-spec"] = DACPQueryPredicate.Is("dmap.containeritemid", "0x" + item.ContainerItemID.ToString("x8")).ToString(); } try { await Server.SubmitRequestAsync(request).ConfigureAwait(false); } catch { return(false); } return(true); }
public async Task <IDACPList> GetGroupedItemsAsync() { if (_groupedItems != null) { return(_groupedItems); } var query = DACPQueryCollection.And(DACPQueryPredicate.Is("daap.songcomposer", Name), Container.MediaKindQuery); DACPRequest request = Container.GetItemsRequest(query, "album", false); try { var response = await Server.SubmitRequestAsync(request).ConfigureAwait(false); var items = DACPUtility.GetItemsFromNodes(response.Nodes, n => new DACPItem(Container, n)).ToList(); ItemGroup <DACPItem> currentGroup = null; DACPList <ItemGroup <DACPItem> > result = new DACPList <ItemGroup <DACPItem> >(true); foreach (var item in items) { if (currentGroup == null || currentGroup.Key != item.AlbumName) { currentGroup = new ItemGroup <DACPItem>(item.AlbumName); result.Add(currentGroup); } currentGroup.Add(item); } _items = items; _groupedItems = result; } catch { _items = new List <DACPItem>(); _groupedItems = new DACPList <DACPItem>(false); } return(_groupedItems); }
public async Task <bool> Play(PlayQueueMode mode = PlayQueueMode.Replace) { if (!Server.SupportsPlayQueue) { // Send a play request for the first item in this playlist var items = await GetItemsAsync(); if (items == null || items.Count == 0) { return(false); } return(await PlayItem(items[0], mode).ConfigureAwait(false)); } var query = DACPQueryPredicate.Is("dmap.itemid", ID); DACPRequest request = Database.GetPlayQueueEditRequest("add", query, mode); request.QueryParameters["query-modifier"] = "containers"; try { await Server.SubmitRequestAsync(request).ConfigureAwait(false); } catch { return(false); } return(true); }
public async Task <IDACPList> GetGroupedItemsAsync() { if (_groupedItems != null) { return(_groupedItems); } var query = DACPQueryCollection.And(DACPQueryPredicate.Is("daap.songgenre", Name), Container.MediaKindQuery); DACPRequest request = Container.GetItemsRequest(query, "name", true); try { var response = await Server.SubmitRequestAsync(request).ConfigureAwait(false); _groupedItems = DACPUtility.GetAlphaGroupedDACPList(response.Nodes, n => new DACPItem(Container, n), out _items); } catch { _items = new List <DACPItem>(); _groupedItems = new DACPList <DACPItem>(false); } return(_groupedItems); }
public Task <List <Podcast> > GetUnplayedShowsAsync() { var query = DACPQueryCollection.And(DACPQueryPredicate.Is("daap.songuserplaycount", 0), GroupsQuery); return(GetGroupsAsync(query, n => new Podcast(this, n))); }
public Task <List <iTunesUCourse> > GetUnplayedCoursesAsync() { var query = DACPQueryCollection.And(DACPQueryPredicate.Is("daap.songuserplaycount", 0), GroupsQuery); return(GetGroupsAsync(query, n => new iTunesUCourse(this, n))); }