public void AddNewItem(IVideoItem item, bool isIncrease = true, bool isUpdateCount = true) { if (item == null) { throw new ArgumentException("item"); } item.ParentTitle = Title; if (item.SyncState == SyncState.Added) { ChannelItems.Insert(0, item); if (isIncrease) { CountNew += 1; } } else { ChannelItems.Add(item); } if (isUpdateCount) { ChannelItemsCount += 1; } }
public void AddNewItem(IVideoItem item, bool isIncrease = true, bool isUpdateCount = true) { if (item == null) { throw new ArgumentException("item"); } if (item.ParentTitle == null) { item.ParentTitle = item.ParentID; } if (ChannelItems.Select(x => x.ID).Contains(item.ID)) { ChannelItems.Remove(ChannelItems.First(x => x.ID == item.ID)); } item.FileState = ItemState.LocalNo; if (item.SyncState == SyncState.Added) { ChannelItems.Insert(0, item); } else { ChannelItems.Add(item); } }
public void DeleteItem(IVideoItem item) { IVideoItem el = ChannelItems.FirstOrDefault(x => x.ID == item.ID); if (el != null) { ChannelItems.Remove(el); } }
public NoVideoSourceProvider(LanguageManager Loc, IIconSet Icons) : base(Loc) { Sources = new IVideoItem[] { WaveItem.Instance } .Concat(FFmpegAudioItem.Items) .ToArray(); Icon = Icons.NoVideo; }
public void DeleteItem(IVideoItem item) { if (item == null) { throw new ArgumentException("item"); } ChannelItems.Remove(item); }
public void AddItemToDownload(IVideoItem item) { SelectedCountry = Countries.First(x => x.Key == dlindex); if (!SelectedCountry.Value.Select(x => x.ID).Contains(item.ID)) { SelectedCountry.Value.Add(item); } RefreshItems(); }
private static async void FillTestChannel(IChannel ch, IVideoItem v1, IVideoItem v2) { ch.ChannelItems = new ObservableCollection <IVideoItem>(); ch.ID = "testch"; ch.Title = "тестовая канал, для отладки слоя бд"; ch.SubTitle = "использутеся для отдладки :)"; ch.Thumbnail = await SiteHelper.GetStreamFromUrl(null).ConfigureAwait(false); ch.ChannelItems.Add(v1); ch.ChannelItems.Add(v2); }
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"); }
public void AddNewItem(IVideoItem item, bool isIncrease = true, bool isUpdateCount = true) { if (ChannelItems.Contains(item)) { return; } item.IsHasLocalFileFound(DirPath); ChannelItems.Insert(0, item); if (isUpdateCount) { ChannelItemsCount += 1; } }
private static async void FillTestVideoItem(IVideoItem vi, SyncState state) { vi.ID = "vi"; vi.ParentID = "testch"; vi.Title = "отдельный итем"; vi.Description = "для отладки"; vi.ViewCount = 123; vi.Duration = 321; vi.Comments = 123; vi.Thumbnail = await SiteHelper.GetStreamFromUrl(null).ConfigureAwait(false); vi.Timestamp = DateTime.Now; vi.SyncState = state; vi.WatchState = WatchState.Notset; }
public void DeleteItem(IVideoItem item) { if (item == null) { throw new ArgumentException("item"); } ChannelItems.Remove(item); ChannelItemsCount -= 1; if (item.SyncState == SyncState.Added) { CountNew -= 1; } }
private async void DownloadLink(object obj) { var window = obj as Window; if (window == null) { return; } window.Close(); if (string.IsNullOrEmpty(Link)) { return; } if (!Link.IsValidUrl()) { MessageBox.Show("Can't parse URL"); return; } if (IsYouTube) { IVideoItem vi = await VideoItemFactory.GetVideoItemNetAsync(youId, SiteType.YouTube).ConfigureAwait(true); foreach (ISubtitle subtitle in Subtitles.Where(subtitle => subtitle.IsChecked)) { vi.Subtitles.Add(subtitle); } vi.ParentID = null; vi.SyncState = SyncState.Added; onDownloadYouItem?.Invoke(vi); await vi.DownloadItem(youpath, downloaddir, SelectedOption).ConfigureAwait(false); } else { string param = $"-o {downloaddir}\\%(title)s.%(ext)s {Link} --no-check-certificate -i --console-title"; await Task.Run(() => { Process process = Process.Start(youpath, param); process?.Close(); }).ConfigureAwait(false); } }
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; } } }
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 VideoItemViewModel(IVideoItem videoItem, IDataSource dataSource, IContextMenuStrategy menuProvider, IPlaylistsSevice playlistService, bool isLargeItems) : base(dataSource, menuProvider, isLargeItems, playlistService) { VideoItem = videoItem; _videoId = videoItem.Details.VideoId; _id = Guid.NewGuid().ToString(); Title = videoItem.Details.Title; ChannelTitle = videoItem.ChannelTitle; Description = videoItem.Details.Description; ImagePath = videoItem.Thumbnails.GetThumbnailUrl(); Duration = videoItem.Details.Duration; ViewCount = videoItem.Details.Statistics.ViewCount; PublishedAt = videoItem.PublishedAt; IsContexMenu = dataSource.IsAuthorized; IsLive = videoItem.Details.IsLive; if (isLargeItems) { LayoutHelper.InvokeFromUiThread(async() => { ChannelLogo = await _dataSource.GetChannelLogo(videoItem.ChannelId); }); } }
public void TestCrudPlaylists() { IVideoItem vi = VideoItemFactory.CreateVideoItem(SiteType.YouTube); FillTestVideoItem(vi, SyncState.Added); IVideoItem vi2 = VideoItemFactory.CreateVideoItem(SiteType.YouTube); FillTestVideoItem(vi2, SyncState.Deleted); vi2.ID = "vi2"; ICred cred = CredFactory.CreateCred(); FillTestCred(cred); IChannel ch = ChannelFactory.CreateChannel(SiteType.YouTube); FillTestChannel(ch, vi, vi2); IPlaylist pl = PlaylistFactory.CreatePlaylist(SiteType.YouTube); FillTestPl(pl, ch); // DeleteCredAsync Task t = db.DeleteCredAsync(cred.SiteAdress); Assert.IsTrue(!t.IsFaulted); // InsertCredAsync t = db.InsertCredAsync(cred); Assert.IsTrue(!t.IsFaulted); // DeleteChannelAsync t = db.DeleteChannelAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // InsertChannelItemsAsync t = db.InsertChannelItemsAsync(ch); Assert.IsTrue(!t.IsFaulted); // DeletePlaylistAsync t = db.DeletePlaylistAsync(pl.ID); Assert.IsTrue(!t.IsFaulted); // InsertPlaylistAsync t = db.InsertPlaylistAsync(pl); Assert.IsTrue(!t.IsFaulted); // GetPlaylistAsync t = db.GetPlaylistAsync(pl.ID); Assert.IsTrue(!t.IsFaulted); // GetChannelPlaylistAsync t = db.GetChannelPlaylistAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // UpdatePlaylistAsync t = db.UpdatePlaylistAsync(pl.ID, vi.ID, ch.ID); Assert.IsTrue(!t.IsFaulted); // GetPlaylistItemsAsync t = db.GetPlaylistItemsAsync(pl.ID, ch.ID); Assert.IsTrue(!t.IsFaulted); // DeletePlaylistAsync t = db.DeletePlaylistAsync(pl.ID); Assert.IsTrue(!t.IsFaulted); // DeleteChannelAsync t = db.DeleteChannelAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // DeleteCredAsync t = db.DeleteCredAsync(cred.SiteAdress); Assert.IsTrue(!t.IsFaulted); }
public void TestCrudTags() { ITag tag = TagFactory.CreateTag(); FillTestTag(tag); // DeleteTagAsync Task t = db.DeleteTagAsync(tag.Title); Assert.IsTrue(!t.IsFaulted); // InsertTagAsync t = db.InsertTagAsync(tag); Assert.IsTrue(!t.IsFaulted); IVideoItem vi = VideoItemFactory.CreateVideoItem(SiteType.YouTube); FillTestVideoItem(vi, SyncState.Notset); IVideoItem vi2 = VideoItemFactory.CreateVideoItem(SiteType.YouTube); FillTestVideoItem(vi2, SyncState.Deleted); vi2.ID = "vi2"; ICred cred = CredFactory.CreateCred(); FillTestCred(cred); IChannel ch = ChannelFactory.CreateChannel(SiteType.YouTube); FillTestChannel(ch, vi, vi2); // DeleteCredAsync t = db.DeleteCredAsync(cred.SiteAdress); Assert.IsTrue(!t.IsFaulted); // InsertCredAsync t = db.InsertCredAsync(cred); Assert.IsTrue(!t.IsFaulted); // DeleteChannelAsync t = db.DeleteChannelAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // InsertChannelAsync t = db.InsertChannelAsync(ch); Assert.IsTrue(!t.IsFaulted); // InsertChannelTagsAsync t = db.InsertChannelTagsAsync(ch.ID, tag.Title); Assert.IsTrue(!t.IsFaulted); // GetChannelTagsAsync t = db.GetChannelTagsAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // GetChannelsByTagAsync //t = db.GetChannelsByTagAsync(tag.Title); //Assert.IsTrue(!t.IsFaulted); // DeleteChannelTagsAsync t = db.DeleteChannelTagsAsync(ch.ID, tag.Title); Assert.IsTrue(!t.IsFaulted); // DeleteChannelAsync t = db.DeleteChannelAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // DeleteTagAsync t = db.DeleteTagAsync(tag.Title); Assert.IsTrue(!t.IsFaulted); // DeleteCredAsync t = db.DeleteCredAsync(cred.SiteAdress); Assert.IsTrue(!t.IsFaulted); }
public EditDescriptionViewModel(IVideoItem item) { this.item = item; Title = $"{item.ParentTitle} : {item.Title}"; Description = item.Description; }
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; } }
protected virtual VideoAdapter GetVideoAdapter(IVideoItem videoItem) { var va = videoItem.GetVideoAdapter(this.VideoAdapter); va.CurrentItem = videoItem; va.Controller = this; return va; }
private async void ReloadFilteredLists(object state) { ChannelItems.Clear(); if (state is WatchState) { var st = (WatchState)state; List <IVideoItem> readyel; List <string> readyAddedIds; List <string> notreadyList; List <VideoItemPOCO> items; switch (st) { case WatchState.Watched: readyel = allchannels.SelectMany(x => x.ChannelItems).Where(y => y.WatchState == WatchState.Watched).ToList(); foreach (IVideoItem item in readyel.Where(item => !watchedList.Contains(item))) { watchedList.Add(item); } readyAddedIds = readyel.Select(x => x.ID).ToList(); foreach (string id in watchedList.Select(x => x.ID).Where(id => !readyAddedIds.Contains(id))) { readyAddedIds.Add(id); } notreadyList = watchedListIds.Except(readyAddedIds).ToList(); if (notreadyList.Any()) { items = await db.GetItemsByIdsAndState(WatchState.Watched, notreadyList).ConfigureAwait(false); foreach (VideoItemPOCO poco in items) { IChannel parent = allchannels.First(x => x.ID == poco.ParentID); IVideoItem item = VideoItemFactory.CreateVideoItem(poco, parent.Site); parent.AddNewItem(item, false); parent.IsHasNewFromSync = true; watchedList.Add(item); } } watchedList.OrderBy(x => x.Timestamp).ForEach(x => AddNewItem(x)); break; case WatchState.Planned: readyel = allchannels.SelectMany(x => x.ChannelItems).Where(y => y.WatchState == WatchState.Planned).ToList(); foreach (IVideoItem item in readyel.Where(item => !plannedList.Contains(item))) { plannedList.Add(item); } readyAddedIds = readyel.Select(x => x.ID).ToList(); foreach (string id in plannedList.Select(x => x.ID).Where(id => !readyAddedIds.Contains(id))) { readyAddedIds.Add(id); } notreadyList = plannedListIds.Except(readyAddedIds).ToList(); if (notreadyList.Any()) { items = await db.GetItemsByIdsAndState(WatchState.Planned, notreadyList).ConfigureAwait(false); foreach (VideoItemPOCO poco in items) { IChannel parent = allchannels.First(x => x.ID == poco.ParentID); IVideoItem item = VideoItemFactory.CreateVideoItem(poco, parent.Site); parent.AddNewItem(item, false); parent.IsHasNewFromSync = true; plannedList.Add(item); } } plannedList.OrderBy(x => x.Timestamp).ForEach(x => AddNewItem(x)); break; } } else if (state is SyncState) { var st = (SyncState)state; switch (st) { case SyncState.Added: List <IVideoItem> readyel = allchannels.SelectMany(x => x.ChannelItems).Where(y => y.SyncState == SyncState.Added).ToList(); foreach (IVideoItem item in readyel.Where(item => !addedList.Contains(item))) { addedList.Add(item); } List <string> readyAddedIds = readyel.Select(x => x.ID).ToList(); foreach (string id in addedList.Select(x => x.ID).Where(id => !readyAddedIds.Contains(id))) { readyAddedIds.Add(id); } List <string> notreadyList = addedListIds.Except(readyAddedIds).ToList(); if (notreadyList.Any()) { List <VideoItemPOCO> items = await db.GetItemsByIdsAndState(SyncState.Added, notreadyList).ConfigureAwait(false); foreach (VideoItemPOCO poco in items) { IChannel parent = allchannels.First(x => x.ID == poco.ParentID); IVideoItem item = VideoItemFactory.CreateVideoItem(poco, parent.Site); parent.AddNewItem(item, false); parent.IsHasNewFromSync = true; addedList.Add(item); } } addedList.OrderBy(x => x.ParentID).ThenBy(y => y.Timestamp).ForEach(x => AddNewItem(x)); break; } } }
public void AddToStateList(object state, IVideoItem item) { if (state is WatchState) { var st = (WatchState)state; switch (st) { case WatchState.Watched: if (!watchedList.Select(x => x.ID).Contains(item.ID)) { watchedList.Add(item); if (SelectedState != null && SelectedState.State as WatchState? == st) { AddNewItem(item); } if (!watchedListIds.Contains(item.ID)) { watchedListIds.Add(item.ID); } } break; case WatchState.Planned: if (!plannedList.Select(x => x.ID).Contains(item.ID)) { plannedList.Add(item); if (SelectedState != null && SelectedState.State as WatchState? == st) { AddNewItem(item); } if (!plannedListIds.Contains(item.ID)) { plannedListIds.Add(item.ID); } IVideoItem vi = watchedList.FirstOrDefault(x => x.ID == item.ID); if (vi != null) { watchedList.Remove(vi); if (watchedListIds.Contains(item.ID)) { watchedListIds.Remove(item.ID); } } if (SelectedState != null && SelectedState.State as WatchState? == WatchState.Watched) { DeleteItem(item); } } break; case WatchState.Notset: IVideoItem vim = plannedList.FirstOrDefault(x => x.ID == item.ID); if (vim != null) { plannedList.Remove(vim); if (plannedListIds.Contains(item.ID)) { plannedListIds.Remove(item.ID); } } // if (SelectedState != null && SelectedState.State as WatchState? == WatchState.Planned) // { // DeleteItem(item); // } break; } } else if (state is SyncState) { var st = (SyncState)state; switch (st) { case SyncState.Added: if (!addedList.Select(x => x.ID).Contains(item.ID)) { addedList.Add(item); if (!addedListIds.Contains(item.ID)) { addedListIds.Add(item.ID); if (SelectedState != null && SelectedState.State as SyncState? == st) { if (!ChannelItems.Select(x => x.ID).Contains(item.ID)) { ChannelItems.Add(item); } } } } break; case SyncState.Notset: IVideoItem vi = addedList.FirstOrDefault(x => x.ID == item.ID); if (vi != null) { addedList.Remove(vi); if (addedListIds.Contains(item.ID)) { addedListIds.Remove(item.ID); if (SelectedState != null && SelectedState.State as SyncState? == SyncState.Added) { IVideoItem ite = ChannelItems.FirstOrDefault(x => x.ID == item.ID); if (ite != null) { ChannelItems.Remove(ite); } } } } break; } } }
public void SetItem(IVideoItem item) { cache[item.Details.VideoId] = item; }
public void TestCrudItems() { IVideoItem vi = VideoItemFactory.CreateVideoItem(SiteType.YouTube); FillTestVideoItem(vi, SyncState.Added); IVideoItem vi2 = VideoItemFactory.CreateVideoItem(SiteType.YouTube); FillTestVideoItem(vi2, SyncState.Notset); vi2.ID = "vi2"; var lst = new List <IVideoItem> { vi, vi2 }; ICred cred = CredFactory.CreateCred(); FillTestCred(cred); IChannel ch = ChannelFactory.CreateChannel(SiteType.YouTube); FillTestChannel(ch, vi, vi2); // DeleteCredAsync Task t = db.DeleteCredAsync(cred.SiteAdress); Assert.IsTrue(!t.IsFaulted); // InsertCredAsync t = db.InsertCredAsync(cred); Assert.IsTrue(!t.IsFaulted); // DeleteChannelAsync t = db.DeleteChannelAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // InsertChannelAsync t = db.InsertChannelAsync(ch); Assert.IsTrue(!t.IsFaulted); // RenameChannelAsync t = db.RenameChannelAsync(ch.ID, "newname"); Assert.IsTrue(!t.IsFaulted); // UpdateChannelNewCountAsync t = db.UpdateChannelNewCountAsync(ch.ID, 5); Assert.IsTrue(!t.IsFaulted); // UpdateChannelFastSync t = db.UpdateChannelFastSync(ch.ID, true); Assert.IsTrue(!t.IsFaulted); // GetChannelAsync t = db.GetChannelAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // GetChannelsListAsync t = db.GetChannelsListAsync(); Assert.IsTrue(!t.IsFaulted); // GetChannelItemsAsync t = db.GetChannelItemsBaseAsync(ch.ID, 25); Assert.IsTrue(!t.IsFaulted); // GetChannelItemsCountDbAsync t = db.GetChannelItemsCountDbAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // DeleteChannelAsync t = db.DeleteChannelAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // InsertChannelItemsAsync t = db.InsertChannelItemsAsync(ch); Assert.IsTrue(!t.IsFaulted); // DeleteChannelAsync t = db.DeleteChannelAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // ITEMS // InsertChannelAsync t = db.InsertChannelAsync(ch); Assert.IsTrue(!t.IsFaulted); // InsertItemAsync t = db.InsertItemAsync(vi); Assert.IsTrue(!t.IsFaulted); // UpdateItemWatchState t = db.UpdateItemWatchState(vi.ID, WatchState.Watched); Assert.IsTrue(!t.IsFaulted); // UpdateItemSyncState t = db.UpdateItemSyncState(vi.ID, SyncState.Deleted); Assert.IsTrue(!t.IsFaulted); // UpdateItemSyncState t = db.UpdateItemSyncState(lst, SyncState.Deleted); Assert.IsTrue(!t.IsFaulted); // GetVideoItemAsync t = db.GetVideoItemAsync(vi.ID); Assert.IsTrue(!t.IsFaulted); // DeleteItemAsync t = db.DeleteItemAsync(vi.ID); Assert.IsTrue(!t.IsFaulted); // DeleteChannelAsync t = db.DeleteChannelAsync(ch.ID); Assert.IsTrue(!t.IsFaulted); // DeleteCredAsync t = db.DeleteCredAsync(cred.SiteAdress); Assert.IsTrue(!t.IsFaulted); }