diff --git a/VDownload/Services/Config.cs b/VDownload/Services/Config.cs index 52f96db..8b1999c 100644 --- a/VDownload/Services/Config.cs +++ b/VDownload/Services/Config.cs @@ -50,7 +50,8 @@ namespace VDownload.Services { "use_mrfcrf444", "1" }, { "use_hardware_acceleration", "1" }, { "delete_temp_on_start", "1" }, - { "delete_video_temp_after_error", "1" } + { "delete_video_temp_after_error", "1" }, + { "max_playlist_videos", "0" }, }; // SETTINGS CONTAINER diff --git a/VDownload/Sources/PObject.cs b/VDownload/Sources/PObject.cs index e6329d7..a5a150c 100644 --- a/VDownload/Sources/PObject.cs +++ b/VDownload/Sources/PObject.cs @@ -30,13 +30,16 @@ namespace VDownload.Sources public PlaylistSource SourceType { get; private set; } public string ID { get; private set; } public Dictionary VObjects { get; private set; } + private List DeletedVObjects { get; set; } + + // PLAYLIST PANEL OBJECTS public StackPanel PlaylistPanel { get; set; } - private List DeletedVObjects = new List(); private Grid DeletedVideosPanel { get; set; } // CONSTRUCTOR public PObject(Uri url) { + DeletedVObjects = new List(); VObjects = new Dictionary(); (SourceType, ID) = Source.GetPlaylistSourceData(url); if (SourceType == PlaylistSource.Null) @@ -54,39 +57,40 @@ namespace VDownload.Sources // GET VIDEOS public async Task GetVideos() { + VObject[] videos = null; switch (SourceType) { case PlaylistSource.TwitchChannel: - // TODO + videos = await Twitch.Channel.GetVideos(ID); break; case PlaylistSource.Null: throw new ArgumentException(); } - } - // ADD VIDEOS TO LIST - public async Task InitPlaylistPanel(StackPanel parent) - { - // Attach to panel object to PObject - PlaylistPanel = parent; - - // Add videos to panel - foreach (VObject video in VObjects.Keys.ToArray()) + foreach(VObject video in videos) { - await HandleVideoOnList(video); + VObjects.Add(video, null); } - } - #endregion #region VIDEO PANEL + // INIT PLAYLIST PANEL + public async Task InitPlaylistPanel() + { + // Add videos to panel + foreach (VObject video in VObjects.Keys.ToArray()) + { + await VideoPanelHandler(video); + } + } + // VIDEO PANEL HANDLER - private async Task HandleVideoOnList(VObject Video) + private async Task VideoPanelHandler(VObject Video) { // Video panel Expander videoPanel = new Expander @@ -99,18 +103,16 @@ namespace VDownload.Sources // Header - #region HEADER - - Grid header = new Grid + Grid videoPanelHeader = new Grid { Margin = new Thickness(0, 15, 0, 15), }; - header.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); - header.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(15) }); - header.ColumnDefinitions.Add(new ColumnDefinition()); - header.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(15) }); - header.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); - videoPanel.Header = header; + videoPanelHeader.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + videoPanelHeader.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(15) }); + videoPanelHeader.ColumnDefinitions.Add(new ColumnDefinition()); + videoPanelHeader.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(15) }); + videoPanelHeader.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + videoPanel.Header = videoPanelHeader; // Thumbnail Image thumbnailImage = new Image @@ -119,8 +121,7 @@ namespace VDownload.Sources Width = 120, }; Grid.SetColumn(thumbnailImage, 0); - header.Children.Add(thumbnailImage); - + videoPanelHeader.Children.Add(thumbnailImage); // Metadata grid @@ -129,7 +130,7 @@ namespace VDownload.Sources metadataGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(10) }); metadataGrid.RowDefinitions.Add(new RowDefinition()); Grid.SetColumn(metadataGrid, 2); - header.Children.Add(metadataGrid); + videoPanelHeader.Children.Add(metadataGrid); // Title & Source icon grid Grid titleSourceGrid = new Grid(); @@ -260,7 +261,6 @@ namespace VDownload.Sources detailedMetadataGrid.Children.Add(durationDataTextBlock); - // Delete button AppBarButton deleteButton = new AppBarButton { @@ -277,19 +277,14 @@ namespace VDownload.Sources DeletedVideosPanelHandler(); }; Grid.SetColumn(deleteButton, 4); - header.Children.Add(deleteButton); - - #endregion + videoPanelHeader.Children.Add(deleteButton); // Content - #region CONTENT - Grid content = new Grid { HorizontalAlignment = HorizontalAlignment.Stretch, - //Margin = new Thickness(0, 15, 0, 15), }; content.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); content.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); @@ -297,7 +292,6 @@ namespace VDownload.Sources videoPanel.Content = content; - // Download options Grid downloadOptionsGrid = new Grid { @@ -464,7 +458,6 @@ namespace VDownload.Sources trimTextBoxGrid.Children.Add(AddPlaylistVideoDownloadOptionsTrimEndTextBox); - // File & location Grid fileLocationGrid = new Grid { @@ -556,8 +549,6 @@ namespace VDownload.Sources Grid.SetColumn(AddPlaylistVideoLocationDataChooseLocationButton, 2); locationGrid.Children.Add(AddPlaylistVideoLocationDataChooseLocationButton); - #endregion - // Set items in quality combobox @@ -725,7 +716,7 @@ namespace VDownload.Sources PlaylistPanel.Children.Add(videoPanel); } - // HANDLE DELETED VIDEOS PANEL + // DELETED VIDEOS PANEL HANDLER private void DeletedVideosPanelHandler() { if (DeletedVideosPanel == null) @@ -762,7 +753,7 @@ namespace VDownload.Sources { foreach (VObject v in DeletedVObjects) { - await HandleVideoOnList(v); + await VideoPanelHandler(v); } DeletedVObjects.Clear(); PlaylistPanel.Children.Remove(DeletedVideosPanel); @@ -776,6 +767,7 @@ namespace VDownload.Sources } else { + // Update panel ((TextBlock)DeletedVideosPanel.Children[0]).Text = ResourceLoader.GetForCurrentView().GetString("AddPlaylistDeletedVideosPanelTextBlock").Replace("{x}", DeletedVObjects.Count.ToString()); } } diff --git a/VDownload/Sources/Twitch/Channel.cs b/VDownload/Sources/Twitch/Channel.cs index 0b23577..6ac233a 100644 --- a/VDownload/Sources/Twitch/Channel.cs +++ b/VDownload/Sources/Twitch/Channel.cs @@ -6,42 +6,26 @@ using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; +using VDownload.Services; namespace VDownload.Sources.Twitch { internal class Channel { - #region INIT - - // ID - private string ID { get; set; } - - // CONSTRUCTOR - public Channel(string id) - { - ID = id; - } - - #endregion - - - - #region MAIN - // GET VIDEOS - public async Task GetVideos() + public static async Task GetVideos(string ID) { // Client settings WebClient Client = new WebClient(); Client.Headers.Add("Accept", "application/vnd.twitchtv.v5+json"); - Client.Headers.Add("Client-ID", "uo6dggojyb8d6soh92zknwmi5ej1q2"); + Client.Headers.Add("Client-ID", "v8kfhyc2980it9e7t5hhc7baukzuj2"); + // Get channel id Uri requestUri; JObject response; if (!ID.All(char.IsDigit)) { - Debug.WriteLine(ID); requestUri = new Uri($"https://api.twitch.tv/kraken/users?login={ID}"); response = JObject.Parse(await Client.DownloadStringTaskAsync(requestUri)); response = (JObject)response["users"][0]; @@ -52,9 +36,9 @@ namespace VDownload.Sources.Twitch response = JObject.Parse(await Client.DownloadStringTaskAsync(requestUri)); } string id = response["_id"].ToString(); - + // Get list - List videos = new List(); + List videos = new List(); int offset = 0; do { @@ -66,11 +50,23 @@ namespace VDownload.Sources.Twitch response = JObject.Parse(await Client.DownloadStringTaskAsync(requestUri)); foreach (var v in response["videos"]) { - Debug.WriteLine(v["_id"].ToString().Replace("v", "")); - videos.Add(v["_id"].ToString().Replace("v", "")); + if (int.Parse(Config.GetValue("max_playlist_videos")) == 0 || videos.Count < int.Parse(Config.GetValue("max_playlist_videos"))) + { + try + { + VObject vid = new VObject(new Uri($"https://www.twitch.tv/videos/{v["_id"].ToString().Replace("v", "")}")); + await vid.GetMetadata(); + videos.Add(vid); + } + catch { } + } + else + { + break; + } } - if (response["videos"].ToArray().Length == 100) + if (response["videos"].ToArray().Length == 100 && !(int.Parse(Config.GetValue("max_playlist_videos")) == 0 || videos.Count < int.Parse(Config.GetValue("max_playlist_videos")))) { offset += 100; } @@ -79,11 +75,9 @@ namespace VDownload.Sources.Twitch break; } } while (true); - + // Return videos return videos.ToArray(); } - - #endregion } } diff --git a/VDownload/Views/AddPlaylist/AddPlaylistBase.xaml b/VDownload/Views/AddPlaylist/AddPlaylistBase.xaml index 353e78e..d6e6b9a 100644 --- a/VDownload/Views/AddPlaylist/AddPlaylistBase.xaml +++ b/VDownload/Views/AddPlaylist/AddPlaylistBase.xaml @@ -15,7 +15,7 @@ - + diff --git a/VDownload/Views/AddPlaylist/AddPlaylistMain.xaml.cs b/VDownload/Views/AddPlaylist/AddPlaylistMain.xaml.cs index e5ff910..aafc5b7 100644 --- a/VDownload/Views/AddPlaylist/AddPlaylistMain.xaml.cs +++ b/VDownload/Views/AddPlaylist/AddPlaylistMain.xaml.cs @@ -62,9 +62,8 @@ namespace VDownload.Views.AddPlaylist // Get playlist object from parent base.OnNavigatedTo(e); Playlist = (PObject)e.Parameter; - await Playlist.InitPlaylistPanel(AddPlaylistVideoPanel); - - + Playlist.PlaylistPanel = AddPlaylistVideoPanel; + await Playlist.InitPlaylistPanel(); } // SELECT LOCATION diff --git a/VDownload/Views/MainPage.xaml b/VDownload/Views/MainPage.xaml index f84bbbd..7e88010 100644 --- a/VDownload/Views/MainPage.xaml +++ b/VDownload/Views/MainPage.xaml @@ -40,7 +40,7 @@ - +