private void ConfigureDirectory(Config config) { // Directory C.WriteLine("Output directory:"); CC.WriteLine(ConsoleColor.DarkGray, "Enter nothing to use your 'My Music' directory."); C.ForegroundColor = ConsoleColor.Yellow; bool exists; do { config.Output.Directory = C.ReadLine(); // My Music if (string.IsNullOrWhiteSpace(config.Output.Directory)) { config.Output.Directory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); C.SetCursorPosition(0, C.CursorTop - 1); C.WriteLine(config.Output.Directory); } // Check validity exists = Directory.Exists(config.Output.Directory); if (!exists) { CC.WriteLine(ConsoleColor.Red, "The directory does not exist. Please enter a valid directory."); } } while (!exists); C.ResetColor(); }
public void Configure() { var config = Config; config.Output = config.Output ?? new SpotDl.Options(); CC.WriteLine(ConsoleColor.DarkCyan, "Configuring"); ConfigureDirectory(config); C.WriteLine(); ConfigureExtension(config); CC.WriteLine(ConsoleColor.Green, "Done configuring!"); }
private static void Main(string[] args) { var version = Assembly.GetExecutingAssembly().GetName().Version; // Title C.Write("| "); CC.Write(ConsoleColor.Cyan, "Spotify-Downloader Handler"); C.WriteLine($" v{version.Major}.{version.Minor}.{version.Build}"); C.Write("| "); C.Write("Repository: "); CC.WriteLine(ConsoleColor.White, "https://github.com/Silverfeelin/spotdl-handler"); C.Write("| "); C.Write("Powered by Spotify-Downloader: "); CC.WriteLine(ConsoleColor.White, "https://github.com/ritiek/spotify-downloader"); //C.WriteLine(""); try { _manager = new ConfigurationManager(); // Configure if (args.Length == 0 || args.Any(a => a == "--configure")) { _manager.Configure(); _manager.Save(); Exit(); return; } // Run Run(args); } catch (Exception exc) { CC.WriteLine(ConsoleColor.Red, $"Unhandled exception:\n{exc}"); C.WriteLine("Press Enter to exit..."); C.ReadLine(); Environment.Exit(1); } Exit(); }
private static bool ValidateDirectory(Config config) { var directory = config.Output.Directory; if (string.IsNullOrWhiteSpace(directory)) { CC.WriteLine(ConsoleColor.Red, "Output directory not configured. Please run the application without any arguments to configure settings."); return(false); } if (!Directory.Exists(directory)) { CC.Write(ConsoleColor.Red, "Output directory "); CC.Write(ConsoleColor.Yellow, directory); CC.Write(ConsoleColor.Red, " does not exist. Please run the application without any arguments to configure settings."); return(false); } return(true); }
private void ConfigureExtension(Config config) { var allowed = new HashSet <string> { ".m4a", ".mp3", ".flac" }; // Extension C.WriteLine("File format (.m4a .mp3 .flac):"); CC.WriteLine(ConsoleColor.DarkGray, "Enter nothing to use '.m4a'."); C.ForegroundColor = ConsoleColor.Yellow; string extension; do { extension = (C.ReadLine() ?? string.Empty).ToLowerInvariant(); // Default if (string.IsNullOrWhiteSpace(extension)) { extension = ".m4a"; PreviousLine(); C.WriteLine(extension); } else if (!extension.StartsWith(".")) { extension = $".{extension}"; } if (!allowed.Contains(extension)) { CC.WriteLine(ConsoleColor.Red, "The format is not valid. Please enter one of the options."); } } while (!allowed.Contains(extension)); config.Output.Extension = extension; C.ResetColor(); }
private static void Run(string[] args) { var config = _manager.Config; /* Check output directory */ if (!ValidateDirectory(config)) { Exit(1); return; } // Fix args if (args[0].IndexOf("%20", StringComparison.Ordinal) != -1) { args = args[0].Split("%20"); } if (args[0].IndexOf("spotdl:", StringComparison.Ordinal) == 0) { args[0] = args[0].Substring(7); } // Get type var reg = new Regex("https:\\/\\/open\\.spotify\\.com\\/([a-zA-Z]+)\\/[a-zA-Z0-9]+"); var match = reg.Match(args[0]); if (!match.Success) { CC.WriteLine(ConsoleColor.Red, "Incorrect Spotify URL."); Exit(1); return; } // Download if (args.Skip(1).Any(a => a == "-m")) { config.Output.Manual = true; config.Output.Overwrite = "force"; } // Detmerine download type. var valid = true; var spotdl = new SpotDl(); switch (match.Groups[1].Value) { case "track": config.Output.SongUrl = args[0]; break; case "album": config.Output.AlbumUrl = args[0]; break; case "playlist": config.Output.PlaylistUrl = args[0]; break; default: C.WriteLine("Type {0} not supported! Downloading is limited to tracks, albums and playlists.", match.Groups[1].Value); valid = false; break; } if (valid) { spotdl.Download(config.Output); } CC.WriteLine(ConsoleColor.Green, "Done downloading!"); }