static void CreateAndSaveYash(string videoId, string destination, string ydlPath, bool forceIpv6, bool verbose) { Console.WriteLine("Processing {0}", videoId); Console.WriteLine("Downloading audio"); string ytAudioFile; try { ytAudioFile = YoutubeDl.CallYoutubeDl(videoId, ydlPath, forceIpv6, verbose); } catch (YoutubeDlException) { throw; } Console.WriteLine("Analyzing song"); var file = TagLib.File.Create(ytAudioFile); float duration = (float)file.Properties.Duration.TotalSeconds; file.Dispose(); var sums = songLoader.DecodeSongSums(ytAudioFile); Console.WriteLine("Saving yash"); try { var filename = $"youtube_{videoId}.yash"; SaveYash(sums, duration, Path.Combine(destination, filename)); } catch (IOException) { throw; } try { File.Delete(ytAudioFile); } catch (IOException) { // oh well. } }
static void CreateAndSaveYash(string videoId, string path) { Console.WriteLine("Processing {0} now", videoId); Console.WriteLine("Downloading audio"); string ytAudioFile; try { ytAudioFile = YoutubeDl.CallYoutubeDl(videoId); } catch (YoutubeDlException yex) { Console.Error.WriteLine("youtube-dl encountered an error:"); Console.Error.WriteLine(yex.Message); return; } Console.WriteLine("Analyzing song"); TagLib.File file = TagLib.File.Create(ytAudioFile); float duration = (float)file.Properties.Duration.TotalSeconds; file.Dispose(); List <float> sums = songLoader.DecodeSongSums(ytAudioFile, duration); Console.WriteLine("Saving yash"); try { var filename = $"youtube_{videoId}.yash"; SaveYash(sums, duration, Path.Combine(path, filename)); } catch (IOException ioex) { Console.Error.WriteLine("Something went wrong:"); Console.Error.WriteLine(ioex.ToString()); } }
static void Main(string[] args) { string id = ""; string destination = "."; string ydlPath = "./youtube-dl"; bool forceIpv6 = false; bool verbose = false; var p = new OptionSet() { { "<>", "A YouTube ID", x => { id = x; } }, { "d|dest=", $"The output folder.\nDefault: {destination}", x => { destination = x; } }, { "p|proc=", $"Path to youtube-dl or a compatible fork.\nDefault: {ydlPath}", x => { ydlPath = x; } }, { "6", "Forces the downloader to use IPv6.", x => { forceIpv6 = true; } }, { "v|verbose", "Displays downloader console output.", x => { verbose = true; } }, }; if (args.Length == 0) { Console.WriteLine("yashgen video_id [options]\n"); Console.WriteLine("Options:"); p.WriteOptionDescriptions(Console.Out); Environment.Exit(ExitNoArgs); } p.Parse(args); #if DEBUG YoutubeDl.PrintVersion(ydlPath); #endif try { if (IsYoutubeId(id)) { CreateAndSaveYash(id, destination, ydlPath, forceIpv6, verbose); Console.WriteLine("Done\n"); } else { Console.Error.WriteLine("\"{0}\" doesn't appear to be a valid ID\n", id); Environment.Exit(ExitInvalidId); } } catch (YoutubeDlException yex) { Console.Error.WriteLine("youtube-dl encountered an error:"); Console.Error.WriteLine(yex.Message); Environment.Exit(ExitYoutubeDlError); } catch (Exception ex) { Console.Error.WriteLine("Something went wrong:"); Console.Error.WriteLine(ex.ToString()); Environment.Exit(ExitUnspecified); } }