public async Task GetPlaylistItemsIdsListNetAsync()
        {
            IEnumerable <string> res =
                await YouTubeSite.GetPlaylistItemsIdsListNetAsync("PLt2cGgt6G8WrItA7KTI5m6EFniMfphWJC", 0).ConfigureAwait(false);

            Assert.IsTrue(res.Any());
        }
        public static async Task UpdatePlaylist(IPlaylist playlist, IChannel selectedChannel)
        {
            switch (playlist.Site)
            {
            case SiteType.YouTube:

                HashSet <string> dbids         = selectedChannel.ChannelItems.Select(x => x.ID).ToHashSet();
                List <string>    plitemsIdsNet = await YouTubeSite.GetPlaylistItemsIdsListNetAsync(playlist.ID, 0).ConfigureAwait(false);

                List <string> ids = plitemsIdsNet.Where(netid => !playlist.PlItems.Contains(netid)).ToList();
                if (!ids.Any())
                {
                    return;
                }
                var lstInDb   = new List <string>();
                var lstNoInDb = new List <string>();
                foreach (string id in ids)
                {
                    if (dbids.Contains(id))
                    {
                        lstInDb.Add(id);
                    }
                    else
                    {
                        lstNoInDb.Add(id);
                    }
                }
                foreach (string id in lstInDb)
                {
                    await db.UpdatePlaylistAsync(playlist.ID, id, selectedChannel.ID).ConfigureAwait(false);

                    playlist.PlItems.Add(id);
                }

                IEnumerable <List <string> > chanks = lstNoInDb.SplitList();
                foreach (List <string> list in chanks)
                {
                    List <VideoItemPOCO> res = await YouTubeSite.GetVideosListByIdsAsync(list).ConfigureAwait(false);    // получим скопом

                    foreach (IVideoItem vi in res.Select(poco => VideoItemFactory.CreateVideoItem(poco, SiteType.YouTube)))
                    {
                        vi.SyncState = SyncState.Added;
                        if (vi.ParentID == selectedChannel.ID)
                        {
                            selectedChannel.AddNewItem(vi);
                            await db.InsertItemAsync(vi).ConfigureAwait(false);

                            await db.UpdatePlaylistAsync(playlist.ID, vi.ID, selectedChannel.ID).ConfigureAwait(false);
                        }
                        else
                        {
                            selectedChannel.ChannelItems.Add(vi);
                        }
                        playlist.PlItems.Add(vi.ID);
                    }
                }

                break;
            }
        }
        public async Task GetChannelRelatedPlaylistsNetAsync()
        {
            List <PlaylistPOCO> lst =
                await YouTubeSite.GetChannelRelatedPlaylistsNetAsync("UC0lT9K8Wfuc1KPqm6YjRf1A").ConfigureAwait(false);

            Assert.AreEqual(lst.Count(), 3);
        }
        public static async Task <IChannel> GetChannelNetAsync(string channelID, SiteType site)
        {
            ChannelPOCO poco = null;

            try
            {
                switch (site)
                {
                case SiteType.YouTube:
                    poco = await YouTubeSite.GetChannelFullNetAsync(channelID).ConfigureAwait(false);

                    break;

                case SiteType.RuTracker:
                    poco = await CommonFactory.CreateRutrackerSite().GetChannelNetAsync(channelID).ConfigureAwait(false);

                    break;

                case SiteType.Tapochek:
                    poco = await CommonFactory.CreateTapochekSite().GetChannelNetAsync(channelID).ConfigureAwait(false);

                    break;
                }
                IChannel channel = CreateChannel(poco);
                return(channel);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        private static async Task InsertNewItems(IEnumerable <string> trueIds,
                                                 IChannel channel,
                                                 string playlistId          = null,
                                                 ICollection <string> dbIds = null,
                                                 Action <IVideoItem, object> stateAction = null)
        {
            List <VideoItemPOCO> res = await YouTubeSite.GetVideosListByIdsAsync(trueIds).ConfigureAwait(true); // получим скопом

            IEnumerable <IVideoItem> result =
                res.Select(poco => VideoItemFactory.CreateVideoItem(poco, channel.Site, false, SyncState.Added))
                .Reverse()
                .Where(vi => vi.ParentID == channel.ID)
                .ToList();
            await db.InsertChannelItemsAsync(result).ConfigureAwait(false);

            foreach (IVideoItem vi in result)
            {
                channel.AddNewItem(vi);
                stateAction?.Invoke(vi, SyncState.Added);
                if (playlistId != null)
                {
                    await db.UpdatePlaylistAsync(playlistId, vi.ID, channel.ID).ConfigureAwait(false);
                }
                if (dbIds == null)
                {
                    continue;
                }
                if (!dbIds.Contains(vi.ID))
                {
                    dbIds.Add(vi.ID);
                }
            }
        }
        public static async Task <IEnumerable <IVideoItem> > GetChannelItemsNetAsync(IChannel channel, int maxresult)
        {
            var lst = new List <IVideoItem>();

            SiteType site = channel.Site;
            IEnumerable <VideoItemPOCO> res;

            switch (site)
            {
            case SiteType.YouTube:
                res = await YouTubeSite.GetChannelItemsAsync(channel.ID, maxresult).ConfigureAwait(true);

                break;

            case SiteType.Tapochek:
                res = await CommonFactory.CreateTapochekSite().GetChannelItemsAsync(channel, maxresult).ConfigureAwait(false);

                break;

            default:
                throw new Exception(EnumHelper.GetAttributeOfType(channel.Site) + " is not implemented yet");
            }

            lst.AddRange(res.Select(poco => VideoItemFactory.CreateVideoItem(poco, site)));
            return(lst);
        }
        public async Task GetPlaylistNetAsync()
        {
            PlaylistPOCO res = await YouTubeSite.GetPlaylistNetAsync("PLt2cGgt6G8WrItA7KTI5m6EFniMfphWJC").ConfigureAwait(false);

            Assert.AreEqual(res.Title, "Creating Windows Services");

            Assert.AreEqual(res.SubTitle, "How to create, install and deploy windows services.");
        }
        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 GetChannelIdByUserNameNetAsync()
        {
            string res = await YouTubeSite.GetChannelIdByUserNameNetAsync("mcmbmirussian").ConfigureAwait(false);

            Assert.AreEqual(res, "UCH0miwnqCojki-ado_lLI5A");

            res = await YouTubeSite.GetChannelIdByUserNameNetAsync("CarCrashCompilation7").ConfigureAwait(false);

            Assert.AreEqual("UCeXeMXzjt21uv5tonZHtOrA", res);
        }
        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 GetListVideoByIdsAsync()
        {
            var lst = new List <string> {
                "-wA6Qj4oF2E"
            };

            List <VideoItemPOCO> res = await YouTubeSite.GetVideosListByIdsAsync(lst).ConfigureAwait(false);

            Assert.AreEqual(res.Count(), 1);
        }
        public async Task SearchItemsAsync()
        {
            var testindex = new[] { 5 };

            foreach (int i in testindex)
            {
                List <VideoItemPOCO> lst = await YouTubeSite.SearchItemsAsync("russia", "RU", i).ConfigureAwait(false);

                Assert.AreEqual(lst.Count(), i);
            }
        }
        public async Task GetChannelItemsAsync()
        {
            // UCGtFbbGApG0s_8mMuJd-zKg = berestian
            // UCQoZVSaWvaJN046F-8SmyPg
            // UCq9B1wrqZKwucNkjHnUW39A
            const int count = 2;
            IEnumerable <VideoItemPOCO> lst =
                await YouTubeSite.GetChannelItemsAsync("UCGtFbbGApG0s_8mMuJd-zKg", count).ConfigureAwait(false);

            Assert.AreEqual(count, lst.Count());
        }
        public async Task GetVideoRateCountNetAsync()
        {
            var res = await YouTubeSite.GetVideoRateCountNetAsync(new List <string> {
                "lHgIpxQac3w", "-wA6Qj4oF2E"
            }).ConfigureAwait(false);

            Assert.IsTrue(res.Count == 2);
            var res1 = await YouTubeSite.GetVideoViewCountNetAsync("lHgIpxQac3w").ConfigureAwait(false);

            Assert.IsTrue(res[0].ViewCount == res1.ViewCount);
        }
        public async Task GetPopularItemsAsync()
        {
            // var testindex = new[] { 1, 2, 25, 26, 27, 49, 50, 51 };
            var testindex = new[] { 2 };

            foreach (int i in testindex)
            {
                List <VideoItemPOCO> lst = await YouTubeSite.GetPopularItemsAsync("ru", i).ConfigureAwait(false);

                Assert.AreEqual(lst.Count(), i);
            }
        }
        public static async Task <IEnumerable <IChannel> > GetRelatedChannelNetAsync(IChannel channel)
        {
            IEnumerable <ChannelPOCO> related = null;

            if (channel is YouChannel)
            {
                related = await YouTubeSite.GetRelatedChannelsByIdAsync(channel.ID).ConfigureAwait(true);
            }

            if (related != null)
            {
                return(related.Select(poco => CreateChannel(poco, channel.DirPath)));
            }
            throw new Exception(channel.ID);
        }
Exemple #17
0
        public static async Task <IEnumerable <ISubtitle> > GetVideoItemSubtitlesAsync(string id)
        {
            var res = new List <ISubtitle>();
            List <SubtitlePOCO> poco = await YouTubeSite.GetVideoSubtitlesByIdAsync(id).ConfigureAwait(false);

            res.AddRange(poco.Select(SubtitleFactory.CreateSubtitle));
            if (res.Any())
            {
                return(res);
            }
            ISubtitle chap = SubtitleFactory.CreateSubtitle();

            chap.IsEnabled = false;
            chap.Language  = "Auto";
            res.Add(chap);
            return(res);
        }
        public static async Task SyncChannelRatesAsync(IChannel channel)
        {
            var ids = new List <string>();

            switch (channel.Site)
            {
            case SiteType.NotSet:
                ids = channel.ChannelItems.Select(x => x.ID).ToList();
                break;

            case SiteType.YouTube:
                ids = await db.GetChannelItemsIdListDbAsync(channel.ID, 0, 0).ConfigureAwait(false);

                break;
            }
            IEnumerable <List <string> > chanks = ids.SplitList();

            foreach (List <string> list in chanks)
            {
                List <StatisticPOCO> items = await YouTubeSite.GetVideoRateCountNetAsync(list);

                foreach (StatisticPOCO itemp in items.Where(itemp => itemp.Filled))
                {
                    await db.UpdateItemRateCount(itemp.VideoId, itemp);

                    IVideoItem item = channel.ChannelItems.FirstOrDefault(x => x.ID == itemp.VideoId);
                    if (item == null)
                    {
                        continue;
                    }
                    if (itemp.ViewCount != item.ViewCount)
                    {
                        item.ViewDiff = itemp.ViewCount - item.ViewCount;
                    }
                    item.ViewCount               = itemp.ViewCount;
                    item.LikeCount               = itemp.LikeCount;
                    item.DislikeCount            = itemp.DislikeCount;
                    item.Comments                = itemp.CommentCount;
                    channel.ChannelViewCount    += item.ViewCount;
                    channel.ChannelLikeCount    += item.LikeCount;
                    channel.ChannelDislikeCount += item.DislikeCount;
                    channel.ChannelCommentCount += item.Comments;
                }
            }
        }
Exemple #19
0
        private async Task FillSubtitles()
        {
            if (Subtitles.Any())
            {
                return;
            }

            List <SubtitlePOCO> res = await YouTubeSite.GetVideoSubtitlesByIdAsync(youId).ConfigureAwait(false);

            if (res.Any())
            {
                Subtitles.Clear();
                foreach (ISubtitle sb in res.Select(SubtitleFactory.CreateSubtitle))
                {
                    Subtitles.Add(sb);
                }
            }
        }
Exemple #20
0
        public static async Task <IVideoItem> GetVideoItemNetAsync(string id, SiteType site)
        {
            try
            {
                VideoItemPOCO poco = null;
                switch (site)
                {
                case SiteType.YouTube:
                    poco = await YouTubeSite.GetVideoItemNetAsync(id).ConfigureAwait(false);

                    break;
                }
                IVideoItem vi = CreateVideoItem(poco, site);
                return(vi);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public async Task Search(Dictionary <string, string> dic)
        {
            if (string.IsNullOrEmpty(SearchKey))
            {
                return;
            }

            switch (SelectedSite.Cred.Site)
            {
            case SiteType.YouTube:

                if (SelectedCountry.Key == dlindex)
                {
                    SelectedCountry = Countries.First();
                }

                SelectedCountry.Value.Clear();

                List <VideoItemPOCO> lst = await YouTubeSite.SearchItemsAsync(SearchKey, SelectedCountry.Key, 50).ConfigureAwait(true);

                if (lst.Any())
                {
                    foreach (IVideoItem item in lst.Select(poco => VideoItemFactory.CreateVideoItem(poco, SiteType.YouTube)))
                    {
                        item.IsHasLocalFileFound(DirPath);
                        string title;
                        if (dic.TryGetValue(item.ParentID, out title))
                        {
                            // подсветим видео, если канал уже есть в подписке
                            item.SyncState   = SyncState.Added;
                            item.ParentTitle = title;
                            item.WatchState  = await db.GetItemWatchStateAsync(item.ID).ConfigureAwait(false);
                        }
                        SelectedCountry.Value.Add(item);
                    }
                    RefreshItems();
                }
                break;
            }
        }
        public async Task GetVideoCommentsNetAsync()
        {
            List <string> res = await YouTubeSite.GetVideoCommentsNetAsync("-wA6Qj4oF2E", 0).ConfigureAwait(false);

            Assert.IsTrue(res.Any());
        }
        public async Task GetChannelPlaylistNetAsync()
        {
            List <PlaylistPOCO> res = await YouTubeSite.GetChannelPlaylistsNetAsync("UCq9B1wrqZKwucNkjHnUW39A").ConfigureAwait(false);

            Assert.IsTrue(res.Any());
        }
        public async Task GetChannelNetAsync()
        {
            ChannelPOCO res = await YouTubeSite.GetChannelNetAsync("UCE27j85FZ8-aZOn6D8vWMWg").ConfigureAwait(false);

            Assert.AreEqual(res.Title, "Vlad RT");
        }
        public async Task GetChannelItemsIdsListNetAsync()
        {
            List <string> res = await YouTubeSite.GetChannelItemsIdsListNetAsync("UCE27j85FZ8-aZOn6D8vWMWg", 5).ConfigureAwait(false);

            Assert.AreEqual(res.Count(), 5);
        }
        public async Task GetChannelItemsCountNetAsync()
        {
            int res = await YouTubeSite.GetChannelItemsCountNetAsync("UCE27j85FZ8-aZOn6D8vWMWg").ConfigureAwait(false);

            Assert.AreEqual(res, 6);
        }
        public async Task GetRelatedChannelsByIdAsync()
        {
            List <ChannelPOCO> res = await YouTubeSite.GetRelatedChannelsByIdAsync("UCsNGRSN63gFoo5z6Oqv1A6A").ConfigureAwait(false);

            Assert.IsTrue(res.Any());
        }
        public async Task GetVideoSubtitlesByIdAsync()
        {
            List <SubtitlePOCO> res = await YouTubeSite.GetVideoSubtitlesByIdAsync("WaEcvDnbaIc").ConfigureAwait(false);

            Assert.IsTrue(res.Any());
        }
        public async Task GetVideoItemNetAsync()
        {
            VideoItemPOCO res = await YouTubeSite.GetVideoItemNetAsync("lHgIpxQac3w").ConfigureAwait(false); //

            Assert.AreEqual(res.Title, "Metallica — Unforgiven (FDM edition)");
        }
        public async Task GetVideoViewCountNetAsync()
        {
            var res = await YouTubeSite.GetVideoViewCountNetAsync("lHgIpxQac3w").ConfigureAwait(false);

            Assert.IsTrue(res.ViewCount > 0);
        }