diff --git a/FastWebDownloader/Boot.cs b/FastWebDownloader/Boot.cs index a8826d5..0dad70a 100644 --- a/FastWebDownloader/Boot.cs +++ b/FastWebDownloader/Boot.cs @@ -8,6 +8,7 @@ namespace FastWebDownloader public class FWD { public static string path = Path.Combine(Directory.GetCurrentDirectory(), "config.yaml"); + public static string downloadsPath = Path.Combine(Directory.GetCurrentDirectory(), "downloads"); public static string YtDlppath = Path.Combine(Directory.GetCurrentDirectory(), "yt-dlp.exe"); public static string FFmpegpath = Path.Combine(Directory.GetCurrentDirectory(), "ffmpeg.exe"); diff --git a/FastWebDownloader/Downloader.cs b/FastWebDownloader/Downloader.cs index 84e9a74..f0048c5 100644 --- a/FastWebDownloader/Downloader.cs +++ b/FastWebDownloader/Downloader.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using YoutubeDLSharp.Options; + namespace FastWebDownloader { public class Downloader @@ -47,22 +48,45 @@ public static void ReadFile() } - /* NOT YET IMPLEMENTED - Console.ForegroundColor = ConsoleColor.Yellow; - Console.Write("Converting all audio files to the correct format"); + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine("Deleting temporal files..."); Console.ForegroundColor = ConsoleColor.White; - //convert opus to mp3 - string path = Path.Combine(Directory.GetCurrentDirectory(), "downloads"); - Process process = new Process(); - process.StartInfo.FileName = "cmd.exe"; - process.StartInfo.Arguments = $"cd {path} || for %f in (*.opus) do ffmpeg -i \"%f\" \"%~nf.mp3\" || del *.opus"; - process.Start(); - process.WaitForExit(); + //foreach file in a directory remove spaces from the file name + foreach (string filePath in Directory.EnumerateFiles(FWD.downloadsPath)) + { + string fileName = Path.GetFileNameWithoutExtension(filePath); + string fileExtension = Path.GetExtension(filePath); + + //In the string the is a "[" and "]", delete everything between them and the brackets + if (fileName.Contains("[") && fileName.Contains("]")) + { + int start = fileName.IndexOf('['); + int end = fileName.IndexOf(']'); + fileName = fileName.Remove(start, end - start + 1); + } + + //Delete any non alphanumeric characters + fileName = System.Text.RegularExpressions.Regex.Replace(fileName, "[^a-zA-Z0-9_]+", "", System.Text.RegularExpressions.RegexOptions.Compiled); + + //If string has 2 or more consecutive underscores, remove one + fileName = System.Text.RegularExpressions.Regex.Replace(fileName, "(_{2,})", "_", System.Text.RegularExpressions.RegexOptions.Compiled); + + //If the file name is the same as the new file name, skip it + try + { + File.Move(filePath, Path.Combine(FWD.downloadsPath, fileName + fileExtension)); + } + catch (IOException) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"Error renaming {fileName}"); + Console.ForegroundColor = ConsoleColor.White; + } + } - */ Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; @@ -80,8 +104,6 @@ public static void ReadFile() } - - public static async Task Download(string url, bool IsMusic) { var ytdl = new YoutubeDL(); @@ -100,7 +122,7 @@ public static async Task Download(string url, bool IsMusic) Console.ForegroundColor = ConsoleColor.Cyan; Console.Write($" {title} "); Console.ForegroundColor = ConsoleColor.Yellow; - Console.Write($" to "); + Console.Write($"to "); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write($"{ytdl.OutputFolder}"); Console.WriteLine(); @@ -115,13 +137,13 @@ public static async Task Download(string url, bool IsMusic) { NoContinue = true, RestrictFilenames = true, + AudioFormat = AudioConversionFormat.Mp3 }; if (IsMusic) { var resMusic = await ytdl.RunAudioDownload( - url, - AudioConversionFormat.Mp3, + url, overrideOptions: optionsMusic ); } @@ -156,12 +178,18 @@ public static async Task DownloadPlaylist(string url, bool IsMusic) RestrictFilenames = true }; + var optionsMusic = new OptionSet() + { + RestrictFilenames = true, + AudioFormat = AudioConversionFormat.Mp3 + }; + if (IsMusic) { var res = await ytdl.RunAudioPlaylistDownload( url, - overrideOptions: options + overrideOptions: optionsMusic ); } else diff --git a/README.md b/README.md index c0343a2..08850d9 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,12 @@ An easy way to bulk download videos ## Tutorial -https://youtu.be/O5OVfGqE_po +Not yet available :( ## Features -- Easily and Silently bulk install programs -- UltraSilent bulk install mode +- Easily download videos from the web +- Portable configuration file ## Screenshots @@ -27,17 +27,15 @@ No instalation needed. ## Usage -1. Launch FBI to create "config.yaml" file -2. Select option 1 to check available programs on the database -3. Copy the codenames and paste them on "config.yaml" -4. Select how you want to install - 1. (Via the FBI UI) Select option 2 on the main menu to install - 2. (UltraSilent) (FastWebDownloader.exe /S) via cmd +1. Launch FWD to create "config.yaml" file +2. Copy YouTube URLs and paste them on "config.yaml" +3. Select if you want them to be downloaded as audio or video +4. Wait for the downloads to finish ## Contributing -Contributions expanding the database are always welcomed! To contribute open a new issue with the database tag. +Contributions are always welcomed! To contribute open a new issue and fork the proyect. [FBI database](https://pastebin.com/XkgNYRTL) ## Reposting