Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var text = File.ReadAllText(@"e:\kefirPls.m3u", Encoding.GetEncoding(1251));
- Func<string,string> getFileName = s =>
- {
- foreach (char c in Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()).Concat(new[]{'.'}))
- {
- s = s.Replace(c.ToString(), "");
- }
- return s.Length > 100 ? s.Substring(0, 100) : s;
- };
- text.Substring(0, 200).Dump();
- var fileInfos = Regex.Matches(text, "#EXTINF:[0-9]+,(.*?)\n(.*)")
- .Cast<Match>()
- .Select(m=>new{Title=m.Groups[1].Value, Url=m.Groups[2].Value, FileName=getFileName(m.Groups[1].Value) + ".mp3"});
- foreach(var f in fileInfos)
- {
- f.Dump();
- var targetFile = Path.Combine(@"e:\KefirPls", f.FileName);
- if (!File.Exists(targetFile))
- {
- new WebClient().DownloadFile(f.Url, targetFile);
- }
- }
Add Comment
Please, Sign In to add comment