Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick and dirty .NET command line utility in CSharp for downloading all HR3 clubnight DJ sets from Archive.org
using System;
using System.ComponentModel;
using System.Net;
using System.Xml;
namespace Napolitano
{
class ClubnightDownloader
{
private static string currentFilename = String.Empty;
/// <summary>
/// Download Source-XML-File here:
/// https://archive.org/download/techno.livesets.collection.hr3.clubnight/techno.livesets.collection.hr3.clubnight_files.xml
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
if (args == null || args.Length < 4)
{
Console.WriteLine("ClubnightDownloader.exe <path-to-source-xml> <targetFolder> <startIndex> <endIndex>");
Environment.Exit(-1);
}
var sourceXmlFile = args[0];
var targetFolder = args[1];
var startIndex = Convert.ToInt32(args[2]);
var endIndex = Convert.ToInt32(args[3]);
var currentIndex = 0;
var settings = new XmlReaderSettings {DtdProcessing = DtdProcessing.Parse};
var urlPrefix = "https://archive.org/download/techno.livesets.collection.hr3.clubnight/{0}";
Console.WriteLine("");
Console.WriteLine("Clubnight Downloader");
Console.WriteLine("Source XML: {0}", sourceXmlFile);
Console.WriteLine("Start Index: {0} - End Index: {1}", startIndex, endIndex);
Console.WriteLine("--------------------------------------------------------");
using (var reader = XmlReader.Create(sourceXmlFile, settings))
{
using (var client = new WebClient())
{
client.DownloadFileCompleted += ClientOnDownloadFileCompleted;
client.DownloadProgressChanged += ClientOnDownloadProgressChanged;
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.Name.Equals("file") && reader["name"] != null && reader["name"].EndsWith("mp3")) {
if (currentIndex >= startIndex && currentIndex <= endIndex)
{
currentFilename = reader["name"];
client.DownloadFileTaskAsync(String.Format(urlPrefix, currentFilename),
targetFolder + currentFilename).Wait();
}
currentIndex++;
}
break;
}
}
client.DownloadProgressChanged -= ClientOnDownloadProgressChanged;
client.DownloadFileCompleted -= ClientOnDownloadFileCompleted;
}
}
}
/// <summary>
/// Handles the progress change event of WebClient downloader
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void ClientOnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.CursorLeft = 0;
Console.Write("{0} - {1} of {2} bytes. {3} % complete...", currentFilename, e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage);
}
/// <summary>
/// Handles the download completed event of WebClient downloader (for files)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void ClientOnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
Console.WriteLine(Environment.NewLine);
}
}
}
@napolitano

This comment has been minimized.

Copy link
Owner Author

@napolitano napolitano commented Oct 14, 2020

Usage Example:

ClubnightDownloader.exe techno.livesets.collection.hr3.clubnight_files.xml D:\Music\ 0 250

How-To and super simple solution for users with the possibility to use a modern shell can be found here:
https://napolitano.de/2020/10/14/hr3-clubnight-dj-sets-collection-downloader/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.