basically works
This commit is contained in:
parent
028ffa2686
commit
0ee2bf90f5
29
Program.cs
29
Program.cs
@ -1,11 +1,34 @@
|
||||
|
||||
namespace podcast_agent
|
||||
namespace podcast_agent
|
||||
{
|
||||
using System.Xml.Linq;
|
||||
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("hello world");
|
||||
var downloader = new HttpClient();
|
||||
downloader.DefaultRequestHeaders.UserAgent.ParseAdd("wget-is-not-a-crime");
|
||||
|
||||
var xml = XDocument.Load("https://feeds.npr.org/500005/podcast.xml");
|
||||
|
||||
XNamespace ns = "http://www.itunes.com/dtds/podcast-1.0.dtd";
|
||||
foreach (var item in xml.Descendants("item"))
|
||||
{
|
||||
var title = item.Element("title")?.Value;
|
||||
var ext=".wav";
|
||||
var attachmentLink = item.Element("enclosure")?.Attribute("url")?.Value.ToString();
|
||||
var probableFilename = attachmentLink.Substring(0, attachmentLink.IndexOf('?'));
|
||||
if(probableFilename.LastIndexOf('.') > 0)
|
||||
{
|
||||
ext = probableFilename.Substring(probableFilename.LastIndexOf('.'));
|
||||
}
|
||||
|
||||
Console.WriteLine($"{title}, {attachmentLink}");
|
||||
var downloadPath = title + ext;
|
||||
var dlResult = (await downloader.GetAsync(attachmentLink));
|
||||
File.WriteAllBytes(downloadPath, await dlResult.Content.ReadAsByteArrayAsync());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user