// public class TrackRow: INotifyPropertyChanged { // public PlaylistTrack PlaylistTrack { get;} // public Track Track { get; } // public string LocationLower { get; } // public string AlbumLower { get; } // public string ArtistsLower { get; } // public string ComposersLower { get; } // public string PublisherLower { get; } // public string TitleLower { get; } // public bool IsAdditionalTrack { get; } // public Brush RowBackground { get; } // public int PlaylistTrackNo { // get { // return playlistTrackNo; // } // set { // if (playlistTrackNo!=value) { // playlistTrackNo = value; // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PlaylistTrackNo))); // } // } // } // int playlistTrackNo; // public int PlaylistTrackNoOld { get; } // /// <summary> // /// Track is marked for removal from playlist // /// </summary> // public bool IsRemoval { // get { // return isRemoval; // } // set { // if (isRemoval!=value) { // isRemoval = value; // //**--updatePlaylistCheckBox(); // HasIsRemovalChanged?.Invoke(); // } // } // } // bool isRemoval; // /// <summary> // /// User selected this track for adding to playlist OR CheckBox is disabled and displays that the track is already in the playlist // /// </summary> // public bool IsAddPlaylist { // get { // return isAddPlaylist; // } // set { // if (isAddPlaylist!=value) { // isAddPlaylist = value; // HasIsAddPlaylistChanged?.Invoke(); // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsAddPlaylist))); // } // } // } // bool isAddPlaylist; // /// <summary> // /// Playlist CheckBox is visible if a playlist name is entered and track is not marked for deletion // /// </summary> // public Visibility PlaylistCheckBoxVisibility { // get { // return playlistCheckBoxVisibility; // } // set { // if (playlistCheckBoxVisibility!=value) { // playlistCheckBoxVisibility = value; // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PlaylistCheckBoxVisibility))); // } // } // } // Visibility playlistCheckBoxVisibility; // /// <summary> // /// Playlist CheckBox is disabled when the track is already in the playlist // /// </summary> // public bool PlaylistCheckBoxIsEnabled { // get { // return playlistCheckBoxIsEnabled; // } // set { // if (playlistCheckBoxIsEnabled!=value) { // playlistCheckBoxIsEnabled = value; // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PlaylistCheckBoxIsEnabled))); // } // } // } // bool playlistCheckBoxIsEnabled; // public event PropertyChangedEventHandler? PropertyChanged; //#pragma warning disable CA2211 // Non-constant fields should not be visible // public static Action? HasIsRemovalChanged; // public static Action? HasIsAddPlaylistChanged; //#pragma warning restore CA2211 // static readonly Brush highlightedBackgroundBrush = new SolidColorBrush(Color.FromRgb(0xDF, 0xF1, 0xFA)); // public TrackRow(PlaylistTrack playlistTrack, bool isAdditionalTrack = false) { // PlaylistTrack = playlistTrack; // Track = playlistTrack.Track; // LocationLower = Track.Location.Name.ToLowerInvariant(); // ArtistsLower = Track.Artists?.ToLowerInvariant()??""; // AlbumLower = Track.Album?.ToLowerInvariant()??""; // ComposersLower = Track.Composers?.ToLowerInvariant()??""; // PublisherLower = Track.Publisher?.ToLowerInvariant()??""; // TitleLower = Track.Title?.ToLowerInvariant()??""; // IsAdditionalTrack = isAdditionalTrack; // RowBackground = isAdditionalTrack ? highlightedBackgroundBrush : Brushes.White; // PlaylistTrackNoOld = PlaylistTrackNo = playlistTrack.TrackNo; // isRemoval = false; // isAddPlaylist = false; // } // } #endregion #region Events // ------ private void playlistWindow_Loaded(object sender, RoutedEventArgs e) { PlaylistNameTextBox.Focus(); if (firstAddedTrackRow is not null) { TracksDataGrid.ScrollIntoView(firstAddedTrackRow); } AddToOtherPlaylistComboBox.SelectionChanged += addToOtherPlaylistComboBox_SelectionChanged; AddToOtherPlaylistComboBox.AddHandler(TextBoxBase.TextChangedEvent, new RoutedEventHandler(addToOtherPlaylistComboBox_TextChanged)); AddToOtherPlaylistComboBox.LostFocus += addToOtherPlaylistComboBox_LostFocus; updatePlaylistCheckBoxes(); }
private void DownloadPlaylist_Click(object sender, EventArgs e) { if (!CheckLibs(false)) { return; } Cursor.Current = Cursors.WaitCursor; DownloadPlaylist.Enabled = false; DownloadPlaylist.Text = "Descargando lista de reproducción/canal..."; DownloadPlaylist.Update(); Log("\n\nDownloading playlist/channel from YouTube"); InitializeProcess(PlaylistProcess); PlaylistProcess.StartInfo.Arguments = PlaylistTextBox.Text + " -i -f mp4" + ((MP3CheckBox.Checked) ? " -x --audio-format mp3": "") + ((MetadataCheckBox.Checked) ? " --add-metadata" : ""); DownloadingPlaylist = PlaylistProcess.Start(); StreamReader sr = PlaylistProcess.StandardOutput; string Info = ""; PageTypes PageType = PageTypes.Unknown; string PageName = ""; int PageVideos = 0; int DownloadedVideos = 0; int DownloadingVideo = 0; bool OpenDirAtEnd = OpenAtEndCheckBox.Checked; try { string FileToRename = "", FileNewName = ""; for (int i = 0; !PlaylistProcess.HasExited; i++) { string dLine = sr.ReadLine(); if (dLine == null) { continue; } switch (i) { case 0: if (PageType != PageTypes.Unknown) { continue; } if (dLine.StartsWith("[youtube:playlist]")) { PageType = PageTypes.Playlist; DownloadPlaylist.Text = "Descargando lista de reproducción..."; DownloadPlaylist.Update(); } else if (dLine.StartsWith("[youtube:channel]")) { PageType = PageTypes.Channel; i -= 1; DownloadPlaylist.Text = "Descargando canal..."; DownloadPlaylist.Update(); } else { throw new InvalidDataException("La URL especificada no corresponde a ninguna lista de reproducción/canal"); } continue; case 1: PageName = dLine.Remove(0, (PageType == PageTypes.Playlist) ? 33 : 46); PlaylistNameTextBox.Text = ((PageType == PageTypes.Playlist) ? "Lista de reproducción: " : "Canal: ") + PageName; PlaylistNameTextBox.Update(); continue; case 2: PageVideos = int.Parse(dLine.Remove(0, 28 + ((PageType == PageTypes.Playlist) ? 0 : 13) + PageName.Length + 14).Split(' ')[0]); DownloadedVideos = PageVideos; DownloadProgressBar.Maximum = PageVideos; ProgressText.Text = "1/" + PageVideos; //string PageVideosText = dLine.Remove(0, 28 + ((PageType == PageTypes.Playlist) ? 0 : 13) + PageName.Length + 14); continue; default: if (dLine.StartsWith("[download] Downloading video ") || dLine.StartsWith("[download] Finished downloading")) { if (FileToRename != "") { try { string DirectoryToMove = SaveTextBox.Text + ((DownloadInSubfolderCheckBox.Checked) ? PageName + "\\" : ""); if (!Directory.Exists(DirectoryToMove)) { Directory.CreateDirectory(DirectoryToMove); } if (MP3CheckBox.Checked) { FileToRename = FileToRename.Remove(FileToRename.Length - 1, 1) + "3"; } File.Move(SaveTextBox.Text + FileToRename, DirectoryToMove + FileNewName + ((MP3CheckBox.Checked) ? ".mp3" : ".mp4")); } catch (IOException ioex) { Log("\n[ERROR] Error trying to rename \"" + SaveTextBox.Text + FileToRename + "\" to \"" + SaveTextBox.Text + FileNewName + "\"\n" + ioex.ToString() + "\n"); Info += "\n ERROR AL MOVER/RENOMBRAR:\n " + ioex.ToString() + "\n Archivo guardado en: " + SaveTextBox.Text + FileToRename; } } if (dLine.StartsWith("[download] Finished downloading")) { continue; } DownloadingVideo = int.Parse(dLine.Remove(0, 29).Split(' ')[0]); Info += "\n\n" + DownloadingVideo + "/" + PageVideos + ": "; ProgressText.Text = DownloadingVideo + "/" + PageVideos; ProgressText.Update(); DownloadProgressBar.Value = DownloadingVideo; } if (dLine == "ERROR: This video is unavailable.") { DownloadedVideos--; Log("\n[ERROR] Video " + DownloadingVideo + "/" + PageVideos + " was not found"); Info += "VíDEO NO DISPONIBLE\n"; } if (dLine.StartsWith("[download] Destination: ")) { FileToRename = dLine.Remove(0, 24); FileNewName = FileToRename.Remove(FileToRename.Length - 16, 16); string TempURL = FileToRename.Remove(0, FileNewName.Length + 1).Remove(11, 4); Info += FileNewName + "\n URL: https://www.youtube.com/watch?v=" + TempURL; } if (dLine.EndsWith(" has already been downloaded")) { FileToRename = dLine.Remove(0, 11); FileToRename = FileToRename.Remove(FileToRename.Length - 28, 28); FileNewName = FileToRename.Remove(FileToRename.Length - 16, 16); string TempURL = FileToRename.Remove(0, FileNewName.Length + 1).Remove(11, 4); Info += FileNewName + "\n URL: https://www.youtube.com/watch?v=" + TempURL + "\n VÍDEO YA DESCARGADO"; } continue; } } sr.Close(); DownloadingPlaylist = false; Log("\nVídeos downloaded from " + ((MP3CheckBox.Checked) ? "and converted to .mp3 " : "") + "successfully from " + PageType + " # " + PageName + ": " + DownloadedVideos + "/" + PageVideos + "\n"); DownloadResultForm drm = new DownloadResultForm(Results.Info, "Vídeos descargados con éxito: " + DownloadedVideos + "/" + PageVideos, (PageType == PageTypes.Playlist) ? DownloadTypes.Playlist : DownloadTypes.Channel, PageName, MP3CheckBox.Checked, MetadataCheckBox.Checked, Info.Remove(0, 2)); } catch (Exception ex) { sr.Close(); DownloadingPlaylist = false; OpenDirAtEnd = false; Log("\n[ERROR] Error during download playlist/channel process: " + ex.Message); Info += "\n\n" + ex.ToString(); DownloadResultForm drm = new DownloadResultForm(Results.Error, "Error en la descarga de " + PageVideos + " vídeos", (PageType == PageTypes.Playlist) ? DownloadTypes.Playlist : DownloadTypes.Channel, PageName, MP3CheckBox.Checked, MetadataCheckBox.Checked, Info.Remove(0, 2)); } Cursor.Current = Cursors.Default; PlaylistNameTextBox.Text = "Nombre de la lista de reproducción/canal"; DownloadPlaylist.Enabled = true; DownloadPlaylist.Text = "Descargar lista de reproducción/canal"; DownloadProgressBar.Value = 0; ProgressText.Text = "--/--"; if (OpenDirAtEnd) { Process.Start("explorer.exe", OutputPath); } }