Refactored write m3u, added error handling to replace playlist middleware