public Task AddLivestream(ChannelIdentifier channelIdentifier, IViewAware viewAware) { if (channelIdentifier == null) { throw new ArgumentNullException(nameof(channelIdentifier)); } Livestreams.Add(new LivestreamModel(channelIdentifier.ChannelId, channelIdentifier)); return(Task.CompletedTask); }
public Task RemoveLivestream(ChannelIdentifier channelIdentifier) { if (channelIdentifier == null) { throw new ArgumentNullException(nameof(channelIdentifier)); } var matchingLivestreams = Livestreams.Where(x => Equals(channelIdentifier, x.ChannelIdentifier)).ToList(); Livestreams.RemoveRange(matchingLivestreams); return(Task.CompletedTask); }
public async Task RemoveLivestream(ChannelIdentifier channelIdentifier) { if (channelIdentifier == null) { return; } await channelIdentifier.ApiClient.RemoveChannel(channelIdentifier); channelIdentifiers.Remove(channelIdentifier); // TODO - if removal of a channel would remove more than 1 livestream, consider warning the user var matchingLivestreams = Livestreams.Where(x => Equals(channelIdentifier, x.ChannelIdentifier)).ToList(); Livestreams.RemoveRange(matchingLivestreams); SaveLivestreams(); }
public async Task AddLivestream(ChannelIdentifier channelIdentifier, IViewAware viewAware) { if (channelIdentifier == null) { throw new ArgumentNullException(nameof(channelIdentifier)); } if (channelIdentifiers.Contains(channelIdentifier)) { return; // ignore duplicate requests } var livestreamQueryResults = await channelIdentifier.ApiClient.AddChannel(channelIdentifier); livestreamQueryResults.EnsureAllQuerySuccess(); AddChannels(channelIdentifier); Livestreams.AddRange(livestreamQueryResults.Select(x => x.LivestreamModel)); }
private async Task PopulateDisplayNames(List <LivestreamFileEntry> fileEntries) { var groupedLivestreams = fileEntries.Where(x => x.StreamProvider != TwitchApiClient.API_NAME).GroupBy(x => x.StreamProvider); foreach (var groupedLivestream in groupedLivestreams) { var tempChannels = new List <ChannelIdentifier>(); var apiClient = apiClientFactory.GetByName(groupedLivestream.Key); foreach (var entry in groupedLivestream) { var channelId = new ChannelIdentifier(apiClient, entry.ChannelId) { DisplayName = entry.DisplayName, ImportedBy = entry.ImportedBy }; apiClient.AddChannelWithoutQuerying(channelId); tempChannels.Add(channelId); } var queriedChannels = await apiClient.QueryChannels(CancellationToken.None); foreach (var entry in groupedLivestream) { var matchingChannel = queriedChannels.FirstOrDefault(x => x.ChannelIdentifier.ChannelId.IsEqualTo(entry.ChannelId)); if (matchingChannel != null) { entry.DisplayName = matchingChannel.LivestreamModel.DisplayName; } else { fileEntries.Remove(entry); // will have to be manually re-imported, most likely the channel has been removed/banned } } tempChannels.ForEach(x => apiClient.RemoveChannel(x)); } }
protected bool Equals(ChannelIdentifier other) { return(ChannelId.IsEqualTo(other.ChannelId) && Equals(ApiClient, other.ApiClient)); }