Skip to content

Commit

Permalink
cleanup partial audio/video streams
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdallas committed Nov 3, 2022
1 parent 46e2475 commit 7ca87aa
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/download.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Borrow;
use std::fmt::format;
use std::fs::File;
use std::path::Path;
use std::process::Command;
Expand Down Expand Up @@ -178,8 +179,8 @@ impl<'a> Downloader<'a> {
// explicitly adding an mp4 extension to make it easy to recognize in the finder
if (media_type == MediaType::RedditVideoWithoutAudio
|| media_type == MediaType::RedditVideoWithAudio)
&& !extension.ends_with(".mp4") {
extension = format!("{}.{}", extension, ".mp4");
&& !extension.ends_with("mp4") {
extension = format!("{}.{}", extension, "mp4");
}
let file_name = self.generate_file_name(
&url,
Expand Down Expand Up @@ -256,6 +257,12 @@ impl<'a> Downloader<'a> {
// check the status code of the ffmpeg command. if the command is unsuccessful,
// display the error and skip combining the media.
if output.status.success() {

for media_file in &media_files {
// Cleanup the files with the single stream components
fs::remove_file(media_file)?;
}

debug!("Successfully combined into temporary file: {:?}", temporary_file_name);
debug!("Renaming file: {} -> {}", temporary_file_name.display(), combined_file_name);
fs::rename(&temporary_file_name, &combined_file_name)?;
Expand Down Expand Up @@ -317,8 +324,7 @@ impl<'a> Downloader<'a> {
// media is overwritten by this method
let hash = md5::compute(url);
format!(
// TODO: Fixme, use appropriate prefix
"{}/{}/img-{:x}.{}",
"{}/{}/{:x}.{}",
self.data_directory, subreddit, hash, extension
)
} else {
Expand Down

0 comments on commit 7ca87aa

Please sign in to comment.