When I try to download a Qobuz playlist , it fails to create the playlist file with the filename .m3u8 in the playlist root folder. When the playlist name has illegal characters in its name, the file can not be created and it's thrown an exception by the operating system.
To remove the illegal characters in the filename, the following character replacement is recommended before writing contents with System.IO.File.WriteAllText call.
string qobuzPlaylistName_IllegalCharactersRemoved = string.Concat(qobuzPlaylist.Name.Split(Path.GetInvalidFileNameChars()));
// or you can replace illegal characters with a special character like "_"
string qobuzPlaylistName_IllegalCharactersRemoved = string.Join("_", qobuzPlaylist.Name.Split(Path.GetInvalidFileNameChars()));
// Write m3u playlist to file, override if exists
string m3uPlaylistFile = Path.Combine(playlistBasePath, $"{qobuzPlaylistName_IllegalCharactersRemoved}.m3u8");
System.IO.File.WriteAllText(m3uPlaylistFile, PlaylistToTextHelper.ToText(m3uPlaylist), System.Text.Encoding.UTF8);
The stacktrace of the error is as follows(in Download_Errors.log);
Playlist Download Task ERROR.
System.NotSupportedException: The given path's format is not supported.
at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost)
at System.IO.File.WriteAllText(String path, String contents, Encoding encoding)
at QobuzDownloaderX.Shared.DownloadManager.d__43.MoveNext()
Is this a regression?
To Reproduce
Try to download https://play.qobuz.com/playlist/4824548 to a network folder path..
The songs are downloaded successfully without any problem. But the m3ufile can not be created due to illegal characters in the filename.
1.
2.
3.
4.
Expected behaviour
*
Screenshots
The stacktrace of the error is as follows;
Playlist Download Task ERROR.
System.NotSupportedException: The given path's format is not supported.
at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost)
at System.IO.File.WriteAllText(String path, String contents, Encoding encoding)
at QobuzDownloaderX.Shared.DownloadManager.d__43.MoveNext()
Thank you for the detailed bug description and suggested fix.
The StringTools helper class already contained all required methods, I just forgot to apply them to the name of the playlist file :-\
🐞 Bug Report
Describe the bug
When I try to download a Qobuz playlist , it fails to create the playlist file with the filename.m3u8 in the playlist root folder. When the playlist name has illegal characters in its name, the file can not be created and it's thrown an exception by the operating system.
To remove the illegal characters in the filename, the following character replacement is recommended before writing contents with System.IO.File.WriteAllText call.
Please see--> https://stackoverflow.com/questions/7348768/the-given-paths-format-is-not-supported
string qobuzPlaylistName_IllegalCharactersRemoved = string.Concat(qobuzPlaylist.Name.Split(Path.GetInvalidFileNameChars())); // or you can replace illegal characters with a special character like "_" string qobuzPlaylistName_IllegalCharactersRemoved = string.Join("_", qobuzPlaylist.Name.Split(Path.GetInvalidFileNameChars()));
// Write m3u playlist to file, override if exists string m3uPlaylistFile = Path.Combine(playlistBasePath, $"{qobuzPlaylistName_IllegalCharactersRemoved}.m3u8"); System.IO.File.WriteAllText(m3uPlaylistFile, PlaylistToTextHelper.ToText(m3uPlaylist), System.Text.Encoding.UTF8);
The stacktrace of the error is as follows(in Download_Errors.log);
Playlist Download Task ERROR. System.NotSupportedException: The given path's format is not supported. at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost) at System.IO.File.WriteAllText(String path, String contents, Encoding encoding) at QobuzDownloaderX.Shared.DownloadManager.d__43.MoveNext()
Is this a regression?
To Reproduce
Try to download https://play.qobuz.com/playlist/4824548 to a network folder path.. The songs are downloaded successfully without any problem. But the m3ufile can not be created due to illegal characters in the filename.
1. 2. 3. 4.
Expected behaviour
*
Screenshots
The stacktrace of the error is as follows;
Playlist Download Task ERROR. System.NotSupportedException: The given path's format is not supported. at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost) at System.IO.File.WriteAllText(String path, String contents, Encoding encoding) at QobuzDownloaderX.Shared.DownloadManager.d__43.MoveNext()
Additional context
*