private void button1_Click(object sender, EventArgs e) { if (isListViewDirty) { collectionStatusLabel.Text = "Ready to begin."; collectionProgressBar.Value = 0; SetGlobalProgress(0); SetGlobalProgressState(ProgressBarState.Normal); totalProgressBar.Value = 0; totalStatusLabel.Text = "Ready"; queueListView.Groups.Clear(); queueListView.Items.Clear(); isListViewDirty = false; } #if !DEBUG try { #endif // Don't add if the item is already enqueued. var isAlreadyInQueue = mediaDownloadQueue.ItemById(mResult.Id) != null; if (isAlreadyInQueue) { using ( var td = CommonTaskDialogs.Message(owner: this, icon: TaskDialogStandardIcon.Error, caption: "Cannot add to download queue", message: "This item already exists in the download queue.")) { td.Show(); return; } } // Ask for the location if required before we begin retrieval var prefType = PreferenceForType(mResult.Type); var saveDir = prefType.SaveDirectory; if (prefType.AskForLocation) { using (var folderSelectionDialog = new FolderBrowserDialog { Description = "Select a destionation for this media:" }) { if (folderSelectionDialog.ShowDialog(this) == DialogResult.OK) { saveDir = folderSelectionDialog.SelectedPath; } else { return; } } } // Filter out types we can't process right now if (mResult.Type != MediaType.Album && mResult.Type != MediaType.Playlist && mResult.Type != MediaType.Track) { using (var noTypeTd = CommonTaskDialogs.Message(owner: this, icon: TaskDialogStandardIcon.Warning, caption: $"'{mResult.Type}' is not supported yet.", message: "You may be able to download it in a later release.")) { noTypeTd.Show(); return; } } // Build wait dialog var retrievalWaitTaskDialog = new TaskDialog { Cancelable = false, Caption = "Athame", InstructionText = $"Getting {mResult.Type.ToString().ToLower()} details...", Text = $"{mService.Info.Name}: {mResult.Id}", StandardButtons = TaskDialogStandardButtons.Cancel, OwnerWindowHandle = Handle, ProgressBar = new TaskDialogProgressBar { State = TaskDialogProgressBarState.Marquee } }; // Open handler retrievalWaitTaskDialog.Opened += async(o, args) => { LockUi(); var pathFormat = Path.Combine(saveDir, prefType.GetPlatformSaveFormat()); try { switch (mResult.Type) { case MediaType.Album: // Get album and display it in listview var album = await mService.GetAlbumAsync(mResult.Id, true); AddToQueue(mService, album, pathFormat); break; case MediaType.Playlist: // Get playlist and display it in listview var playlist = await mService.GetPlaylistAsync(mResult.Id); AddToQueue(mService, playlist, pathFormat); break; case MediaType.Track: var track = await mService.GetTrackAsync(mResult.Id); AddToQueue(mService, track.AsCollection(), pathFormat); break; } } catch (ResourceNotFoundException) { CommonTaskDialogs.Message(caption: "This media does not exist.", message: "Ensure the provided URL is valid, and try again", owner: this).Show(); } catch (Exception ex) { CommonTaskDialogs.Exception(ex, "An error occurred while trying to retrieve information for this media.", "The provided URL may be invalid or unsupported.", this).Show(); } idTextBox.Clear(); UnlockUi(); retrievalWaitTaskDialog.Close(); }; // Show dialog retrievalWaitTaskDialog.Show(); #if !DEBUG } catch (Exception ex) { PresentException(ex); } #endif }
private void ParseAndAddUrl(UrlResolver r, bool syncMode) { if (!r.HasParsedUrl) { return; } if (isListViewDirty) { CleanQueueListView(); } #if !DEBUG try { #endif // Don't add if the item is already enqueued. var isAlreadyInQueue = mediaDownloadQueue.ItemById(r.ParseResult.Id) != null; if (isAlreadyInQueue) { TaskDialogHelper.ShowMessage(owner: Handle, icon: TaskDialogStandardIcon.Error, caption: "Cannot add to download queue", message: "This item already exists in the download queue.", buttons: TaskDialogStandardButtons.Ok); return; } // Ask for the location if required before we begin retrieval var prefType = PreferenceForType(r.ParseResult.Type); var saveDir = prefType.SaveDirectory; var folderItems = new List <string>(); if (prefType.AskForLocation || syncMode) { Shell shell = new Shell(); Folder folder = shell.BrowseForFolder((int)this.Handle, "Select a destination for this media:", 0, Program.DefaultSettings.Settings.PlaylistSync.SyncDirectory); if (folder == null) { return; } FolderItem fi = (folder as Folder3).Self; saveDir = fi.Path; foreach (FolderItem curr in folder.Items()) { folderItems.Add(Path.GetFileNameWithoutExtension(curr.Name)); } //using (var folderSelectionDialog = new FolderBrowserDialog { Description = "Select a destination for this media:" }) //{ // if (folderSelectionDialog.ShowDialog(this) == DialogResult.OK) // { // saveDir = folderSelectionDialog.SelectedPath; // } // else // { // return; // } //} } // Build wait dialog var retrievalWaitTaskDialog = new TaskDialog { Cancelable = false, Caption = "Athame", InstructionText = $"Getting {r.ParseResult.Type.ToString().ToLower()} details...", Text = $"{r.Service.Info.Name}: {r.ParseResult.Id}", StandardButtons = TaskDialogStandardButtons.Cancel, OwnerWindowHandle = Handle, ProgressBar = new TaskDialogProgressBar { State = TaskDialogProgressBarState.Marquee } }; // Open handler retrievalWaitTaskDialog.Opened += async(o, args) => { LockUi(); var pathFormat = prefType.GetPlatformSaveFormat(); var finalTracks = new List <string>(); bool isPlaylist = false; try { var media = await r.ResolveAsync(syncMode, folderItems, finalTracks); isPlaylist = r.ParseResult.Type == MediaType.Playlist; AddToQueue(r.Service, media, saveDir, pathFormat); } catch (ResourceNotFoundException) { TaskDialogHelper.ShowMessage(caption: "This media does not exist.", message: "Ensure the provided URL is valid, and try again", owner: Handle, buttons: TaskDialogStandardButtons.Ok, icon: TaskDialogStandardIcon.Information); } catch (NotImplementedException) { TaskDialogHelper.ShowMessage( owner: Handle, icon: TaskDialogStandardIcon.Warning, buttons: TaskDialogStandardButtons.Ok, caption: $"'{r.ParseResult.Type}' is not supported yet.", message: "You may be able to download it in a later release."); } catch (Exception ex) { Log.WriteException(Level.Error, Tag, ex, "While attempting to resolve media"); TaskDialogHelper.ShowExceptionDialog(ex, "An error occurred while trying to retrieve information for this media.", "The provided URL may be invalid or unsupported.", Handle); } idTextBox.Clear(); UnlockUi(); retrievalWaitTaskDialog.Close(); if (syncMode && isPlaylist) { var toDelete = new List <string>(); foreach (var curTrack in folderItems) { if (!finalTracks.Contains(curTrack)) { toDelete.Add(curTrack); } } if (toDelete.Count > 0) { DialogResult dialogResult = MessageBox.Show("Delete " + toDelete.Count + " tracks, which is not in playlist?", "Confirm delete", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { DirectoryInfo di = new DirectoryInfo(saveDir); foreach (FileInfo file in di.GetFiles()) { if (toDelete.Contains(Path.GetFileNameWithoutExtension(file.Name))) { file.Delete(); } } } } } else if (!isPlaylist && syncMode) { MessageBox.Show("Can't sync if not playlist"); } }; // Show dialog retrievalWaitTaskDialog.Show(); #if !DEBUG } catch (Exception ex) { PresentException(ex); } #endif }
private void button1_Click(object sender, EventArgs e) { if (!resolver.HasParsedUrl) { return; } if (isListViewDirty) { CleanQueueListView(); } #if !DEBUG try { #endif // Don't add if the item is already enqueued. var isAlreadyInQueue = mediaDownloadQueue.ItemById(resolver.ParseResult.Id) != null; if (isAlreadyInQueue) { TaskDialogHelper.ShowMessage(owner: Handle, icon: TaskDialogStandardIcon.Error, caption: "Cannot add to download queue", message: "This item already exists in the download queue.", buttons: TaskDialogStandardButtons.Ok); } // Ask for the location if required before we begin retrieval var prefType = PreferenceForType(resolver.ParseResult.Type); var saveDir = prefType.SaveDirectory; if (prefType.AskForLocation) { using (var folderSelectionDialog = new FolderBrowserDialog { Description = "Select a destination for this media:" }) { if (folderSelectionDialog.ShowDialog(this) == DialogResult.OK) { saveDir = folderSelectionDialog.SelectedPath; } else { return; } } } // Build wait dialog var retrievalWaitTaskDialog = new TaskDialog { Cancelable = false, Caption = "Athame", InstructionText = $"Getting {resolver.ParseResult.Type.ToString().ToLower()} details...", Text = $"{resolver.Service.Info.Name}: {resolver.ParseResult.Id}", StandardButtons = TaskDialogStandardButtons.Cancel, OwnerWindowHandle = Handle, ProgressBar = new TaskDialogProgressBar { State = TaskDialogProgressBarState.Marquee } }; // Open handler retrievalWaitTaskDialog.Opened += async(o, args) => { LockUi(); var pathFormat = prefType.GetPlatformSaveFormat(); try { var media = await resolver.Resolve(); AddToQueue(resolver.Service, media, saveDir, pathFormat); } catch (ResourceNotFoundException) { TaskDialogHelper.ShowMessage(caption: "This media does not exist.", message: "Ensure the provided URL is valid, and try again", owner: Handle, buttons: TaskDialogStandardButtons.Ok, icon: TaskDialogStandardIcon.Information); } catch (NotImplementedException) { TaskDialogHelper.ShowMessage( owner: Handle, icon: TaskDialogStandardIcon.Warning, buttons: TaskDialogStandardButtons.Ok, caption: $"'{resolver.ParseResult.Type}' is not supported yet.", message: "You may be able to download it in a later release."); } catch (Exception ex) { Log.WriteException(Level.Error, Tag, ex, "While attempting to resolve media"); TaskDialogHelper.ShowExceptionDialog(ex, "An error occurred while trying to retrieve information for this media.", "The provided URL may be invalid or unsupported.", Handle); } idTextBox.Clear(); UnlockUi(); retrievalWaitTaskDialog.Close(); }; // Show dialog retrievalWaitTaskDialog.Show(); #if !DEBUG } catch (Exception ex) { PresentException(ex); } #endif }
private void button1_Click(object sender, EventArgs e) { try { // Don't add if the item is already enqueued. var isAlreadyInQueue = mediaDownloadQueue.ItemById(mResult.Id) != null; if (isAlreadyInQueue) { using ( var td = CommonTaskDialogs.Message(this, TaskDialogStandardIcon.Error, "Athame", "Cannot add to download queue", "This item already exists in the download queue.", TaskDialogStandardButtons.Ok)) { td.Show(); return; } } // Ask for the location if required before we begin retrieval var prefType = PreferenceForType(mResult.Type); var saveDir = prefType.SaveDirectory; if (prefType.AskForLocation) { using (var folderSelectionDialog = new FolderBrowserDialog { Description = "Select a destionation for this media:" }) { if (folderSelectionDialog.ShowDialog(this) == DialogResult.OK) { saveDir = folderSelectionDialog.SelectedPath; } else { return; } } } // Filter out types we can't process right now if (mResult.Type != MediaType.Album && mResult.Type != MediaType.Playlist && mResult.Type != MediaType.Track) { using (var noTypeTd = CommonTaskDialogs.Message(this, TaskDialogStandardIcon.Warning, "Athame", $"'{mResult.Type}' is not supported yet.", "You may be able to download it in a later release.", TaskDialogStandardButtons.Ok)) { noTypeTd.Show(); return; } } // Build wait dialog var retrievalWaitTaskDialog = new TaskDialog { Cancelable = false, Caption = "Athame", InstructionText = $"Getting {mResult.Type.ToString().ToLower()} details...", Text = $"{mService.Name}: {mResult.Id}", StandardButtons = TaskDialogStandardButtons.Cancel, OwnerWindowHandle = Handle, ProgressBar = new TaskDialogProgressBar { State = TaskDialogProgressBarState.Marquee } }; // Open handler retrievalWaitTaskDialog.Opened += async(o, args) => { LockUi(); var pathFormat = Path.Combine(saveDir, prefType.GetPlatformSaveFormat()); switch (mResult.Type) { case MediaType.Album: // Get album and display it in listview var album = await mService.GetAlbumAsync(mResult.Id, true); AddToQueue(mService, album, pathFormat); break; case MediaType.Playlist: // Get playlist and display it in listview var playlist = await mService.GetPlaylistAsync(mResult.Id); AddToQueue(mService, playlist, pathFormat); break; case MediaType.Track: var track = await mService.GetTrackAsync(mResult.Id); AddToQueue(mService, track.AsCollection(), pathFormat); break; } idTextBox.Clear(); UnlockUi(); retrievalWaitTaskDialog.Close(); }; // Show dialog retrievalWaitTaskDialog.Show(); } catch (Exception ex) { throw ex; } }