Working first pass. Downloads all files with generic filename. Does not parse title. Does not write metadata.
This commit is contained in:
14
MyArgs.cs
Normal file
14
MyArgs.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using PowerArgs;
|
||||||
|
|
||||||
|
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 = true), ArgShortcut("-h")]
|
||||||
|
public string Har { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
77
Program.cs
Normal file
77
Program.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using PowerArgs;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace SBT_Downloader
|
||||||
|
{
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Welcome to the Sound Booth Theater Personal Archiving Tool!");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var parsed = Args.Parse<MyArgs>(args);
|
||||||
|
Console.WriteLine("Downloading book now...");
|
||||||
|
DownloadBook(parsed.Har);
|
||||||
|
}
|
||||||
|
catch (ArgException ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
Console.WriteLine(ArgUsage.GenerateUsageFromTemplate<MyArgs>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DownloadBook(string fileName)
|
||||||
|
{
|
||||||
|
string harContents = LoadHar(fileName);
|
||||||
|
JObject harObject = JObject.Parse(harContents);
|
||||||
|
List<string> mp3Urls = ParseUrls(harObject);
|
||||||
|
_ = DownloadMp3sAsync(mp3Urls);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task DownloadMp3sAsync(List<string> mp3Urls)
|
||||||
|
{
|
||||||
|
int fileNumber = 1;
|
||||||
|
foreach (string url in mp3Urls)
|
||||||
|
{
|
||||||
|
using var client = new WebClient();
|
||||||
|
client.DownloadFile(url, "file" + fileNumber + ".mp3");
|
||||||
|
Console.WriteLine("Downloading file #" + fileNumber);
|
||||||
|
fileNumber++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static string LoadHar(string harFileName)
|
||||||
|
{
|
||||||
|
string harContents;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using StreamReader streamReader = new(harFileName);
|
||||||
|
harContents = streamReader.ReadToEnd();
|
||||||
|
return harContents;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("The file could not be read:");
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
Environment.Exit(0);
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<string> ParseUrls(JObject harObject)
|
||||||
|
{
|
||||||
|
List<string> urls = harObject["log"]["entries"]
|
||||||
|
.Where(x => x.SelectToken("_resourceType").ToString() == "media")
|
||||||
|
.Select(y => y.SelectToken("request"))
|
||||||
|
.DistinctBy(z => z.SelectToken("url"))
|
||||||
|
.Select(x => x.SelectToken("url").ToString()).ToList();
|
||||||
|
|
||||||
|
Console.WriteLine(urls.Count + " total requests");
|
||||||
|
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Properties/launchSettings.json
Normal file
8
Properties/launchSettings.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"SBT Downloader": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "-har \"C:\\Repos\\sbt-downloader\\soundbooththeater.com.har\""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
SBT Downloader.csproj
Normal file
16
SBT Downloader.csproj
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<RootNamespace>SBT_Downloader</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="PowerArgs" Version="4.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
25
SBT Downloader.sln
Normal file
25
SBT Downloader.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.0.32014.148
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SBT Downloader", "SBT Downloader.csproj", "{F4898EE2-CBCD-4301-B5ED-9D73BB1F4425}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{F4898EE2-CBCD-4301-B5ED-9D73BB1F4425}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{F4898EE2-CBCD-4301-B5ED-9D73BB1F4425}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{F4898EE2-CBCD-4301-B5ED-9D73BB1F4425}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{F4898EE2-CBCD-4301-B5ED-9D73BB1F4425}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {3EE4D311-5E9A-4BBD-804B-C8D508703F30}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user