Exemplo n.º 1
0
        public static IPlaylist CreatePlaylist(PlaylistPOCO poco, SiteType site)
        {
            if (poco == null)
            {
                return(null);
            }
            switch (site)
            {
            case SiteType.YouTube:
                var pl = new YouPlaylist
                {
                    ID        = poco.ID,
                    Title     = poco.Title,
                    SubTitle  = poco.SubTitle,
                    Thumbnail = poco.Thumbnail,
                    ChannelId = poco.ChannelID,
                    PlItems   = poco.PlaylistItems,
                    IsDefault = false
                };
                return(pl);

            default:
                return(null);
            }
        }
Exemplo n.º 2
0
        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.");
        }
Exemplo n.º 3
0
        private static async Task SyncPlaylists(IChannel channel, List <string> dbids)
        {
            List <string> plIdsNet = await YouTubeSite.GetChannelPlaylistsIdsNetAsync(channel.ID).ConfigureAwait(true);

            List <string> plIdsDb = await db.GetChannelsPlaylistsIdsListDbAsync(channel.ID).ConfigureAwait(false);

            foreach (string playlistId in plIdsDb)
            {
                if (plIdsNet.Contains(playlistId))
                {
                    // обновим плейлисты, которые есть уже в базе
                    List <string> plitemsIdsNet = await YouTubeSite.GetPlaylistItemsIdsListNetAsync(playlistId, 0).ConfigureAwait(true);

                    List <string> plitemsIdsDb = await db.GetPlaylistItemsIdsListDbAsync(playlistId).ConfigureAwait(false);

                    List <string> ids = plitemsIdsNet.Where(netid => !plitemsIdsDb.Contains(netid)).ToList();
                    if (!ids.Any())
                    {
                        continue;
                    }
                    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(playlistId, id, channel.ID).ConfigureAwait(false);
                    }

                    IEnumerable <List <string> > chanks = lstNoInDb.SplitList();
                    foreach (List <string> list in chanks)
                    {
                        List <VideoItemPOCO> trlist = await YouTubeSite.GetVideosListByIdsLiteAsync(list).ConfigureAwait(true);

                        List <string> trueIds = (from poco in trlist where poco.ParentID == channel.ID select poco.ID).ToList();
                        if (!trueIds.Any())
                        {
                            continue;
                        }

                        // странный вариант, через аплоад видео не пришло, а через плейлист - есть, но оставим
                        await InsertNewItems(trueIds, channel, playlistId).ConfigureAwait(true);
                    }
                }
                else
                {
                    // просто удалим уже не существующий в инете плейлист из базы
                    await db.DeletePlaylistAsync(playlistId).ConfigureAwait(false);
                }
            }

            // новые плейлисты
            foreach (string playlistId in plIdsNet.Where(playlistId => !plIdsDb.Contains(playlistId)))
            {
                PlaylistPOCO plpoco = await YouTubeSite.GetPlaylistNetAsync(playlistId).ConfigureAwait(true);

                List <string> plpocoitems = await YouTubeSite.GetPlaylistItemsIdsListNetAsync(playlistId, 0).ConfigureAwait(true);

                plpoco.PlaylistItems.AddRange(plpocoitems);
                IPlaylist pl = PlaylistFactory.CreatePlaylist(plpoco, channel.Site);
                pl.State = SyncState.Added;
                channel.ChannelPlaylists.Add(pl);
                channel.PlaylistCount += 1;
                await db.InsertPlaylistAsync(pl).ConfigureAwait(false);

                dbids = await db.GetChannelItemsIdListDbAsync(channel.ID, 0, 0).ConfigureAwait(false);

                List <string> ids = plpocoitems.Where(netid => !dbids.Contains(netid)).ToList();
                IEnumerable <List <string> > chanks = ids.SplitList();
                foreach (List <string> trueIds in chanks)
                {
                    await InsertNewItems(trueIds, channel, playlistId).ConfigureAwait(true);
                }

                foreach (string plpocoitem in plpocoitems)
                {
                    await db.UpdatePlaylistAsync(pl.ID, plpocoitem, channel.ID).ConfigureAwait(false);
                }
            }
        }