public async Task GetPlaylistItemsCountNetAsync() { int res = await YouTubeSite.GetPlaylistItemsCountNetAsync("UU0lT9K8Wfuc1KPqm6YjRf1A").ConfigureAwait(false); int res2 = await YouTubeSite.GetChannelItemsCountNetAsync("UC0lT9K8Wfuc1KPqm6YjRf1A").ConfigureAwait(false); Assert.IsTrue(res == res2); }
public async Task GetFullChannel() { ChannelPOCO channel = await YouTubeSite.GetChannelFullNetAsync("UCeXeMXzjt21uv5tonZHtOrA").ConfigureAwait(false); int count = await YouTubeSite.GetChannelItemsCountNetAsync("UCeXeMXzjt21uv5tonZHtOrA").ConfigureAwait(false); Assert.IsTrue(channel.Items.Count == count); Assert.IsTrue(channel.Items.Any()); Assert.IsTrue(channel.Playlists.Any()); }
public async Task GetChannelItemsCountNetAsync() { int res = await YouTubeSite.GetChannelItemsCountNetAsync("UCE27j85FZ8-aZOn6D8vWMWg").ConfigureAwait(false); Assert.AreEqual(res, 6); }
public static async Task SyncChannelAsync(IChannel channel, bool isFastSync, bool isSyncPls = false, Action <IVideoItem, object> stateAction = null) { channel.ChannelState = ChannelState.InWork; if (channel is YouChannel) { string pluploadsid = YouChannel.MakePlaylistUploadId(channel.ID); // убираем признак предыдущей синхронизации List <IVideoItem> preds = channel.ChannelItems.Where(x => x.SyncState == SyncState.Added).ToList(); foreach (IVideoItem item in preds) { item.SyncState = SyncState.Notset; stateAction?.Invoke(item, SyncState.Notset); } if (channel.CountNew > 0) { channel.CountNew = 0; await db.UpdateItemSyncState(SyncState.Notset, SyncState.Added, channel.ID).ConfigureAwait(false); await db.UpdateChannelNewCountAsync(channel.ID, 0).ConfigureAwait(false); } // получаем списки id в базе и в нете List <string> netids; List <string> dbids; if (isFastSync) { // быстрая проверка if (channel.UseFast) { dbids = await db.GetChannelItemsIdListDbAsync(channel.ID, 0, 0, SyncState.Deleted).ConfigureAwait(false); int netcount = await YouTubeSite.GetChannelItemsCountNetAsync(channel.ID).ConfigureAwait(true); int resint = Math.Abs(netcount - dbids.Count) + 3; // буфер, можно регулировать netids = await YouTubeSite.GetPlaylistItemsIdsListNetAsync(pluploadsid, resint).ConfigureAwait(true); } else { // некоторые каналы хотим проверять жестко (добавляют, удаляют часто) dbids = await db.GetChannelItemsIdListDbAsync(channel.ID, 0, 0).ConfigureAwait(false); netids = await YouTubeSite.GetPlaylistItemsIdsListNetAsync(pluploadsid, 0).ConfigureAwait(true); await SetDeletedInDb(channel, dbids, netids); } } else { // полная проверка dbids = await db.GetChannelItemsIdListDbAsync(channel.ID, 0, 0).ConfigureAwait(false); netids = await YouTubeSite.GetPlaylistItemsIdsListNetAsync(pluploadsid, 0).ConfigureAwait(true); // проставляем в базе признак того, что видео больше нет на канале, а так же если видео было удалено, а теперь вернулось await SetDeletedInDb(channel, dbids, netids); } // cобираем новые List <string> trueids = netids.Where(netid => !dbids.Contains(netid)).ToList(); IEnumerable <List <string> > tchanks = trueids.SplitList(); foreach (List <string> list in tchanks) { List <VideoItemPOCO> trlist = await YouTubeSite.GetVideosListByIdsLiteAsync(list).ConfigureAwait(true); IEnumerable <string> trueIds = from poco in trlist where poco.ParentID == channel.ID select poco.ID; await InsertNewItems(trueIds, channel, null, dbids, stateAction).ConfigureAwait(true); } // обновим инфу о количестве новых после синхронизации if (channel.CountNew > 0) { await db.UpdateChannelNewCountAsync(channel.ID, channel.CountNew).ConfigureAwait(false); } // синхронизовать также плейлисты (двойной клик с UI по каналу) if (isSyncPls) { await SyncPlaylists(channel, dbids).ConfigureAwait(true); } int wnot = channel.ChannelItems.Count(x => x.WatchState != WatchState.Notset); int snot = channel.ChannelItems.Count(x => x.SyncState != SyncState.Notset); channel.IsHasNewFromSync = channel.ChannelItems.Any() && channel.ChannelItems.Count == wnot + snot + preds.Count; } channel.ChannelState = ChannelState.Notset; }