Skip to content

Commit

Permalink
Ensure normalization file doesn't override original file
Browse files Browse the repository at this point in the history
  • Loading branch information
bertyhell committed Jul 29, 2017
1 parent 6eb7d3c commit 9c09ae7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
Binary file modified PlaylistDownloader.exe
Binary file not shown.
Binary file modified PlaylistDownloader.zip
Binary file not shown.
19 changes: 11 additions & 8 deletions PlaylistDownloader/PlaylistDownloader/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ protected override void OnDoWork(DoWorkEventArgs args)

public async Task<string> DownloadPlaylistItem(PlaylistItem item)
{
string filePath = null;
string filePathWithoutExtension = null;

item.DownloadProgress = 5;
if (!string.IsNullOrWhiteSpace(item.Name))
{

YoutubeLink youtubeLink = YoutubeSearcher.GetYoutubeLinks(item.Name).FirstOrDefault();
item.FileName = MakeValidFileName(youtubeLink.Label);
filePath = Path.Combine(_runSettings.SongsFolder, item.FileName + ".mp3");
filePathWithoutExtension = Path.Combine(_runSettings.SongsFolder, item.FileName);

if (!File.Exists(filePath))
if (!File.Exists(filePathWithoutExtension + ".mp3"))
{
item.DownloadProgress = 10;

Expand All @@ -107,14 +107,14 @@ public async Task<string> DownloadPlaylistItem(PlaylistItem item)
}
else
{

// Download videoand extract the mp3 file
await StartProcess(
_runSettings.YoutubeDlPath,
string.Format(" --ffmpeg-location \"{3}\"" +
string.Format(" --ffmpeg-location \"{0}\"" +
" --extract-audio" +
" --audio-format mp3" +
" --output \"{2}\\{0}.%(ext)s\" {1}", item.FileName, youtubeLink.Url, _runSettings.SongsFolder, _runSettings.FfmpegPath),
" --output \"{1}\"" +
" {2}", _runSettings.FfmpegPath, filePathWithoutExtension + "-raw.mp3", youtubeLink.Url),
item,
ParseYoutubeDlProgress);

Expand All @@ -124,9 +124,12 @@ await StartProcess(_runSettings.FfmpegPath,
" -af loudnorm=I=-16:TP=-1.5:LRA=11" +
" -ar 48k" +
" -y" +
" \"{1}\"", filePath, new Regex("\\.mp3$").Replace(filePath, _runSettings.NormalizedSuffix + ".mp3")),
" \"{1}\"", filePathWithoutExtension + "-raw.mp3", filePathWithoutExtension + _runSettings.NormalizedSuffix + ".mp3"),
item,
ParseYoutubeDlProgress);

// Delete the non normalized file after completion if not in debug mode
File.Delete(Path.Combine(_runSettings.SongsFolder, item.FileName + "-raw.mp3"));
}
}
}
Expand All @@ -135,7 +138,7 @@ await StartProcess(_runSettings.FfmpegPath,
_progress++;
OnProgressChanged(new ProgressChangedEventArgs(_progress * 100 / _totalSongs, null));

return filePath;
return filePathWithoutExtension;
}

private void ParseYoutubeDlProgress(string consoleLine, PlaylistItem item)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PlaylistDownloader 1.9
======================
PlaylistDownloader 1.9.1
========================

Download your whole playlist with one click of a button

Expand Down

0 comments on commit 9c09ae7

Please sign in to comment.