Skip to content

Commit 09b4899

Browse files
committed
bub fix
1 parent 8030519 commit 09b4899

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

src/download.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,15 @@ fn download(req: Client, song_uri: String, arguments: &Arguments, is_track: bool
182182
download_audio(&mut song, arguments, &req, &mut temp_dir, client_id);
183183
}
184184
// check if we have legacy or non-legacy streaming downloaded
185-
let mut check = download_dir.clone();
185+
let mut check = temp_dir.clone();
186186
check.push("1.m4s");
187187
if check.exists() {
188188
file_type = FileType::M4S;
189189
}
190190

191191
match file_type {
192192
FileType::MP3 => {
193+
logging(Severities::DEBUG, format!("Downloading {} with file format MP3", song.name));
193194
download_dir.push(format!("{}.mp3",sanitize_song_name(&song.name)));
194195
let mut input_string = "concat:".to_string();
195196
for i in 0..song.audio_file_count {
@@ -215,31 +216,32 @@ fn download(req: Client, song_uri: String, arguments: &Arguments, is_track: bool
215216
add_metadata(song, &mut temp_dir, &download_dir);
216217
}
217218
FileType::M4S => {
218-
let mut buffer = Vec::new();
219+
logging(Severities::DEBUG, format!("Downloading {} with file format M4S", song.name));
220+
let mut buffer = Vec::new();
221+
let mut path = temp_dir.clone();
222+
path.push("0.mp3");
223+
let mut oo = OpenOptions::new().read(true).open(path).unwrap();
224+
oo.read_to_end(&mut buffer).unwrap();
225+
for i in 1..song.audio_file_count {
219226
let mut path = temp_dir.clone();
220-
path.push("0.mp3");
227+
path.push(format!("{i}.m4s"));
221228
let mut oo = OpenOptions::new().read(true).open(path).unwrap();
222229
oo.read_to_end(&mut buffer).unwrap();
223-
for i in 1..song.audio_file_count {
224-
let mut path = temp_dir.clone();
225-
path.push(format!("{i}.m4s"));
226-
let mut oo = OpenOptions::new().read(true).open(path).unwrap();
227-
oo.read_to_end(&mut buffer).unwrap();
228-
}
229-
download_dir.push("temp.mp4");
230-
let mut oo = OpenOptions::new().write(true).create(true).truncate(true).open(&download_dir).unwrap();
231-
oo.write_all(&buffer).unwrap();
232-
let mut convert = FfmpegCommand::new();
233-
convert.input(download_dir.to_str().unwrap());
234-
download_dir.pop();
235-
download_dir.push(format!("{}.mp3",sanitize_song_name(&song.name)));
236-
convert.output(download_dir.to_str().unwrap());
237-
convert.spawn().unwrap().wait().unwrap();
238-
let final_dir = download_dir.clone();
239-
download_dir.pop();
240-
download_dir.push("temp.mp4");
241-
std::fs::remove_file(download_dir).unwrap();
242-
add_metadata(song, &mut temp_dir, &final_dir);
230+
}
231+
download_dir.push("temp.mp4");
232+
let mut oo = OpenOptions::new().write(true).create(true).truncate(true).open(&download_dir).unwrap();
233+
oo.write_all(&buffer).unwrap();
234+
let mut convert = FfmpegCommand::new();
235+
convert.input(download_dir.to_str().unwrap());
236+
download_dir.pop();
237+
download_dir.push(format!("{}.mp3",sanitize_song_name(&song.name)));
238+
convert.output(download_dir.to_str().unwrap());
239+
convert.spawn().unwrap().wait().unwrap();
240+
let final_dir = download_dir.clone();
241+
download_dir.pop();
242+
download_dir.push("temp.mp4");
243+
std::fs::remove_file(download_dir).unwrap();
244+
add_metadata(song, &mut temp_dir, &final_dir);
243245
},
244246
FileType::Undefined => {
245247
logging(Severities::ERROR, format!("Something went wrong while trying to download song : {} | If this issue persists, please contact the developer", song.name));
@@ -382,7 +384,8 @@ fn download_audio(song: &mut Song, arguments: &Arguments, req: &Client, temp_dir
382384
logging(Severities::WARNING, format!("No download link found on song, trying next download method : {}",&song.name));
383385
continue;
384386
}
385-
let r = req.get(&r[8..r.len()-2]).headers(headers.clone()).send().unwrap().text().unwrap();
387+
logging(Severities::DEBUG, format!("Parsed URL : {}", &r[8..r.len()-19]));
388+
let r = req.get(&r[8..r.len()-19]).headers(headers.clone()).send().unwrap().text().unwrap();
386389
logging(Severities::INFO, format!("Valid download URL found, downloading song {}",song.name));
387390
let re = Regex::new(r#"(https://cf-hls-media.sndcdn.com/media/.*?|https://playback.media-streaming.soundcloud.cloud.*?)\n"#).unwrap();
388391
let links = re.captures_iter(&r);

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ Additional arguments:
9595
--temp-dir="path" - Sets the temporary folder location
9696
--download-dir="path" - Sets the download folder location
9797
--thread-count=10 - Sets the amount of threads (only valid for downloading playlist)
98-
--original-cover-size - Downloads the song cover in it's original size"#);
98+
--original-cover-size - Downloads the song cover in it's original size
99+
--disable-cache=true - Forces the program to redownload all the songs"#);
99100
exit(0);
100101
}
101102
if args.len() == 2 {

0 commit comments

Comments
 (0)