예제 #1
0
        /// <summary>
        /// Handles the case where a user inputs a YouTube URL.
        /// </summary>
        /// <remarks>Any URL works as long as the full video ID is included. Also parses timestamps. </remarks>
        /// <returns>The path of the downloaded file.</returns>
        public async static Task <string> youtubeURLCase(string trackFilename)
        {
            Console.WriteLine("Enter a Youtube URL. If you want to include a timestamp, make sure it's at the END of the URL.");
            string input     = Console.ReadLine();
            string videoId   = input.Split('&')[0].Split('=')[1];
            int    startTime = 0;
            int    endTime   = Int32.MaxValue;
            string path      = "";

            try
            {
                path = await YoutubeHandler.downloadAudio(videoId, trackFilename);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Something went wrong when trying to get your YouTube link. This could be a problem on their end.");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey(intercept: true);
                Environment.Exit(1);
            }

            path = await AudioHandler.convertToWav(path);

            if (input.Contains("t="))
            {
                startTime = Int32.Parse(input.Split('=').Last());
                Console.WriteLine("Timestamp detected. Do you want to specify an end time as well? (Y/N)");
                if (Console.ReadLine().ToLower().Equals("y"))
                {
                    Console.WriteLine("Enter an end time in seconds.");
                    endTime = Int32.Parse(Console.ReadLine());
                }

                try
                {
                    path = await AudioHandler.cutAudio(path, startTime, endTime);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey(intercept: true);
                    Environment.Exit(1);
                }
            }

            return(path);
        }
예제 #2
0
        /// <summary>
        /// Handles the case where a user inputs a local file.
        /// </summary>
        /// <remarks>This supports tab autocompletion.</remarks>
        /// <returns>The path of the downloaded file.</returns>
        public async static Task <string> audioFileCase(string trackFilename, List <string> keys)
        {
            Console.WriteLine("Enter the name of an audio file in the current directory.");
            var builder = new StringBuilder();
            var input   = Console.ReadKey(intercept: true);

            while (input.Key != ConsoleKey.Enter)
            {
                var currentInput = builder.ToString();
                if (input.Key == ConsoleKey.Tab)
                {
                    var match = keys.FirstOrDefault(item => item != currentInput && item.StartsWith(currentInput, true, CultureInfo.InvariantCulture));

                    if (string.IsNullOrEmpty(match))
                    {
                        input = Console.ReadKey(intercept: true);
                        continue;
                    }

                    ClearCurrentLine();
                    builder.Clear();

                    Console.Write(match);
                    builder.Append(match);
                }

                else
                {
                    if (input.Key == ConsoleKey.Backspace && currentInput.Length > 0)
                    {
                        builder.Remove(builder.Length - 1, 1);
                        ClearCurrentLine();

                        currentInput = currentInput.Remove(currentInput.Length - 1);
                        Console.Write(currentInput);
                    }
                    else
                    {
                        var key = input.KeyChar;
                        builder.Append(key);
                        Console.Write(key);
                    }
                }

                input = Console.ReadKey(intercept: true);
            }

            var finalinput = builder.ToString();

            Console.WriteLine('\n');

            if (File.Exists(finalinput))
            {
                string current = System.AppContext.BaseDirectory;

                if (!Directory.GetCurrentDirectory().Contains("system32"))
                {
                    current = Directory.GetCurrentDirectory();
                }

                if (!Directory.Exists(current + "\\brstms"))
                {
                    Directory.CreateDirectory(current + "\\brstms");
                }

                string path = finalinput;

                if (!path.Substring(path.Length - 3).Equals("wav"))
                {
                    path = await AudioHandler.convertToWav(path);
                }

                AudioHandler.handleExistingFile(current + "\\brstms\\" + trackFilename + "_temp.wav");
                File.Copy(path, current + "\\brstms\\" + trackFilename + "_temp.wav");
                path = current + "\\brstms\\" + trackFilename + "_temp.wav";

                Console.WriteLine("Would you like to specify a start/end time? (Y/N)");

                if (Console.ReadLine().ToLower().Equals("y"))
                {
                    int startTime = 0;
                    int endTime   = Int32.MaxValue;
                    Console.WriteLine("Enter a start time in seconds.");
                    startTime = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("Enter an end time in seconds (leave this blank if you want to keep the rest of the song)");
                    string end = Console.ReadLine();
                    if (!string.IsNullOrEmpty(end))
                    {
                        endTime = Int32.Parse(end);
                    }
                    else
                    {
                        endTime = startTime + 300;
                    }

                    try
                    {
                        path = await AudioHandler.cutAudio(path, startTime, endTime);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Press any key to exit...");
                        Console.ReadKey(intercept: true);
                        Environment.Exit(1);
                    }
                }

                return(path);
            }
            else
            {
                Console.WriteLine("Something went wrong. That file either doesn't exist, or you just inputted garbage.");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey(intercept: true);
                Environment.Exit(1);
                return("");
            }
        }