Instantly share code, notes, and snippets.

What would you like to do?
Easy C# Code to pull playlist
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using HtmlAgilityPack;
using System.Text.RegularExpressions;
using System.IO;
namespace TheRockNoRepeat
class Program
static void Main(string[] args)
//Download the webpage contents.
WebClient client = new WebClient();
var webpageContents = client.DownloadString("");
//Store it in an HTML document for easier access.
HtmlDocument webpageHtml = new HtmlDocument();
Regex timeRegex = new Regex("var fullday = \"(.*)\";");
Regex titleRegex = new Regex("var tit = \"(.*)\";");
Regex artistRegex = new Regex("var art = \"(.*)\";");
var timeMatches = timeRegex.Matches(webpageContents);
var titleMatches = titleRegex.Matches(webpageContents);
var artistMatches = artistRegex.Matches(webpageContents);
if(timeMatches.Count != titleMatches.Count || titleMatches.Count != artistMatches.Count)
throw new Exception("Unable to find the correct amount of matches");
List<string> outputLines = new List<string>();
for(int i =0; i < timeMatches.Count; i++)
outputLines.Add(string.Format("{0},\"{1}\",\"{2}\"", timeMatches[i].Groups[1].Value, titleMatches[i].Groups[1].Value, artistMatches[i].Groups[1].Value));
//Just reverse them so oldest is at the bottom.
File.AppendAllLines("output.csv", outputLines.AsEnumerable().Reverse());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment