Пример #1
0
        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;
            }
        }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        public static IChannel CreateChannel(ChannelPOCO poco, string dirPath = null)
        {
            SiteType site    = poco.Site;
            IChannel channel = null;

            switch (site)
            {
            case SiteType.YouTube:

                channel = new YouChannel
                {
                    ID        = poco.ID,
                    Title     = poco.Title,
                    SubTitle  = poco.SubTitle,    // .WordWrap(80);
                    Thumbnail = poco.Thumbnail,
                    CountNew  = poco.Countnew,
                    UseFast   = poco.UseFast
                };

                if (poco.Items != null)
                {
                    foreach (VideoItemPOCO item in poco.Items)
                    {
                        channel.AddNewItem(VideoItemFactory.CreateVideoItem(item, site));
                    }
                }

                if (poco.Playlists != null)
                {
                    foreach (PlaylistPOCO playlist in poco.Playlists)
                    {
                        channel.ChannelPlaylists.Add(PlaylistFactory.CreatePlaylist(playlist, site));
                    }
                }

                break;

            case SiteType.RuTracker:
                channel = null;
                break;

            case SiteType.Tapochek:
                channel = null;
                break;
            }

            if (channel == null)
            {
                throw new Exception(poco.ID);
            }

            if (dirPath != null)
            {
                channel.DirPath = dirPath;
            }
            channel.ChannelItemsCollectionView = CollectionViewSource.GetDefaultView(channel.ChannelItems);
            return(channel);
        }
Пример #5
0
        public static async void FillChannelItemsFromDbAsync(IChannel channel, int basePage, List <string> excepted = null)
        {
            List <VideoItemPOCO> items =
                await Task.Run(() => db.GetChannelItemsBaseAsync(channel.ID, basePage, excepted)).ConfigureAwait(true);

            foreach (VideoItemPOCO poco in items)
            {
                IVideoItem vi = VideoItemFactory.CreateVideoItem(poco, channel.Site);
                vi.IsHasLocalFileFound(channel.DirPath);
                channel.AddNewItem(vi, false, false);
            }
            channel.RefreshView("Timestamp");
        }
Пример #6
0
        public static async Task SyncChannelPlaylistsAsync(IChannel channel)
        {
            switch (channel.Site)
            {
            case SiteType.YouTube:

                List <PlaylistPOCO> fbres = await YouTubeSite.GetChannelPlaylistsNetAsync(channel.ID).ConfigureAwait(true);

                var pls = new List <IPlaylist>();
                pls.AddRange(fbres.Select(poco => PlaylistFactory.CreatePlaylist(poco, channel.Site)));
                if (pls.Any())
                {
                    List <string> ids = await db.GetChannelItemsIdListDbAsync(channel.ID, 0, 0).ConfigureAwait(false);

                    await db.DeleteChannelPlaylistsAsync(channel.ID).ConfigureAwait(false);

                    channel.ChannelPlaylists.Clear();
                    channel.PlaylistCount = pls.Count;
                    foreach (IPlaylist playlist in pls)
                    {
                        await db.InsertPlaylistAsync(playlist).ConfigureAwait(false);

                        List <string> plv = await YouTubeSite.GetPlaylistItemsIdsListNetAsync(playlist.ID, 0).ConfigureAwait(true);

                        foreach (string id in plv)
                        {
                            if (ids.Contains(id))
                            {
                                await db.UpdatePlaylistAsync(playlist.ID, id, channel.ID).ConfigureAwait(false);

                                if (!playlist.PlItems.Contains(id))
                                {
                                    playlist.PlItems.Add(id);
                                }
                            }
                            else
                            {
                                IVideoItem item = await VideoItemFactory.GetVideoItemNetAsync(id, channel.Site).ConfigureAwait(false);

                                if (item.ParentID != channel.ID)
                                {
                                    continue;
                                }

                                channel.AddNewItem(item);
                                await db.InsertItemAsync(item).ConfigureAwait(false);

                                await db.UpdatePlaylistAsync(playlist.ID, item.ID, channel.ID).ConfigureAwait(false);

                                if (!playlist.PlItems.Contains(id))
                                {
                                    playlist.PlItems.Add(id);
                                }
                            }
                        }
                        channel.ChannelPlaylists.Add(playlist);
                    }
                }
                break;
            }
        }