예제 #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
        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);
        }
예제 #3
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);
                }
            }
        }
예제 #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");
        }