Created
April 7, 2012 16:34
-
-
Save praeclarum/2330176 to your computer and use it in GitHub Desktop.
Downloads Kevin's music from SoundCloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Net; | |
| using System.IO; | |
| namespace DLKevin | |
| { | |
| class App | |
| { | |
| public static void Main (string[] args) | |
| { | |
| new App ().Run (); | |
| } | |
| CookieContainer _cookies = new CookieContainer (); | |
| void Run () | |
| { | |
| Get ("http://soundcloud.com/echuir/tracks", s => { | |
| var html = new StreamReader (s).ReadToEnd (); | |
| var p = 0; | |
| Func<string, string> ReadJsonValue = (key) => { | |
| var i = html.IndexOf ("\"" + key + "\":", p); | |
| if (i >= 0) { | |
| var start = i + 4 + key.Length; | |
| var end = html.IndexOf ("\"", start); | |
| p = end; | |
| return html.Substring (start, end - start); | |
| } | |
| else { | |
| return ""; | |
| } | |
| }; | |
| for (;;) { | |
| var title = ReadJsonValue ("title"); | |
| var streamUrl = ReadJsonValue ("streamUrl"); | |
| if (streamUrl.StartsWith ("http")) { | |
| Get (streamUrl, (ss) => { | |
| Console.WriteLine ("Downloading " + title); | |
| ss.CopyTo (File.OpenWrite ("/Users/fak/Downloads/" + title + ".mp3")); | |
| }); | |
| } | |
| else { | |
| break; | |
| } | |
| } | |
| }); | |
| } | |
| void Get (string url, Action<Stream> k) | |
| { | |
| var req = (HttpWebRequest)WebRequest.Create (url); | |
| req.CookieContainer = _cookies; | |
| var res = req.GetResponse (); | |
| using (var s = res.GetResponseStream ()) { | |
| k (s); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment