@@ -29,12 +29,22 @@ function download_song_from_url() {
2929 var headers = async_load[? " response_headers" ];
3030 var contentLength = -1 ;
3131 var contentDisposition = " " ;
32+ var contentType = " " ;
3233 if (headers > 0 ) {
3334 contentLength = headers[? " Content-Length" ];
34- contentDisposition = headers[? " Content-Disposition" ]
35+ contentDisposition = headers[? " Content-Disposition" ];
36+ contentType = headers[? " Content-Type" ];
3537 }
3638 var writtenFileSize = file_get_size (song_download_file);
3739
40+ // Check mimetype to see if response is a valid file
41+ var invalid_type = false ;
42+ if (!is_undefined (contentType)) {
43+ if !(contentType == " application/zip" || contentType == " application/octet-stream" ) {
44+ invalid_type = true
45+ }
46+ }
47+
3848 // Read file name from Content-Disposition header, if present
3949 var override_fn = " " ;
4050 if (!is_undefined (contentDisposition) && string_count (" attachment; filename=" , contentDisposition) > 0 ) { // attachment; filename="<song.nbs>"
@@ -45,7 +55,7 @@ function download_song_from_url() {
4555 override_fn = string_copy (contentDisposition, firstQuotePos, lastQuotePos - firstQuotePos);
4656 }
4757
48- if (contentLength > 0 && writtenFileSize == contentLength) {
58+ if (!invalid_type && contentLength > 0 && writtenFileSize == contentLength) {
4959 song_downloaded_size = song_total_size; // prevent freezing under 100%
5060 show_debug_message (override_fn);
5161 load_song (song_download_file, true ); // load as backup file (keep unsaved, don't add to recent etc.)
0 commit comments