Downloads all files, names them in chapter order, writes metdata tags
This commit is contained in:
15
MyArgs.cs
15
MyArgs.cs
@@ -5,10 +5,19 @@ namespace SBT_Downloader
|
|||||||
[TabCompletion]
|
[TabCompletion]
|
||||||
public class MyArgs
|
public class MyArgs
|
||||||
{
|
{
|
||||||
// This argument is required and if not specified the user
|
[ArgRequired(PromptIfMissing = false), ArgShortcut("-a")]
|
||||||
// will be prompted. It has the short '-h', but tab completion
|
public string Author { get; set; }
|
||||||
// Is support
|
|
||||||
[ArgRequired(PromptIfMissing = true), ArgShortcut("-h")]
|
[ArgRequired(PromptIfMissing = true), ArgShortcut("-h")]
|
||||||
public string Har { get; set; }
|
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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
34
Program.cs
34
Program.cs
@@ -14,7 +14,7 @@ namespace SBT_Downloader
|
|||||||
var parsed = Args.Parse<MyArgs>(args);
|
var parsed = Args.Parse<MyArgs>(args);
|
||||||
Console.WriteLine("Downloading book now...");
|
Console.WriteLine("Downloading book now...");
|
||||||
(List<string> mp3Urls, List<string> chapters) = ParseHar(parsed.Har);
|
(List<string> mp3Urls, List<string> chapters) = ParseHar(parsed.Har);
|
||||||
DownloadMp3s(mp3Urls, chapters);
|
DownloadMp3s(mp3Urls, chapters, parsed);
|
||||||
}
|
}
|
||||||
catch (ArgException ex)
|
catch (ArgException ex)
|
||||||
{
|
{
|
||||||
@@ -61,9 +61,9 @@ namespace SBT_Downloader
|
|||||||
Uri uri = new(url);
|
Uri uri = new(url);
|
||||||
string fixedUri = uri.AbsoluteUri.Replace(uri.Query, string.Empty);
|
string fixedUri = uri.AbsoluteUri.Replace(uri.Query, string.Empty);
|
||||||
List<string> urlTokens = fixedUri.Split("/").ToList();
|
List<string> urlTokens = fixedUri.Split("/").ToList();
|
||||||
string series = urlTokens[5];
|
//string series = urlTokens[5];
|
||||||
string title = urlTokens[6];
|
//string title = urlTokens[6];
|
||||||
string episode = urlTokens[7];
|
//string episode = urlTokens[7];
|
||||||
var chapterTokens = urlTokens.Last().Split("_").ToList();
|
var chapterTokens = urlTokens.Last().Split("_").ToList();
|
||||||
chapterTokens.RemoveRange(0,5);
|
chapterTokens.RemoveRange(0,5);
|
||||||
string chapterLastToken = chapterTokens.Last().Split(".").First();
|
string chapterLastToken = chapterTokens.Last().Split(".").First();
|
||||||
@@ -83,17 +83,37 @@ namespace SBT_Downloader
|
|||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DownloadMp3s(List<string> mp3Urls, List<string> chapters)
|
private static void DownloadMp3s(List<string> mp3Urls, List<string> chapters, MyArgs arguments)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (string url in mp3Urls)
|
foreach (string url in mp3Urls)
|
||||||
{
|
{
|
||||||
|
string chapterName = chapters[index];
|
||||||
|
index++;
|
||||||
|
string fileName = $"{index} {chapterName}.mp3";
|
||||||
using var client = new WebClient();
|
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<string> artistsList = new List<string>();
|
||||||
|
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)
|
static string LoadHar(string harFileName)
|
||||||
{
|
{
|
||||||
string harContents;
|
string harContents;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"SBT Downloader": {
|
"SBT Downloader": {
|
||||||
"commandName": "Project",
|
"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\""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="PowerArgs" Version="4.0.3" />
|
<PackageReference Include="PowerArgs" Version="4.0.3" />
|
||||||
|
<PackageReference Include="TagLibSharp" Version="2.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user