public async Task <List <Album> > GetAlbumsAsync() { if (_albums != null && _albumCacheRevision == Server.CurrentLibraryUpdateNumber) { return(_albums); } DACPRequest request = GetGroupsRequest(GroupsQuery, true); try { var response = await Server.SubmitRequestAsync(request).ConfigureAwait(false); _groupedAlbums = DACPUtility.GetAlphaGroupedDACPList(response.Nodes, n => new Album(this, n), out _albums); _albumsByID = _albums.ToDictionary(a => a.ID); } catch { _albums = new List <Album>(); _albumsByID = new Dictionary <int, Album>(); _groupedAlbums = new DACPList <Album>(false); } _albumCacheRevision = Server.CurrentLibraryUpdateNumber; return(_albums); }
public async Task <IDACPList> GetGroupedComposersAsync() { if (_groupedComposers != null) { return(_groupedComposers); } DACPRequest request = GetComposersRequest(true); try { var response = await Server.SubmitRequestAsync(request).ConfigureAwait(false); // iTunes returns an "abcp" node with "mlit" list items that only contain the composer name if (response.Nodes.Any(n => n.Key == "abcp")) { _groupedComposers = DACPUtility.GetAlphaGroupedDACPList(response.Nodes, d => new DACPComposer(this, (byte[])d), "abcp"); } // Apple TV returns an "mlcl" node with "mlit" items that contain an ID, persistent ID, and name else { _groupedComposers = DACPUtility.GetAlphaGroupedDACPList(response.Nodes, n => new DACPComposer(this, (DACPNodeDictionary)n)); } } catch { _groupedComposers = new DACPList <DACPComposer>(false); } return(_groupedComposers); }
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 async Task <bool> RequestStationsAsync() { DACPRequest request = new DACPRequest("/databases/{0}/containers", ID); request.QueryParameters["meta"] = "dmap.itemname,dmap.itemid,com.apple.itunes.cloud-id,dmap.downloadstatus,dmap.persistentid,daap.baseplaylist,com.apple.itunes.special-playlist,com.apple.itunes.smart-playlist,com.apple.itunes.saved-genius,dmap.parentcontainerid,dmap.editcommandssupported,com.apple.itunes.jukebox-current,daap.songcontentdescription,dmap.haschildcontainers"; try { var response = await Server.SubmitRequestAsync(request).ConfigureAwait(false); var containers = DACPUtility.GetItemsFromNodes(response.Nodes, n => DACPContainer.GetContainer(this, n)); List <iTunesRadioStation> newStations = new List <iTunesRadioStation>(); List <iTunesRadioStation> newFeaturedStations = new List <iTunesRadioStation>(); // There is a property (aeRf) that indicates whether a station is a "featured" station, but in some cases // featured stations may not have this property set to "true". // For now, checking the index of the last "featured" station as a workaround. int lastFeaturedStationIndex = 0; var stations = containers.Where(c => c.Type == ContainerType.iTunesRadio).Select(c => (iTunesRadioStation)c).ToArray(); for (int i = 0; i < stations.Length; i++) { if (stations[i].IsFeaturedStation) { lastFeaturedStationIndex = i; } } for (int i = 0; i < stations.Length; i++) { if (i <= lastFeaturedStationIndex) { newFeaturedStations.Add(stations[i]); } else { newStations.Add(stations[i]); } } Stations = newStations; FeaturedStations = newFeaturedStations; } catch (Exception e) { Stations = new List <iTunesRadioStation>(); FeaturedStations = new List <iTunesRadioStation>(); Server.HandleHTTPException(request, e); 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); } }
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 async Task <bool> RequestContainersAsync() { DACPRequest request = new DACPRequest("/databases/{0}/containers", ID); request.QueryParameters["meta"] = "dmap.itemname,dmap.itemid,com.apple.itunes.cloud-id,dmap.downloadstatus,dmap.persistentid,daap.baseplaylist,com.apple.itunes.special-playlist,com.apple.itunes.smart-playlist,com.apple.itunes.saved-genius,dmap.parentcontainerid,dmap.editcommandssupported,com.apple.itunes.jukebox-current,daap.songcontentdescription,dmap.haschildcontainers"; try { var response = await Server.SubmitRequestAsync(request).ConfigureAwait(false); var containers = DACPUtility.GetItemsFromNodes(response.Nodes, n => DACPContainer.GetContainer(this, n)); List <Playlist> newPlaylists = new List <Playlist>(); List <Playlist> newParentPlaylists = new List <Playlist>(); List <GeniusMix> newGeniusMixes = new List <GeniusMix>(); foreach (DACPContainer container in containers) { if (container.BasePlaylist) { BasePlaylist = container; if (Server.IsAppleTV && container is MusicContainer) { MusicContainer = (MusicContainer)container; } continue; } switch (container.Type) { case ContainerType.Playlist: newPlaylists.Add((Playlist)container); if (container.ParentContainerID == 0) { newParentPlaylists.Add((Playlist)container); } break; case ContainerType.Music: MusicContainer = (MusicContainer)container; break; case ContainerType.Movies: MoviesContainer = (MoviesContainer)container; break; case ContainerType.TVShows: TVShowsContainer = (TVShowsContainer)container; break; case ContainerType.Podcasts: PodcastsContainer = (PodcastsContainer)container; break; case ContainerType.iTunesU: iTunesUContainer = (iTunesUContainer)container; break; case ContainerType.Books: BooksContainer = (BooksContainer)container; break; case ContainerType.Purchased: break; case ContainerType.Rentals: break; case ContainerType.GeniusMixes: break; case ContainerType.GeniusMix: newGeniusMixes.Add((GeniusMix)container); break; default: break; } } Playlists = newPlaylists; ParentPlaylists = newParentPlaylists; GeniusMixes = newGeniusMixes; } catch (Exception e) { Server.HandleHTTPException(request, e); return(false); } return(true); }
public override string ToString() { return("'" + _key + _operator + Uri.EscapeDataString(DACPUtility.EscapeSingleQuotes(_value)) + "'"); }
public DACPGenre(DACPContainer container, byte[] data) : this(container, DACPUtility.GetStringValue(data)) { }
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); }