diff --git a/MyArgs.cs b/MyArgs.cs index 6c643d9..d841695 100644 --- a/MyArgs.cs +++ b/MyArgs.cs @@ -5,10 +5,19 @@ namespace SBT_Downloader [TabCompletion] public class MyArgs { - // This argument is required and if not specified the user - // will be prompted. It has the short '-h', but tab completion - // Is support + [ArgRequired(PromptIfMissing = false), ArgShortcut("-a")] + public string Author { get; set; } + [ArgRequired(PromptIfMissing = true), ArgShortcut("-h")] public string Har { get; set; } + + [ArgRequired(PromptIfMissing = false), ArgShortcut("-n")] + public string Narrator { get; set; } + + [ArgRequired(PromptIfMissing = true), ArgShortcut("-t")] + public string Title { get; set; } + + [ArgShortcut("-s")] + public string Series { get; set; } } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index 30bf538..7ef29e7 100644 --- a/Program.cs +++ b/Program.cs @@ -14,7 +14,7 @@ namespace SBT_Downloader var parsed = Args.Parse(args); Console.WriteLine("Downloading book now..."); (List mp3Urls, List chapters) = ParseHar(parsed.Har); - DownloadMp3s(mp3Urls, chapters); + DownloadMp3s(mp3Urls, chapters, parsed); } catch (ArgException ex) { @@ -61,9 +61,9 @@ namespace SBT_Downloader Uri uri = new(url); string fixedUri = uri.AbsoluteUri.Replace(uri.Query, string.Empty); List urlTokens = fixedUri.Split("/").ToList(); - string series = urlTokens[5]; - string title = urlTokens[6]; - string episode = urlTokens[7]; + //string series = urlTokens[5]; + //string title = urlTokens[6]; + //string episode = urlTokens[7]; var chapterTokens = urlTokens.Last().Split("_").ToList(); chapterTokens.RemoveRange(0,5); string chapterLastToken = chapterTokens.Last().Split(".").First(); @@ -83,17 +83,37 @@ namespace SBT_Downloader return urls; } - private static void DownloadMp3s(List mp3Urls, List chapters) + private static void DownloadMp3s(List mp3Urls, List chapters, MyArgs arguments) { int index = 0; foreach (string url in mp3Urls) { + string chapterName = chapters[index]; + index++; + string fileName = $"{index} {chapterName}.mp3"; using var client = new WebClient(); - client.DownloadFile(url, $"{index} {chapters[index]}.mp3"); - Console.WriteLine("Downloading file #" + ++index); + Console.WriteLine("Downloading file #" + index); + client.DownloadFile(url, fileName); + TagFile(chapterName, index, chapters.Count, arguments); } } + private static void TagFile(string chapterName, int index, int chapterCount, MyArgs arguments) + { + var file = TagLib.File.Create($"{index} {chapterName}.mp3"); + + file.Tag.Album = arguments.Title.IsNullOrEmpty() ? string.Empty : arguments.Title; + List artistsList = new List(); + if (!arguments.Author.IsNullOrEmpty()) artistsList.Add(arguments.Author); + if (!arguments.Narrator.IsNullOrEmpty()) artistsList.Add(arguments.Narrator); + file.Tag.AlbumArtists = artistsList.ToArray(); + file.Tag.Title = chapterName; + file.Tag.Track = (uint)index; + file.Tag.TrackCount = (uint)chapterCount; + + file.Save(); + } + static string LoadHar(string harFileName) { string harContents; diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 4485e79..1469e2c 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "SBT Downloader": { "commandName": "Project", - "commandLineArgs": "-har \"C:\\Repos\\sbt-downloader\\episode2.soundbooththeater.com.har\"" + "commandLineArgs": "-har \"C:\\Repos\\sbt-downloader\\episode8.soundbooththeater.com.har\" -a \"Matt Dinniman\" -n \"Jeff Hays\" -t \"Episode 8: A BETRAYAL MOST FOUL\"" } } } \ No newline at end of file diff --git a/SBT Downloader.csproj b/SBT Downloader.csproj index f9af13e..8a03335 100644 --- a/SBT Downloader.csproj +++ b/SBT Downloader.csproj @@ -11,6 +11,7 @@ +