public async Task <List <Artist> > GetArtistsAsync() { if (_artists != null && _artistCacheRevision == Server.CurrentLibraryUpdateNumber) { return(_artists); } var query = DACPQueryCollection.And(DACPQueryPredicate.IsNotEmpty("daap.songartist"), MediaKindQuery); DACPRequest request = GetGroupsRequest(query, true, "artists"); try { var response = await Server.SubmitRequestAsync(request).ConfigureAwait(false); _groupedArtists = DACPUtility.GetAlphaGroupedDACPList(response.Nodes, n => new Artist(this, n), out _artists); _artistsByID = _artists.ToDictionary(a => a.ID); } catch { _artists = new List <Artist>(); _artistsByID = new Dictionary <int, Artist>(); _groupedArtists = new DACPList <Artist>(false); } _artistCacheRevision = Server.CurrentLibraryUpdateNumber; return(_artists); }
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> 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))); }
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 <List <Album> > GetAlbumsAsync() { var query = DACPQueryCollection.And(GroupQuery, Container.GroupsQuery); DACPRequest request = Container.GetGroupsRequest(query); return(Server.GetListAsync(request, n => new Album(Container, 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); }
internal DACPRequest GetComposersRequest(bool requestSortHeaders = false) { DACPRequest request = new DACPRequest("/databases/{0}/browse/composers", Database.ID); DACPQueryElement query = DACPQueryCollection.And(DACPQueryPredicate.IsNotEmpty("daap.songcomposer"), MediaKindQuery); request.QueryParameters["filter"] = query.ToString(); if (requestSortHeaders) { request.QueryParameters["include-sort-headers"] = "1"; } return(request); }
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 <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); } }
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 <bool> Shuffle() { DACPRequest request; if (Server.SupportsPlayQueue) { request = Database.GetPlayQueueEditRequest("add", GenreQuery, PlayQueueMode.Shuffle, "name"); } else { request = Database.GetCueShuffleRequest(DACPQueryCollection.And(GenreQuery, Container.MediaKindQuery), "name"); } try { await Server.SubmitRequestAsync(request).ConfigureAwait(false); } catch { return(false); } return(true); }
public async Task <bool> Play(PlayQueueMode mode = PlayQueueMode.Replace) { DACPRequest request; if (Server.SupportsPlayQueue) { request = Database.GetPlayQueueEditRequest("add", ComposerQuery, mode, "album"); } else { request = Database.GetCueSongRequest(DACPQueryCollection.And(ComposerQuery, Container.MediaKindQuery), "album", 0); } 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 <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))); }