public Task StartDownloadAsync() { if (Settings.ConcurrentDownloads == 0) { Settings.ConcurrentDownloads = 4; } _downloadTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(Settings.ConcurrentDownloads); TaskFactory factory = new TaskFactory(_downloadTaskScheduler); var syncContext = SynchronizationContext.Current; // start all using limited task scheduler foreach (var item in DownloadItems) { item.DownloadAsync(factory).ContinueWith((task) => { if (RemoveItemWhenDowloaded && item.Completed == true && item.Failed == false) { syncContext.Send((o) => { DownloadItems.Remove(item); }, null); } }); } return(Task.Run(() => { WaitAll(); })); }
private string OptionsBuilder(DownloadItems downloadItems) { int subValue = -1; string subtitleFormat = downloadItems.subtitleValue.SubtitleFormat; string languageCode = downloadItems.subtitleValue.LanguageCode; bool hasVideo = downloadItems.videoValue != "-1"; bool hasAudio = downloadItems.audioValue != "-1"; bool hasSubtitle = !Int32.TryParse(subtitleFormat, out subValue) || subValue > -1; StringBuilder arguments = new StringBuilder(); if (hasVideo) { arguments.Append($" -f {downloadItems.videoValue}"); if (hasAudio) { arguments.Append($"+{downloadItems.audioValue}"); } if (hasSubtitle) { if (downloadItems.autoCaption) { arguments.Append($" --write-auto-sub --sub-format {subtitleFormat} --sub-lang {languageCode}"); } else { arguments.Append($" --write-sub --sub-format {subtitleFormat} --sub-lang {languageCode}"); } } } else if (hasAudio) { arguments.Append($" -f {downloadItems.audioValue}"); if (hasSubtitle) { if (downloadItems.autoCaption) { arguments.Append($" --write-auto-sub --sub-format {subtitleFormat} --sub-lang {languageCode}"); } else { arguments.Append($" --write-sub --sub-format {subtitleFormat} --sub-lang {languageCode}"); } } } else if (hasSubtitle) { if (downloadItems.autoCaption) { arguments.Append($" --write-auto-sub --sub-format {subtitleFormat} --sub-lang {languageCode} --skip-download"); } else { arguments.Append($" --write-sub --sub-format {subtitleFormat} --sub-lang {languageCode} --skip-download"); } } arguments.Append($" {downloadItems.url}"); return(arguments.ToString()); }
private void VideoDownloader_DownloadProgressChanged(object sender, ProgressEventArgs e) { CustomVideoDownloader video = (CustomVideoDownloader)sender; var a = DownloadItems.FirstOrDefault(i => i.Id == video.DownloadItem.Id); a.DownloadedPercent = e.ProgressPercentage; }
private void downloadButton_Click(object sender, EventArgs e) { if (!audioCmb.Enabled) { audioCmb.SelectedIndex = 0; } if (videoCombo.SelectedIndex == -1) { videoCombo.SelectedIndex = 0; } if (audioCmb.SelectedIndex == -1) { audioCmb.SelectedIndex = 0; } if (subtitleCmb.SelectedIndex == -1) { subtitleCmb.SelectedIndex = 0; } DownloadItems downloadItems = new DownloadItems(); downloadItems.url = youtubeUrlTextBox.Text; downloadItems.videoValue = ((ComboboxItem)videoCombo.SelectedItem).Value.ToString(); downloadItems.audioValue = ((ComboboxItem)audioCmb.SelectedItem).Value.ToString(); downloadItems.subtitleValue = (SubtitleValues)((ComboboxItem)subtitleCmb.SelectedItem).Value; downloadItems.autoCaption = AutoCaptionCheckBox.Checked; services.Download(downloadItems, SaveFolderBrowserDialog.SelectedPath); }
/// <summary> /// Handles the Install button click; fetches and installs the updates selected. /// </summary> /// <param name="sender">The object triggering this event/</param> /// <param name="e">Event argument.</param> private void updatesBtn_Click(object sender, EventArgs e) { updatesPanel.Visible = false; downloadingPnl.Visible = true; List <DownloadInfo> updatesToInstall = new List <DownloadInfo>(); //Collect the items that need to be installed foreach (ListViewItem item in updatesLv.CheckedItems) { item.Remove(); item.SubItems.RemoveAt(1); item.SubItems.RemoveAt(1); downloadingLv.Items.Add(item); DownloadInfo download = (DownloadInfo)item.Tag; updatesToInstall.Add(download); DownloadItems.Add(download, new DownloadUIInfo(download, item)); } //Then run the thread if there are updates. if (updatesToInstall.Count > 0) { downloader.RunWorkerAsync(updatesToInstall); } else { Close(); } }
public void Delete(DownloadItems items) { foreach (var item in items) { DownloadItems.Remove(item); item.CurrentDownloadTaskCts?.Cancel(); item.Status = DownloadStatusEnum.Cancel; } }
private void Download(object parameter) { var selectItems = DownloadItems .Where(e => e.IsEnable && e.Selected) .Select(e => e.Item) .ToList(); _downloadService.AddRange(selectItems); }
private void _downloadService_OnDownloaded(DownloadItem obj) { var vm = DownloadItems.SingleOrDefault(e => e.Item == obj); if (vm != null) { vm.IsEnable = false; } this.DownloadStatus = $"{obj.DirName}/{obj.Index}-{obj.Title} 下载完毕!"; }
internal void Add(DownloadInfo item) { if (item is DownloadInfo)// && !IsExists(item)) { //lock (items) { items.Add(item); DownloadItems.ScrollIntoView(item); } } }
public async Task FillDownloadItemsAsync() { var allItems = await GetAllMediaItemsAsync(); DownloadItems.Clear(); foreach (var item in allItems.Where(m => !DownloadItem.AllreadyDownloaded(m, Settings.LocalPhotosPath))) { DownloadItems.Add(DownloadItem.CreateDownloadItem(item, Settings.LocalPhotosPath)); } }
public void Stop(DownloadItems items) { foreach (var item in items) { if (item.Status == DownloadStatusEnum.WaitForDownload || item.Status == DownloadStatusEnum.Downloading) { item.CurrentDownloadTaskCts?.Cancel(); item.Status = DownloadStatusEnum.Stop; } } }
private void DeleteAllButtonOnClick(object sender, RoutedEventArgs e) { for (var i = 0; i < DownloadItems.Count; i++) { var item = DownloadItems[i]; if (item.DownloadStatus == DownloadStatusEnum.Success) { DownloadItems.Remove(item); i--; } } ContextMenuPopup.IsOpen = false; }
public void DeleteAllSuccess() { for (var i = 0; i < DownloadItems.Count; i++) { var item = DownloadItems[i]; if (item.Status == DownloadStatusEnum.Success || item.Status == DownloadStatusEnum.Skip) { DownloadItems.Remove(item); i--; } } }
public DownloadItems CastSelectToDwDownloadItems() { var selectItems = DownloadItemsListBox.SelectedItems; var lb = DownloadItemsListBox; var di = new DownloadItems(); foreach (var selectItem in selectItems) { var i = lb.Items.IndexOf(selectItem); di.Add(Downloader.DownloadItems[i]); } return(di); }
public void AddDownload(DownloadItem downitem) { downitem.DownloadStatusChanged += di => DownloadStatusChanged(); DownloadItems.Add(downitem); //DownloadItemsListBox.Items.Refresh(); if (DownloadingItemsPool.Count < Settings.MaxOnDownloadingImageCount) { DownloadingItemsPool.Add(downitem); } else { WaitForDownloadItemsPool.Add(downitem); } DownloadStatusChanged(); }
private void DeleteButtonOnClick(object sender, RoutedEventArgs e) { for (var i = 0; i < DownloadItemsListBox.SelectedItems.Count; i++) { var item = DownloadItemsListBox.SelectedItems[i]; var index = DownloadItemsListBox.Items.IndexOf(item); if (index == -1) { continue; } DownloadItems[index].CurrentDownloadTaskCts?.Cancel(); DownloadItems[index].DownloadStatus = DownloadStatusEnum.Cancel; DownloadItems.RemoveAt(index); } ContextMenuPopup.IsOpen = false; }
private void OnRefreshCommandExecute() { switch (SelectedTab) { case ClaimsTabIndex: AppService.ReloadClaims(); break; case DownloadsTabIndex: var worker = new BackgroundWorker(); worker.DoWork += (i, j) => { var list = AppService.GetDownloads(); DispatcherHelper.CheckBeginInvokeOnUI(() => { DownloadItems.Clear(); foreach (var item in list) { DownloadItems.Add(item); } }); }; worker.RunWorkerAsync(); break; case PaymentsTabIndex: worker = new BackgroundWorker(); worker.DoWork += (i, j) => { var list = AppService.GetPayments(); DispatcherHelper.CheckBeginInvokeOnUI(() => { PaymentItems.Clear(); foreach (var item in list) { PaymentItems.Add(item); } }); }; worker.RunWorkerAsync(); break; default: throw new ArgumentOutOfRangeException(); } }
public void AddDownload(MoeItem item, dynamic bitimg) { var downItem = new DownloadItem(Set, bitimg, item); if (item.ChildrenItems.Count > 0) { for (var i = 0; i < item.ChildrenItems.Count; i++) { var subItem = item.ChildrenItems[i]; var downSubItem = new DownloadItem(Set, bitimg, subItem, i + 1, item); downItem.SubItems.Add(downSubItem); } } DownloadItems.Add(downItem); }
public void Retry(DownloadItems items) { for (var i = 0; i < items.Count; i++) { var item = items[i]; if (item.Status == DownloadStatusEnum.Downloading) { item.CurrentDownloadTaskCts?.Cancel(); item.Status = DownloadStatusEnum.WaitForDownload; } if (item.Status == DownloadStatusEnum.Failed) { item.Status = DownloadStatusEnum.WaitForDownload; } } }
// while download button is clicked private void Download_Click(object sender, RoutedEventArgs args) { int index = Files.SelectedIndex; DownloadLinksViewModel item = Links[index]; // open a SaveFileDialog to choose where to save the file SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "video." + item.Type; sfd.Filter = "All Files (*.*) | *.*"; if ((bool)sfd.ShowDialog()) { //ToggleControls(false); // determine the filename set by user. string fileName = sfd.FileName; int taskIndex = DownloadTasks.Count; DownloadItems.Add(new DownloadListViewModel() { Title = fileName, Progress = 0, Tag = taskIndex }); WebClient client = new WebClient(); client.DownloadProgressChanged += (s, e) => { // update the progress bar DownloadItems[taskIndex].Progress = e.ProgressPercentage; }; client.DownloadFileCompleted += (s, e) => { }; // start to download file. Task task = client.DownloadFileTaskAsync(new Uri(Links[index].Link), fileName); DownloadTasks.Add(task); // clear the url and combobox Url.Text = ""; Url.Focus(); Links.Clear(); } }
private void DownloadBeatmap(Beatmap beatmap, bool fireUpdateEvent) { if (beatmap != null) { BeatmapsToDownload.Add((BeatmapExtension)beatmap); var downloadItem = GetDownloadItem((BeatmapExtension)beatmap); if (downloadItem == null) { return; } DownloadItems.Add(downloadItem); ListedMapSetIds.Add(beatmap.MapSetId); } if (fireUpdateEvent) { DownloadItemsChanged?.Invoke(this, EventArgs.Empty); } }
public void Download(DownloadItems downloadItems, string directory) { string arguments = OptionsBuilder(downloadItems); Utility.ExecuteFile("youtube-dl.exe", arguments, false, directory); }
//public async Task SyncConsoleAsync() //{ // var allItems = await GetAllMediaItemsAsync(); // DownloadItems = allItems.Where(m => !DownloadItem.AllreadyDownloaded(m, SyncDirectory)) // .Select(p => DownloadItem.CreateDownloadItem(p, SyncDirectory)) // .ToList(); // TaskFactory factory = new TaskFactory(_downloadTaskScheduler); // // start all using limited task scheduler // foreach (var item in DownloadItems) // item.DownloadAsync(factory).ConfigureAwait(false); // do // { // Console.Clear(); // foreach (var item in DownloadItems) // { // Console.WriteLine($"{item.MediaItem.Filename} {item.Completed} {item.Exception?.Message} {item.Downloading} "); // } // } // while (!WaitAll(500)); //} public bool WaitAll(int timeout = 0) { return(Task.WaitAll(DownloadItems.Select(p => p.DownloadTask).ToArray(), timeout)); }