From 3b1dcb2685d53e4c88fe518a64205a42f74d6ac7 Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 16:30:12 +0200 Subject: [PATCH 01/17] refactor: add XML doc on properties --- src/BandcampDownloader/Model/Album.cs | 22 ++++++++++++++++++++++ src/BandcampDownloader/Model/Track.cs | 22 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/BandcampDownloader/Model/Album.cs b/src/BandcampDownloader/Model/Album.cs index 30fada41..13c4c9e7 100644 --- a/src/BandcampDownloader/Model/Album.cs +++ b/src/BandcampDownloader/Model/Album.cs @@ -4,17 +4,39 @@ namespace BandcampDownloader { internal class Album { + + /// + /// The album artist. + /// public String Artist { get; set; } + + /// + /// The URL where the artwork should be downloaded from. + /// public String ArtworkUrl { get; set; } + /// + /// True if the album has an artwork; false otherwise. + /// public Boolean HasArtwork { get { return ArtworkUrl != null; } } + /// + /// The release date of the album. + /// public DateTime ReleaseDate { get; set; } + + /// + /// The album title. + /// public String Title { get; set; } + + /// + /// The list of tracks contained in the album. + /// public List Tracks { get; set; } } } \ No newline at end of file diff --git a/src/BandcampDownloader/Model/Track.cs b/src/BandcampDownloader/Model/Track.cs index c2874af0..5b4f9619 100644 --- a/src/BandcampDownloader/Model/Track.cs +++ b/src/BandcampDownloader/Model/Track.cs @@ -3,10 +3,30 @@ namespace BandcampDownloader { internal class Track { - public Double Duration { get; set; } // In seconds + + /// + /// The track length (in seconds). + /// + public Double Duration { get; set; } + + /// + /// The track lyrics. + /// public String Lyrics { get; set; } + + /// + /// The URL where the track should be downloaded from. + /// public String Mp3Url { get; set; } + + /// + /// The track number. + /// public int Number { get; set; } + + /// + /// The track title. + /// public String Title { get; set; } } } \ No newline at end of file From 773e40d006ad99caed5e000de68009c4109f79de Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 16:39:17 +0200 Subject: [PATCH 02/17] refactor: move static method outside of WindowMain --- src/BandcampDownloader/Helpers/FileHelper.cs | 22 +++++++++++++++ .../UI/Dialogs/WindowMain.xaml.cs | 27 +++---------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/BandcampDownloader/Helpers/FileHelper.cs b/src/BandcampDownloader/Helpers/FileHelper.cs index d0c3fcde..11ab9277 100644 --- a/src/BandcampDownloader/Helpers/FileHelper.cs +++ b/src/BandcampDownloader/Helpers/FileHelper.cs @@ -25,5 +25,27 @@ public static long GetFileSize(String url, String protocolMethod) { } return fileSize; } + + /// + /// Returns the download path for the specified album from the specified path format, by replacing the + /// placeholders strings with their corresponding values. If the path is too long (> 247 characters), it will + /// be stripped. + /// + /// The download path to parse. + /// The album. + public static String ParseDownloadPath(String downloadPath, Album album) { + downloadPath = downloadPath.Replace("{year}", album.ReleaseDate.Year.ToString().ToAllowedFileName()); + downloadPath = downloadPath.Replace("{month}", album.ReleaseDate.Month.ToString("00").ToAllowedFileName()); + downloadPath = downloadPath.Replace("{day}", album.ReleaseDate.Day.ToString("00").ToAllowedFileName()); + downloadPath = downloadPath.Replace("{artist}", album.Artist.ToAllowedFileName()); + downloadPath = downloadPath.Replace("{album}", album.Title.ToAllowedFileName()); + + if (downloadPath.Length >= 248) { + // Windows doesn't do well with path >= 248 characters (and path + filename >= 260 characters) + downloadPath = downloadPath.Substring(0, 247); + } + + return downloadPath; + } } } \ No newline at end of file diff --git a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs index fa9789b2..683cb3fb 100644 --- a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs +++ b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs @@ -164,7 +164,7 @@ private void DownloadAlbum(Album album, String downloadsFolder) { // Create playlist file if (App.UserSettings.CreatePlaylist) { - PlaylistHelper.SavePlaylistForAlbum(album, ParseDownloadPath(App.UserSettings.DownloadsPath, album)); + PlaylistHelper.SavePlaylistForAlbum(album, FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album)); Log($"Saved playlist for album \"{album.Title}\"", LogType.IntermediateSuccess); } @@ -768,27 +768,6 @@ private String ParseCoverArtFileName(Album album) { return fileName.ToAllowedFileName(); } - /// - /// Returns the download path for the specified album from the specified path format, by replacing the - /// placeholders strings with their corresponding values. - /// - /// The download path to parse. - /// The album currently downloaded. - private String ParseDownloadPath(String downloadPath, Album album) { - downloadPath = downloadPath.Replace("{year}", album.ReleaseDate.Year.ToString().ToAllowedFileName()); - downloadPath = downloadPath.Replace("{month}", album.ReleaseDate.Month.ToString("00").ToAllowedFileName()); - downloadPath = downloadPath.Replace("{day}", album.ReleaseDate.Day.ToString("00").ToAllowedFileName()); - downloadPath = downloadPath.Replace("{artist}", album.Artist.ToAllowedFileName()); - downloadPath = downloadPath.Replace("{album}", album.Title.ToAllowedFileName()); - - if (downloadPath.Length >= 248) { - // Windows doesn't do well with path >= 248 characters (and path + filename >= 260 characters) - downloadPath = downloadPath.Substring(0, 247); - } - - return downloadPath; - } - /// /// Returns the file name to be used for the specified track from the file name format saved in the UserSettings, /// by replacing the placeholders strings with their corresponding values. @@ -992,7 +971,7 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { if (App.UserSettings.DownloadOneAlbumAtATime) { // Download one album at a time foreach (Album album in albums) { - DownloadAlbum(album, ParseDownloadPath(App.UserSettings.DownloadsPath, album)); + DownloadAlbum(album, FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album)); } } else { // Parallel download @@ -1000,7 +979,7 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < albums.Count; i++) { Album album = albums[i]; // Mandatory or else => race condition tasks[i] = Task.Factory.StartNew(() => - DownloadAlbum(album, ParseDownloadPath(App.UserSettings.DownloadsPath, album))); + DownloadAlbum(album, FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album))); } // Wait for all albums to be downloaded Task.WaitAll(tasks); From 95d8c1bd0aa80762f700fd187bf254bd730bc92c Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 16:42:39 +0200 Subject: [PATCH 03/17] refactor: save track path in Track object --- src/BandcampDownloader/Model/Album.cs | 9 ++++ src/BandcampDownloader/Model/Track.cs | 40 ++++++++++++++ .../UI/Dialogs/WindowMain.xaml.cs | 52 ++++++------------- 3 files changed, 64 insertions(+), 37 deletions(-) diff --git a/src/BandcampDownloader/Model/Album.cs b/src/BandcampDownloader/Model/Album.cs index 13c4c9e7..1b6da78e 100644 --- a/src/BandcampDownloader/Model/Album.cs +++ b/src/BandcampDownloader/Model/Album.cs @@ -38,5 +38,14 @@ public Boolean HasArtwork { /// The list of tracks contained in the album. /// public List Tracks { get; set; } + /// + /// Sets the Path property of each Track from the specified folder. + /// + /// The full path where the tracks files should be saved. + public void SetTracksPath(String folderPath) { + foreach (Track track in Tracks) { + track.SetPath(folderPath, this); + } + } } } \ No newline at end of file diff --git a/src/BandcampDownloader/Model/Track.cs b/src/BandcampDownloader/Model/Track.cs index 5b4f9619..5e943d8d 100644 --- a/src/BandcampDownloader/Model/Track.cs +++ b/src/BandcampDownloader/Model/Track.cs @@ -24,9 +24,49 @@ internal class Track { /// public int Number { get; set; } + /// + /// The local path (full path with file name) where the track file should be saved. + /// + public String Path { get; private set; } + /// /// The track title. /// public String Title { get; set; } + + /// + /// Sets the Path property of the current Track from the specified folder. + /// + /// The full path where the track file should be saved. + /// The album of the current Track. + public void SetPath(String folderPath, Album album) { + String fileName = ParseTrackFileName(album); + + Path = folderPath + "\\" + fileName; + if (Path.Length >= 260) { + // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) + // Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext + int fileNameMaxLength = 12 - System.IO.Path.GetExtension(Path).Length; + Path = folderPath + "\\" + fileName.Substring(0, fileNameMaxLength) + System.IO.Path.GetExtension(Path); + } + } + + /// + /// Returns the file name to be used for the specified track and album from the file name format saved in the + /// UserSettings, by replacing the placeholders strings with their corresponding values. + /// The returned file name DOES contain the extension. + /// + /// The album of the specified track. + private String ParseTrackFileName(Album album) { + String fileName = App.UserSettings.FileNameFormat + .Replace("{year}", album.ReleaseDate.Year.ToString()) + .Replace("{month}", album.ReleaseDate.Month.ToString("00")) + .Replace("{day}", album.ReleaseDate.Day.ToString("00")) + .Replace("{album}", album.Title) + .Replace("{artist}", album.Artist) + .Replace("{title}", Title) + .Replace("{tracknum}", Number.ToString("00")); + return fileName.ToAllowedFileName(); + } } } \ No newline at end of file diff --git a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs index 683cb3fb..4224eab2 100644 --- a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs +++ b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs @@ -156,7 +156,7 @@ private void DownloadAlbum(Album album, String downloadsFolder) { for (int i = 0; i < album.Tracks.Count; i++) { // Temporarily save the index or we will have a race condition exception when i hits its maximum value int currentIndex = i; - tasks[currentIndex] = Task.Factory.StartNew(() => tracksDownloaded[currentIndex] = DownloadAndTagTrack(downloadsFolder, album, album.Tracks[currentIndex], artwork)); + tasks[currentIndex] = Task.Factory.StartNew(() => tracksDownloaded[currentIndex] = DownloadAndTagTrack(album, album.Tracks[currentIndex], artwork)); } // Wait for all tracks to be downloaded before saying the album is downloaded @@ -181,31 +181,22 @@ private void DownloadAlbum(Album album, String downloadsFolder) { /// /// Downloads and tags a track. Returns true if the track has been correctly downloaded; false otherwise. /// - /// The path where to save the tracks. /// The album of the track to download. /// The track to download. /// The cover art. - private Boolean DownloadAndTagTrack(String albumDirectoryPath, Album album, Track track, TagLib.Picture artwork) { + private Boolean DownloadAndTagTrack(Album album, Track track, TagLib.Picture artwork) { Log($"Downloading track \"{track.Title}\" from url: {track.Mp3Url}", LogType.VerboseInfo); - // Set path to save the file - String trackPath = albumDirectoryPath + "\\" + ParseTrackFileName(album, track); - if (trackPath.Length >= 260) { - // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) - // Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext - int fileNameMaxLength = 12 - Path.GetExtension(trackPath).ToString().Length; - trackPath = albumDirectoryPath + "\\" + ParseTrackFileName(album, track).Substring(0, fileNameMaxLength) + Path.GetExtension(trackPath); - } int tries = 0; Boolean trackDownloaded = false; - if (File.Exists(trackPath)) { - long length = new FileInfo(trackPath).Length; + if (File.Exists(track.Path)) { + long length = new FileInfo(track.Path).Length; foreach (TrackFile trackFile in _filesDownload) { if (track.Mp3Url == trackFile.Url && trackFile.Size > length - (trackFile.Size * App.UserSettings.AllowedFileSizeDifference) && trackFile.Size < length + (trackFile.Size * App.UserSettings.AllowedFileSizeDifference)) { - Log($"Track already exists within allowed file size range: track \"{ParseTrackFileName(album, track)}\" from album \"{album.Title}\" - Skipping download!", LogType.IntermediateSuccess); + Log($"Track already exists within allowed file size range: track \"{Path.GetFileName(track.Path)}\" from album \"{album.Title}\" - Skipping download!", LogType.IntermediateSuccess); return false; } } @@ -244,7 +235,7 @@ private Boolean DownloadAndTagTrack(String albumDirectoryPath, Album album, Trac if (App.UserSettings.ModifyTags) { // Tag (ID3) the file when downloaded - var tagFile = TagLib.File.Create(trackPath); + var tagFile = TagLib.File.Create(track.Path); tagFile = TagHelper.UpdateArtist(tagFile, album.Artist, App.UserSettings.TagArtist); tagFile = TagHelper.UpdateAlbumArtist(tagFile, album.Artist, App.UserSettings.TagAlbumArtist); tagFile = TagHelper.UpdateAlbumTitle(tagFile, album.Title, App.UserSettings.TagAlbumTitle); @@ -258,7 +249,7 @@ private Boolean DownloadAndTagTrack(String albumDirectoryPath, Album album, Trac if (App.UserSettings.SaveCoverArtInTags && artwork != null) { // Save cover in tags when downloaded - var tagFile = TagLib.File.Create(trackPath); + var tagFile = TagLib.File.Create(track.Path); tagFile.Tag.Pictures = new TagLib.IPicture[1] { artwork }; tagFile.Save(); } @@ -266,12 +257,12 @@ private Boolean DownloadAndTagTrack(String albumDirectoryPath, Album album, Trac // Note the file as downloaded TrackFile currentFile = _filesDownload.Where(f => f.Url == track.Mp3Url).First(); currentFile.Downloaded = true; - Log($"Downloaded track \"{ParseTrackFileName(album, track)}\" from album \"{album.Title}\"", LogType.IntermediateSuccess); + Log($"Downloaded track \"{Path.GetFileName(track.Path)}\" from album \"{album.Title}\"", LogType.IntermediateSuccess); } else if (!e.Cancelled && e.Error != null) { if (tries + 1 < App.UserSettings.DownloadMaxTries) { - Log($"Unable to download track \"{ParseTrackFileName(album, track)}\" from album \"{album.Title}\". Try {tries + 1} of {App.UserSettings.DownloadMaxTries}", LogType.Warning); + Log($"Unable to download track \"{Path.GetFileName(track.Path)}\" from album \"{album.Title}\". Try {tries + 1} of {App.UserSettings.DownloadMaxTries}", LogType.Warning); } else { - Log($"Unable to download track \"{ParseTrackFileName(album, track)}\" from album \"{album.Title}\". Hit max retries of {App.UserSettings.DownloadMaxTries}", LogType.Error); + Log($"Unable to download track \"{Path.GetFileName(track.Path)}\" from album \"{album.Title}\". Hit max retries of {App.UserSettings.DownloadMaxTries}", LogType.Error); } } // Else the download has been cancelled (by the user) @@ -291,7 +282,7 @@ private Boolean DownloadAndTagTrack(String albumDirectoryPath, Album album, Trac // Register current download _pendingDownloads.Add(webClient); // Start download - webClient.DownloadFileAsync(new Uri(track.Mp3Url), trackPath); + webClient.DownloadFileAsync(new Uri(track.Mp3Url), track.Path); } // Wait for download to be finished doneEvent.WaitOne(); @@ -768,23 +759,6 @@ private String ParseCoverArtFileName(Album album) { return fileName.ToAllowedFileName(); } - /// - /// Returns the file name to be used for the specified track from the file name format saved in the UserSettings, - /// by replacing the placeholders strings with their corresponding values. - /// - /// The album currently downloaded. - /// The track currently downloaded. - private String ParseTrackFileName(Album album, Track track) { - String fileName = App.UserSettings.FileNameFormat - .Replace("{year}", album.ReleaseDate.Year.ToString()) - .Replace("{month}", album.ReleaseDate.Month.ToString("00")) - .Replace("{day}", album.ReleaseDate.Day.ToString("00")) - .Replace("{album}", album.Title) - .Replace("{artist}", album.Artist) - .Replace("{title}", track.Title) - .Replace("{tracknum}", track.Number.ToString("00")); - return fileName.ToAllowedFileName(); - } /// /// Updates the state of the controls. @@ -948,6 +922,10 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { }).ContinueWith(x => { // Get info on albums albums = GetAlbums(urls); + // Compute paths for tracks and artworks + foreach (Album album in albums) { + album.SetTracksPath(FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album)); + } }).ContinueWith(x => { // Save files to download (we'll need the list to update the progressBar) _filesDownload = GetFilesToDownload(albums, App.UserSettings.SaveCoverArtInTags || App.UserSettings.SaveCoverArtInFolder); From 043034ff460bf406156957245fb05e8d2c4fc7a5 Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 16:43:25 +0200 Subject: [PATCH 04/17] refactor: save artwork path in Album object --- src/BandcampDownloader/App.xaml.cs | 4 ++ src/BandcampDownloader/Model/Album.cs | 54 ++++++++++++++++++ .../UI/Dialogs/WindowMain.xaml.cs | 57 +++---------------- 3 files changed, 67 insertions(+), 48 deletions(-) diff --git a/src/BandcampDownloader/App.xaml.cs b/src/BandcampDownloader/App.xaml.cs index 9f92b000..89b60108 100644 --- a/src/BandcampDownloader/App.xaml.cs +++ b/src/BandcampDownloader/App.xaml.cs @@ -7,6 +7,10 @@ namespace BandcampDownloader { public partial class App: Application { + /// + /// Random class used to create random numbers. + /// + public static readonly Random Random = new Random(); /// /// The settings chosen by the user. diff --git a/src/BandcampDownloader/Model/Album.cs b/src/BandcampDownloader/Model/Album.cs index 1b6da78e..f6600a33 100644 --- a/src/BandcampDownloader/Model/Album.cs +++ b/src/BandcampDownloader/Model/Album.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; namespace BandcampDownloader { @@ -10,6 +11,16 @@ internal class Album { /// public String Artist { get; set; } + /// + /// The local path (full path with file name) where the artwork file should be saved. + /// + public String ArtworkPath { get; private set; } + + /// + /// The local path (full path with file name) to the %TEMP% folder where the artwork file should be saved. + /// + public String ArtworkTempPath { get; private set; } + /// /// The URL where the artwork should be downloaded from. /// @@ -38,6 +49,34 @@ public Boolean HasArtwork { /// The list of tracks contained in the album. /// public List Tracks { get; set; } + + /// + /// Sets the ArtworkPath and ArtworkTempPath properties. + /// + /// The full path where the artwork file should be saved. + public void SetArtworkPaths(String folderPath) { + if (HasArtwork) { + String artworkFileExt = Path.GetExtension(ArtworkUrl); + + // In order to prevent #54 (artworkTempPath used at the same time by another downloading thread), we'll add a random number to the name of the artwork file saved in Temp directory + String randomNumber = App.Random.Next(1, 1000).ToString("00#"); + + // Compute paths where to save artwork + ArtworkTempPath = Path.GetTempPath() + "\\" + ParseCoverArtFileName() + randomNumber + artworkFileExt; + ArtworkPath = folderPath + "\\" + ParseCoverArtFileName() + artworkFileExt; + + if (ArtworkTempPath.Length >= 260 || ArtworkPath.Length >= 260) { + // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) + // Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext + // There may be only one path needed to shorten, but it's better to use the same file name in both places + int fileNameInTempMaxLength = 12 - randomNumber.Length - artworkFileExt.Length; + int fileNameInFolderMaxLength = 12 - artworkFileExt.Length; + ArtworkTempPath = Path.GetTempPath() + "\\" + ParseCoverArtFileName().Substring(0, fileNameInTempMaxLength) + randomNumber + artworkFileExt; + ArtworkPath = folderPath + "\\" + ParseCoverArtFileName().Substring(0, fileNameInFolderMaxLength) + artworkFileExt; + } + } + } + /// /// Sets the Path property of each Track from the specified folder. /// @@ -47,5 +86,20 @@ public void SetTracksPath(String folderPath) { track.SetPath(folderPath, this); } } + + /// + /// Returns the file name to be used for the cover art of the specified album from the file name format saved in + /// the UserSettings, by replacing the placeholders strings with their corresponding values. + /// The returned file name does NOT contain the extension. + /// + private String ParseCoverArtFileName() { + String fileName = App.UserSettings.CoverArtFileNameFormat + .Replace("{year}", ReleaseDate.Year.ToString()) + .Replace("{month}", ReleaseDate.Month.ToString("00")) + .Replace("{day}", ReleaseDate.Day.ToString("00")) + .Replace("{album}", Title) + .Replace("{artist}", Artist); + return fileName.ToAllowedFileName(); + } } } \ No newline at end of file diff --git a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs index 4224eab2..d921cf27 100644 --- a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs +++ b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs @@ -29,10 +29,6 @@ public partial class WindowMain: Window { #region Fields - /// - /// Random class used to create random numbers. - /// - private readonly Random _random = new Random(); /// /// True if there are active downloads; false otherwise. /// @@ -147,7 +143,7 @@ private void DownloadAlbum(Album album, String downloadsFolder) { // Download artwork if ((App.UserSettings.SaveCoverArtInTags || App.UserSettings.SaveCoverArtInFolder) && album.HasArtwork) { - artwork = DownloadCoverArt(album, downloadsFolder); + artwork = DownloadCoverArt(album); } // Download & tag tracks @@ -299,27 +295,7 @@ private Boolean DownloadAndTagTrack(Album album, Track track, TagLib.Picture art /// Downloads the cover art and returns the one to save in tags. /// /// The album to download. - /// The path where to save the cover art. - private TagLib.Picture DownloadCoverArt(Album album, String downloadsFolder) { - String artworkFileExt = Path.GetExtension(album.ArtworkUrl); - - // In order to prevent #54 (artworkTempPath used at the same time by another downloading thread), we'll add a random number to the name of the artwork file saved in Temp directory - String randomNumber = _random.Next(1, 1000).ToString("00#"); - - // Compute paths where to save artwork - String artworkTempPath = Path.GetTempPath() + "\\" + ParseCoverArtFileName(album) + randomNumber + artworkFileExt; - String artworkFolderPath = downloadsFolder + "\\" + ParseCoverArtFileName(album) + artworkFileExt; - - if (artworkTempPath.Length >= 260 || artworkFolderPath.Length >= 260) { - // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) - // Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext - // There may be only one path needed to shorten, but it's better to use the same file name in both places - int fileNameInTempMaxLength = 12 - randomNumber.Length - artworkFileExt.Length; - int fileNameInFolderMaxLength = 12 - artworkFileExt.Length; - artworkTempPath = Path.GetTempPath() + "\\" + ParseCoverArtFileName(album).Substring(0, fileNameInTempMaxLength) + randomNumber + artworkFileExt; - artworkFolderPath = downloadsFolder + "\\" + ParseCoverArtFileName(album).Substring(0, fileNameInFolderMaxLength) + artworkFileExt; - } - + private TagLib.Picture DownloadCoverArt(Album album) { TagLib.Picture artworkInTags = null; int tries = 0; @@ -367,9 +343,9 @@ private TagLib.Picture DownloadCoverArt(Album album, String downloadsFolder) { settings.MaxHeight = App.UserSettings.CoverArtInFolderMaxSize; settings.MaxWidth = App.UserSettings.CoverArtInFolderMaxSize; } - ImageBuilder.Current.Build(artworkTempPath, artworkFolderPath, settings); // Save it to the album folder + ImageBuilder.Current.Build(album.ArtworkTempPath, album.ArtworkPath, settings); // Save it to the album folder } else if (App.UserSettings.SaveCoverArtInFolder) { - File.Copy(artworkTempPath, artworkFolderPath, true); + File.Copy(album.ArtworkTempPath, album.ArtworkPath, true); } // Convert/resize artwork to be saved in tags @@ -383,12 +359,12 @@ private TagLib.Picture DownloadCoverArt(Album album, String downloadsFolder) { settings.MaxHeight = App.UserSettings.CoverArtInTagsMaxSize; settings.MaxWidth = App.UserSettings.CoverArtInTagsMaxSize; } - ImageBuilder.Current.Build(artworkTempPath, artworkTempPath, settings); // Save it to %Temp% + ImageBuilder.Current.Build(album.ArtworkTempPath, album.ArtworkTempPath, settings); // Save it to %Temp% } - artworkInTags = new TagLib.Picture(artworkTempPath) { Description = "Picture" }; + artworkInTags = new TagLib.Picture(album.ArtworkTempPath) { Description = "Picture" }; try { - File.Delete(artworkTempPath); + File.Delete(album.ArtworkTempPath); } catch { // Could not delete the file. Nevermind, it's in %Temp% folder... } @@ -421,7 +397,7 @@ private TagLib.Picture DownloadCoverArt(Album album, String downloadsFolder) { // Register current download _pendingDownloads.Add(webClient); // Start download - webClient.DownloadFileAsync(new Uri(album.ArtworkUrl), artworkTempPath); + webClient.DownloadFileAsync(new Uri(album.ArtworkUrl), album.ArtworkTempPath); } // Wait for download to be finished @@ -744,22 +720,6 @@ private void Log(String message, LogType logType) { } } - /// - /// Returns the file name to be used for the cover art of the specified album from the file name format saved in - /// the UserSettings, by replacing the placeholders strings with their corresponding values. - /// - /// The album currently downloaded. - private String ParseCoverArtFileName(Album album) { - String fileName = App.UserSettings.CoverArtFileNameFormat - .Replace("{year}", album.ReleaseDate.Year.ToString()) - .Replace("{month}", album.ReleaseDate.Month.ToString("00")) - .Replace("{day}", album.ReleaseDate.Day.ToString("00")) - .Replace("{album}", album.Title) - .Replace("{artist}", album.Artist); - return fileName.ToAllowedFileName(); - } - - /// /// Updates the state of the controls. /// @@ -924,6 +884,7 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { albums = GetAlbums(urls); // Compute paths for tracks and artworks foreach (Album album in albums) { + album.SetArtworkPaths(FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album)); album.SetTracksPath(FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album)); } }).ContinueWith(x => { From fe740aee800836d3ee94b640ff54b60c09166b4a Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 16:43:59 +0200 Subject: [PATCH 05/17] fix: save correct track path in playlist file Fixes #82 --- src/BandcampDownloader/Helpers/PlaylistHelper.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/BandcampDownloader/Helpers/PlaylistHelper.cs b/src/BandcampDownloader/Helpers/PlaylistHelper.cs index 75ddc0c7..84614abc 100644 --- a/src/BandcampDownloader/Helpers/PlaylistHelper.cs +++ b/src/BandcampDownloader/Helpers/PlaylistHelper.cs @@ -70,7 +70,7 @@ private static String CreateM3uPlaylist(Album album) { Album = album.Title, AlbumArtist = album.Artist, Duration = TimeSpan.FromSeconds(track.Duration), - Path = track.Title + ".mp3", + Path = Path.GetFileName(track.Path), Title = track.Title, }); } @@ -88,7 +88,7 @@ private static String CreatePlsPlaylist(Album album) { foreach (Track track in album.Tracks) { playlist.PlaylistEntries.Add(new PlsPlaylistEntry() { Length = TimeSpan.FromSeconds(track.Duration), - Path = track.Title + ".mp3", + Path = Path.GetFileName(track.Path), Title = track.Title, }); } @@ -110,7 +110,7 @@ private static String CreateWplPlaylist(Album album) { AlbumArtist = album.Artist, AlbumTitle = album.Title, Duration = TimeSpan.FromSeconds(track.Duration), - Path = track.Title + ".mp3", + Path = Path.GetFileName(track.Path), TrackArtist = album.Artist, TrackTitle = track.Title, }); @@ -133,7 +133,7 @@ private static String CreateZplPlaylist(Album album) { AlbumArtist = album.Artist, AlbumTitle = album.Title, Duration = TimeSpan.FromSeconds(track.Duration), - Path = track.Title + ".mp3", + Path = Path.GetFileName(track.Path), TrackArtist = album.Artist, TrackTitle = track.Title, }); From 3dda4e98f082a450a3cb34c2e1c229e8f2b0409f Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 16:47:27 +0200 Subject: [PATCH 06/17] refactor: rename ParseDownloadPath method --- src/BandcampDownloader/Helpers/FileHelper.cs | 2 +- src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BandcampDownloader/Helpers/FileHelper.cs b/src/BandcampDownloader/Helpers/FileHelper.cs index 11ab9277..e7fa97f5 100644 --- a/src/BandcampDownloader/Helpers/FileHelper.cs +++ b/src/BandcampDownloader/Helpers/FileHelper.cs @@ -33,7 +33,7 @@ public static long GetFileSize(String url, String protocolMethod) { /// /// The download path to parse. /// The album. - public static String ParseDownloadPath(String downloadPath, Album album) { + public static String ParseAlbumPath(String downloadPath, Album album) { downloadPath = downloadPath.Replace("{year}", album.ReleaseDate.Year.ToString().ToAllowedFileName()); downloadPath = downloadPath.Replace("{month}", album.ReleaseDate.Month.ToString("00").ToAllowedFileName()); downloadPath = downloadPath.Replace("{day}", album.ReleaseDate.Day.ToString("00").ToAllowedFileName()); diff --git a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs index d921cf27..ee6004fd 100644 --- a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs +++ b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs @@ -160,7 +160,7 @@ private void DownloadAlbum(Album album, String downloadsFolder) { // Create playlist file if (App.UserSettings.CreatePlaylist) { - PlaylistHelper.SavePlaylistForAlbum(album, FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album)); + PlaylistHelper.SavePlaylistForAlbum(album, FileHelper.ParseAlbumPath(App.UserSettings.DownloadsPath, album)); Log($"Saved playlist for album \"{album.Title}\"", LogType.IntermediateSuccess); } @@ -884,8 +884,8 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { albums = GetAlbums(urls); // Compute paths for tracks and artworks foreach (Album album in albums) { - album.SetArtworkPaths(FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album)); - album.SetTracksPath(FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album)); + album.SetArtworkPaths(FileHelper.ParseAlbumPath(App.UserSettings.DownloadsPath, album)); + album.SetTracksPath(FileHelper.ParseAlbumPath(App.UserSettings.DownloadsPath, album)); } }).ContinueWith(x => { // Save files to download (we'll need the list to update the progressBar) @@ -910,7 +910,7 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { if (App.UserSettings.DownloadOneAlbumAtATime) { // Download one album at a time foreach (Album album in albums) { - DownloadAlbum(album, FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album)); + DownloadAlbum(album, FileHelper.ParseAlbumPath(App.UserSettings.DownloadsPath, album)); } } else { // Parallel download @@ -918,7 +918,7 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < albums.Count; i++) { Album album = albums[i]; // Mandatory or else => race condition tasks[i] = Task.Factory.StartNew(() => - DownloadAlbum(album, FileHelper.ParseDownloadPath(App.UserSettings.DownloadsPath, album))); + DownloadAlbum(album, FileHelper.ParseAlbumPath(App.UserSettings.DownloadsPath, album))); } // Wait for all albums to be downloaded Task.WaitAll(tasks); From 33ed06485659fea87221d079243848024c644f06 Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 16:50:07 +0200 Subject: [PATCH 07/17] docs: improve XML doc --- src/BandcampDownloader/Model/Album.cs | 4 ++-- src/BandcampDownloader/Model/Track.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BandcampDownloader/Model/Album.cs b/src/BandcampDownloader/Model/Album.cs index f6600a33..95dafe5c 100644 --- a/src/BandcampDownloader/Model/Album.cs +++ b/src/BandcampDownloader/Model/Album.cs @@ -53,7 +53,7 @@ public Boolean HasArtwork { /// /// Sets the ArtworkPath and ArtworkTempPath properties. /// - /// The full path where the artwork file should be saved. + /// The full path to the folder where the artwork file should be saved. public void SetArtworkPaths(String folderPath) { if (HasArtwork) { String artworkFileExt = Path.GetExtension(ArtworkUrl); @@ -80,7 +80,7 @@ public void SetArtworkPaths(String folderPath) { /// /// Sets the Path property of each Track from the specified folder. /// - /// The full path where the tracks files should be saved. + /// The full path to the folder where the tracks files should be saved. public void SetTracksPath(String folderPath) { foreach (Track track in Tracks) { track.SetPath(folderPath, this); diff --git a/src/BandcampDownloader/Model/Track.cs b/src/BandcampDownloader/Model/Track.cs index 5e943d8d..8caa39f7 100644 --- a/src/BandcampDownloader/Model/Track.cs +++ b/src/BandcampDownloader/Model/Track.cs @@ -37,7 +37,7 @@ internal class Track { /// /// Sets the Path property of the current Track from the specified folder. /// - /// The full path where the track file should be saved. + /// The full path to the folder where the track file should be saved. /// The album of the current Track. public void SetPath(String folderPath, Album album) { String fileName = ParseTrackFileName(album); From 0eea8ced7f18e171eb4a76b9a71d76a5e7710555 Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 16:58:13 +0200 Subject: [PATCH 08/17] refactor: move ParseAlbumPath method to Album class --- src/BandcampDownloader/Helpers/FileHelper.cs | 22 ------------------- src/BandcampDownloader/Model/Album.cs | 20 +++++++++++++++++ .../UI/Dialogs/WindowMain.xaml.cs | 10 ++++----- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/BandcampDownloader/Helpers/FileHelper.cs b/src/BandcampDownloader/Helpers/FileHelper.cs index e7fa97f5..d0c3fcde 100644 --- a/src/BandcampDownloader/Helpers/FileHelper.cs +++ b/src/BandcampDownloader/Helpers/FileHelper.cs @@ -25,27 +25,5 @@ public static long GetFileSize(String url, String protocolMethod) { } return fileSize; } - - /// - /// Returns the download path for the specified album from the specified path format, by replacing the - /// placeholders strings with their corresponding values. If the path is too long (> 247 characters), it will - /// be stripped. - /// - /// The download path to parse. - /// The album. - public static String ParseAlbumPath(String downloadPath, Album album) { - downloadPath = downloadPath.Replace("{year}", album.ReleaseDate.Year.ToString().ToAllowedFileName()); - downloadPath = downloadPath.Replace("{month}", album.ReleaseDate.Month.ToString("00").ToAllowedFileName()); - downloadPath = downloadPath.Replace("{day}", album.ReleaseDate.Day.ToString("00").ToAllowedFileName()); - downloadPath = downloadPath.Replace("{artist}", album.Artist.ToAllowedFileName()); - downloadPath = downloadPath.Replace("{album}", album.Title.ToAllowedFileName()); - - if (downloadPath.Length >= 248) { - // Windows doesn't do well with path >= 248 characters (and path + filename >= 260 characters) - downloadPath = downloadPath.Substring(0, 247); - } - - return downloadPath; - } } } \ No newline at end of file diff --git a/src/BandcampDownloader/Model/Album.cs b/src/BandcampDownloader/Model/Album.cs index 95dafe5c..174e1502 100644 --- a/src/BandcampDownloader/Model/Album.cs +++ b/src/BandcampDownloader/Model/Album.cs @@ -50,6 +50,26 @@ public Boolean HasArtwork { /// public List Tracks { get; set; } + /// + /// Returns the folder path from the specified path format, by replacing the placeholders strings with their + /// corresponding values. If the path is too long (> 247 characters), it will be stripped. + /// + /// The download path to parse. + public String ParseFolderPath(String downloadPath) { + downloadPath = downloadPath.Replace("{year}", ReleaseDate.Year.ToString().ToAllowedFileName()); + downloadPath = downloadPath.Replace("{month}", ReleaseDate.Month.ToString("00").ToAllowedFileName()); + downloadPath = downloadPath.Replace("{day}", ReleaseDate.Day.ToString("00").ToAllowedFileName()); + downloadPath = downloadPath.Replace("{artist}", Artist.ToAllowedFileName()); + downloadPath = downloadPath.Replace("{album}", Title.ToAllowedFileName()); + + if (downloadPath.Length >= 248) { + // Windows doesn't do well with path >= 248 characters (and path + filename >= 260 characters) + downloadPath = downloadPath.Substring(0, 247); + } + + return downloadPath; + } + /// /// Sets the ArtworkPath and ArtworkTempPath properties. /// diff --git a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs index ee6004fd..b3de0540 100644 --- a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs +++ b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs @@ -160,7 +160,7 @@ private void DownloadAlbum(Album album, String downloadsFolder) { // Create playlist file if (App.UserSettings.CreatePlaylist) { - PlaylistHelper.SavePlaylistForAlbum(album, FileHelper.ParseAlbumPath(App.UserSettings.DownloadsPath, album)); + PlaylistHelper.SavePlaylistForAlbum(album, album.ParseFolderPath(App.UserSettings.DownloadsPath)); Log($"Saved playlist for album \"{album.Title}\"", LogType.IntermediateSuccess); } @@ -884,8 +884,8 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { albums = GetAlbums(urls); // Compute paths for tracks and artworks foreach (Album album in albums) { - album.SetArtworkPaths(FileHelper.ParseAlbumPath(App.UserSettings.DownloadsPath, album)); - album.SetTracksPath(FileHelper.ParseAlbumPath(App.UserSettings.DownloadsPath, album)); + album.SetArtworkPaths(album.ParseFolderPath(App.UserSettings.DownloadsPath)); + album.SetTracksPath(album.ParseFolderPath(App.UserSettings.DownloadsPath)); } }).ContinueWith(x => { // Save files to download (we'll need the list to update the progressBar) @@ -910,7 +910,7 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { if (App.UserSettings.DownloadOneAlbumAtATime) { // Download one album at a time foreach (Album album in albums) { - DownloadAlbum(album, FileHelper.ParseAlbumPath(App.UserSettings.DownloadsPath, album)); + DownloadAlbum(album, album.ParseFolderPath(App.UserSettings.DownloadsPath)); } } else { // Parallel download @@ -918,7 +918,7 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < albums.Count; i++) { Album album = albums[i]; // Mandatory or else => race condition tasks[i] = Task.Factory.StartNew(() => - DownloadAlbum(album, FileHelper.ParseAlbumPath(App.UserSettings.DownloadsPath, album))); + DownloadAlbum(album, album.ParseFolderPath(App.UserSettings.DownloadsPath))); } // Wait for all albums to be downloaded Task.WaitAll(tasks); From 8d0aeee9b83d17e510c936192dee36d80dcc615e Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 17:07:58 +0200 Subject: [PATCH 09/17] refactor: save album path in Album object --- src/BandcampDownloader/Model/Album.cs | 62 +++++++++++-------- src/BandcampDownloader/Model/Track.cs | 9 ++- .../UI/Dialogs/WindowMain.xaml.cs | 16 ++--- 3 files changed, 48 insertions(+), 39 deletions(-) diff --git a/src/BandcampDownloader/Model/Album.cs b/src/BandcampDownloader/Model/Album.cs index 174e1502..31086953 100644 --- a/src/BandcampDownloader/Model/Album.cs +++ b/src/BandcampDownloader/Model/Album.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; namespace BandcampDownloader { @@ -35,6 +34,11 @@ public Boolean HasArtwork { } } + /// + /// The local path (full path) to the folder where the album should be saved. + /// + public String Path { get; private set; } + /// /// The release date of the album. /// @@ -51,39 +55,26 @@ public Boolean HasArtwork { public List Tracks { get; set; } /// - /// Returns the folder path from the specified path format, by replacing the placeholders strings with their - /// corresponding values. If the path is too long (> 247 characters), it will be stripped. + /// Sets the Path property of the current album. /// /// The download path to parse. - public String ParseFolderPath(String downloadPath) { - downloadPath = downloadPath.Replace("{year}", ReleaseDate.Year.ToString().ToAllowedFileName()); - downloadPath = downloadPath.Replace("{month}", ReleaseDate.Month.ToString("00").ToAllowedFileName()); - downloadPath = downloadPath.Replace("{day}", ReleaseDate.Day.ToString("00").ToAllowedFileName()); - downloadPath = downloadPath.Replace("{artist}", Artist.ToAllowedFileName()); - downloadPath = downloadPath.Replace("{album}", Title.ToAllowedFileName()); - - if (downloadPath.Length >= 248) { - // Windows doesn't do well with path >= 248 characters (and path + filename >= 260 characters) - downloadPath = downloadPath.Substring(0, 247); - } - - return downloadPath; + public void SetAlbumPath(String downloadPath) { + Path = ParseFolderPath(downloadPath); } /// /// Sets the ArtworkPath and ArtworkTempPath properties. /// - /// The full path to the folder where the artwork file should be saved. - public void SetArtworkPaths(String folderPath) { + public void SetArtworkPaths() { if (HasArtwork) { - String artworkFileExt = Path.GetExtension(ArtworkUrl); + String artworkFileExt = System.IO.Path.GetExtension(ArtworkUrl); // In order to prevent #54 (artworkTempPath used at the same time by another downloading thread), we'll add a random number to the name of the artwork file saved in Temp directory String randomNumber = App.Random.Next(1, 1000).ToString("00#"); // Compute paths where to save artwork - ArtworkTempPath = Path.GetTempPath() + "\\" + ParseCoverArtFileName() + randomNumber + artworkFileExt; - ArtworkPath = folderPath + "\\" + ParseCoverArtFileName() + artworkFileExt; + ArtworkTempPath = System.IO.Path.GetTempPath() + "\\" + ParseCoverArtFileName() + randomNumber + artworkFileExt; + ArtworkPath = Path + "\\" + ParseCoverArtFileName() + artworkFileExt; if (ArtworkTempPath.Length >= 260 || ArtworkPath.Length >= 260) { // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) @@ -91,8 +82,8 @@ public void SetArtworkPaths(String folderPath) { // There may be only one path needed to shorten, but it's better to use the same file name in both places int fileNameInTempMaxLength = 12 - randomNumber.Length - artworkFileExt.Length; int fileNameInFolderMaxLength = 12 - artworkFileExt.Length; - ArtworkTempPath = Path.GetTempPath() + "\\" + ParseCoverArtFileName().Substring(0, fileNameInTempMaxLength) + randomNumber + artworkFileExt; - ArtworkPath = folderPath + "\\" + ParseCoverArtFileName().Substring(0, fileNameInFolderMaxLength) + artworkFileExt; + ArtworkTempPath = System.IO.Path.GetTempPath() + "\\" + ParseCoverArtFileName().Substring(0, fileNameInTempMaxLength) + randomNumber + artworkFileExt; + ArtworkPath = Path + "\\" + ParseCoverArtFileName().Substring(0, fileNameInFolderMaxLength) + artworkFileExt; } } } @@ -100,10 +91,9 @@ public void SetArtworkPaths(String folderPath) { /// /// Sets the Path property of each Track from the specified folder. /// - /// The full path to the folder where the tracks files should be saved. - public void SetTracksPath(String folderPath) { + public void SetTracksPath() { foreach (Track track in Tracks) { - track.SetPath(folderPath, this); + track.SetPath(this); } } @@ -121,5 +111,25 @@ private String ParseCoverArtFileName() { .Replace("{artist}", Artist); return fileName.ToAllowedFileName(); } + + /// + /// Returns the folder path from the specified path format, by replacing the placeholders strings with their + /// corresponding values. If the path is too long (> 247 characters), it will be stripped. + /// + /// The download path to parse. + private String ParseFolderPath(String downloadPath) { + downloadPath = downloadPath.Replace("{year}", ReleaseDate.Year.ToString().ToAllowedFileName()); + downloadPath = downloadPath.Replace("{month}", ReleaseDate.Month.ToString("00").ToAllowedFileName()); + downloadPath = downloadPath.Replace("{day}", ReleaseDate.Day.ToString("00").ToAllowedFileName()); + downloadPath = downloadPath.Replace("{artist}", Artist.ToAllowedFileName()); + downloadPath = downloadPath.Replace("{album}", Title.ToAllowedFileName()); + + if (downloadPath.Length >= 248) { + // Windows doesn't do well with path >= 248 characters (and path + filename >= 260 characters) + downloadPath = downloadPath.Substring(0, 247); + } + + return downloadPath; + } } } \ No newline at end of file diff --git a/src/BandcampDownloader/Model/Track.cs b/src/BandcampDownloader/Model/Track.cs index 8caa39f7..2b1e075b 100644 --- a/src/BandcampDownloader/Model/Track.cs +++ b/src/BandcampDownloader/Model/Track.cs @@ -37,17 +37,16 @@ internal class Track { /// /// Sets the Path property of the current Track from the specified folder. /// - /// The full path to the folder where the track file should be saved. /// The album of the current Track. - public void SetPath(String folderPath, Album album) { + public void SetPath(Album album) { String fileName = ParseTrackFileName(album); - Path = folderPath + "\\" + fileName; + Path = album.Path + "\\" + fileName; if (Path.Length >= 260) { // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) - // Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext + // album.Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext int fileNameMaxLength = 12 - System.IO.Path.GetExtension(Path).Length; - Path = folderPath + "\\" + fileName.Substring(0, fileNameMaxLength) + System.IO.Path.GetExtension(Path); + Path = album.Path + "\\" + fileName.Substring(0, fileNameMaxLength) + System.IO.Path.GetExtension(Path); } } diff --git a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs index b3de0540..d48e9e5d 100644 --- a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs +++ b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs @@ -124,8 +124,7 @@ private void CheckForUpdates() { /// Downloads an album. /// /// The album to download. - /// The path where to save the album. - private void DownloadAlbum(Album album, String downloadsFolder) { + private void DownloadAlbum(Album album) { if (_userCancelled) { // Abort return; @@ -133,7 +132,7 @@ private void DownloadAlbum(Album album, String downloadsFolder) { // Create directory to place track files try { - Directory.CreateDirectory(downloadsFolder); + Directory.CreateDirectory(album.Path); } catch { Log("An error occured when creating the album folder. Make sure you have the rights to write files in the folder you chose", LogType.Error); return; @@ -160,7 +159,7 @@ private void DownloadAlbum(Album album, String downloadsFolder) { // Create playlist file if (App.UserSettings.CreatePlaylist) { - PlaylistHelper.SavePlaylistForAlbum(album, album.ParseFolderPath(App.UserSettings.DownloadsPath)); + PlaylistHelper.SavePlaylistForAlbum(album, album.Path); Log($"Saved playlist for album \"{album.Title}\"", LogType.IntermediateSuccess); } @@ -884,8 +883,9 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { albums = GetAlbums(urls); // Compute paths for tracks and artworks foreach (Album album in albums) { - album.SetArtworkPaths(album.ParseFolderPath(App.UserSettings.DownloadsPath)); - album.SetTracksPath(album.ParseFolderPath(App.UserSettings.DownloadsPath)); + album.SetAlbumPath(App.UserSettings.DownloadsPath); + album.SetArtworkPaths(); + album.SetTracksPath(); } }).ContinueWith(x => { // Save files to download (we'll need the list to update the progressBar) @@ -910,7 +910,7 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { if (App.UserSettings.DownloadOneAlbumAtATime) { // Download one album at a time foreach (Album album in albums) { - DownloadAlbum(album, album.ParseFolderPath(App.UserSettings.DownloadsPath)); + DownloadAlbum(album); } } else { // Parallel download @@ -918,7 +918,7 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < albums.Count; i++) { Album album = albums[i]; // Mandatory or else => race condition tasks[i] = Task.Factory.StartNew(() => - DownloadAlbum(album, album.ParseFolderPath(App.UserSettings.DownloadsPath))); + DownloadAlbum(album)); } // Wait for all albums to be downloaded Task.WaitAll(tasks); From 203fb719e2b6ee0ad2f8d0570f546a7b20c5fb7d Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 17:55:56 +0200 Subject: [PATCH 10/17] refactor: save album path when creating new Album --- src/BandcampDownloader/Model/Album.cs | 12 +++++++---- .../Model/JSON/JsonAlbum.cs | 20 +++++++++---------- .../UI/Dialogs/WindowMain.xaml.cs | 1 - 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/BandcampDownloader/Model/Album.cs b/src/BandcampDownloader/Model/Album.cs index 31086953..9b2dcaea 100644 --- a/src/BandcampDownloader/Model/Album.cs +++ b/src/BandcampDownloader/Model/Album.cs @@ -55,11 +55,15 @@ public Boolean HasArtwork { public List Tracks { get; set; } /// - /// Sets the Path property of the current album. + /// Initializes a new Album. /// - /// The download path to parse. - public void SetAlbumPath(String downloadPath) { - Path = ParseFolderPath(downloadPath); + public Album(String artist, String artworkUrl, DateTime releaseDate, String title) { + Artist = artist; + ArtworkUrl = artworkUrl; + ReleaseDate = releaseDate; + Title = title; + // Must be done after other properties are filled! + Path = ParseFolderPath(App.UserSettings.DownloadsPath); } /// diff --git a/src/BandcampDownloader/Model/JSON/JsonAlbum.cs b/src/BandcampDownloader/Model/JSON/JsonAlbum.cs index d1a992db..faf5c04d 100644 --- a/src/BandcampDownloader/Model/JSON/JsonAlbum.cs +++ b/src/BandcampDownloader/Model/JSON/JsonAlbum.cs @@ -25,16 +25,16 @@ internal class JsonAlbum { public List Tracks { get; set; } public Album ToAlbum() { - return new Album() { - Artist = Artist, - // Some albums do not have a cover art - ArtworkUrl = ArtId == null ? null : _urlStart + ArtId.PadLeft(10, '0') + _urlEnd, - ReleaseDate = ReleaseDate, - Title = AlbumData.AlbumTitle, - // Some tracks do not have their URL filled on some albums (pre-release...) - // Forget those tracks here - Tracks = Tracks.Where(t => t.File != null).Select(t => t.ToTrack()).ToList() - }; + // Some albums do not have a cover art + String artworkUrl = ArtId == null ? null : _urlStart + ArtId.PadLeft(10, '0') + _urlEnd; + + var album = new Album(Artist, artworkUrl, ReleaseDate, AlbumData.AlbumTitle); + + // Some tracks do not have their URL filled on some albums (pre-release...) + // Forget those tracks here + album.Tracks = Tracks.Where(t => t.File != null).Select(t => t.ToTrack(album)).ToList(); + + return album; } } } \ No newline at end of file diff --git a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs index d48e9e5d..8014bf13 100644 --- a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs +++ b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs @@ -883,7 +883,6 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { albums = GetAlbums(urls); // Compute paths for tracks and artworks foreach (Album album in albums) { - album.SetAlbumPath(App.UserSettings.DownloadsPath); album.SetArtworkPaths(); album.SetTracksPath(); } From fe0f35b9ed4a3dd74e84b1e90ebd95f0b2e09a69 Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 17:56:26 +0200 Subject: [PATCH 11/17] refactor: store Album in Track --- src/BandcampDownloader/Model/Album.cs | 2 +- .../Model/JSON/JsonTrack.cs | 4 +- src/BandcampDownloader/Model/Track.cs | 42 ++++++++++++------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/BandcampDownloader/Model/Album.cs b/src/BandcampDownloader/Model/Album.cs index 9b2dcaea..56f88977 100644 --- a/src/BandcampDownloader/Model/Album.cs +++ b/src/BandcampDownloader/Model/Album.cs @@ -97,7 +97,7 @@ public void SetArtworkPaths() { /// public void SetTracksPath() { foreach (Track track in Tracks) { - track.SetPath(this); + track.SetPath(); } } diff --git a/src/BandcampDownloader/Model/JSON/JsonTrack.cs b/src/BandcampDownloader/Model/JSON/JsonTrack.cs index 117fc6d5..a547aa8d 100644 --- a/src/BandcampDownloader/Model/JSON/JsonTrack.cs +++ b/src/BandcampDownloader/Model/JSON/JsonTrack.cs @@ -20,8 +20,8 @@ internal class JsonTrack { [JsonProperty("title")] public String Title { get; set; } - public Track ToTrack() { - return new Track() { + public Track ToTrack(Album album) { + return new Track(album) { Duration = Duration, Mp3Url = (File.Url.StartsWith("//") ? "http:" : "") + File.Url, // "//example.com" Uri lacks protocol Number = Number == 0 ? 1 : Number, // For bandcamp track pages, Number will be 0. Set 1 instead diff --git a/src/BandcampDownloader/Model/Track.cs b/src/BandcampDownloader/Model/Track.cs index 2b1e075b..2de19062 100644 --- a/src/BandcampDownloader/Model/Track.cs +++ b/src/BandcampDownloader/Model/Track.cs @@ -4,6 +4,11 @@ namespace BandcampDownloader { internal class Track { + /// + /// The track album. + /// + public Album Album { get; set; } + /// /// The track length (in seconds). /// @@ -35,34 +40,39 @@ internal class Track { public String Title { get; set; } /// - /// Sets the Path property of the current Track from the specified folder. + /// Initializes a new Track. + /// + /// The track album. + public Track(Album album) { + Album = album; + } + + /// + /// Sets the Path property of the current Track. /// - /// The album of the current Track. - public void SetPath(Album album) { - String fileName = ParseTrackFileName(album); + public void SetPath() { + String fileName = ParseTrackFileName(); - Path = album.Path + "\\" + fileName; + Path = Album.Path + "\\" + fileName; if (Path.Length >= 260) { // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) // album.Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext int fileNameMaxLength = 12 - System.IO.Path.GetExtension(Path).Length; - Path = album.Path + "\\" + fileName.Substring(0, fileNameMaxLength) + System.IO.Path.GetExtension(Path); + Path = Album.Path + "\\" + fileName.Substring(0, fileNameMaxLength) + System.IO.Path.GetExtension(Path); } } /// - /// Returns the file name to be used for the specified track and album from the file name format saved in the - /// UserSettings, by replacing the placeholders strings with their corresponding values. - /// The returned file name DOES contain the extension. + /// Returns the file name to be used for the track from the file name format saved in the UserSettings, by + /// replacing the placeholders strings with their corresponding values. The returned file name DOES contain the extension. /// - /// The album of the specified track. - private String ParseTrackFileName(Album album) { + private String ParseTrackFileName() { String fileName = App.UserSettings.FileNameFormat - .Replace("{year}", album.ReleaseDate.Year.ToString()) - .Replace("{month}", album.ReleaseDate.Month.ToString("00")) - .Replace("{day}", album.ReleaseDate.Day.ToString("00")) - .Replace("{album}", album.Title) - .Replace("{artist}", album.Artist) + .Replace("{year}", Album.ReleaseDate.Year.ToString()) + .Replace("{month}", Album.ReleaseDate.Month.ToString("00")) + .Replace("{day}", Album.ReleaseDate.Day.ToString("00")) + .Replace("{album}", Album.Title) + .Replace("{artist}", Album.Artist) .Replace("{title}", Title) .Replace("{tracknum}", Number.ToString("00")); return fileName.ToAllowedFileName(); From afb926ba79d82c74ffcd5c479efc7103157885f6 Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 18:01:09 +0200 Subject: [PATCH 12/17] refactor: save artwork path when creating new Album --- src/BandcampDownloader/Model/Album.cs | 53 ++++++++++--------- .../UI/Dialogs/WindowMain.xaml.cs | 1 - 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/BandcampDownloader/Model/Album.cs b/src/BandcampDownloader/Model/Album.cs index 56f88977..ed1fc259 100644 --- a/src/BandcampDownloader/Model/Album.cs +++ b/src/BandcampDownloader/Model/Album.cs @@ -64,32 +64,7 @@ public Album(String artist, String artworkUrl, DateTime releaseDate, String titl Title = title; // Must be done after other properties are filled! Path = ParseFolderPath(App.UserSettings.DownloadsPath); - } - - /// - /// Sets the ArtworkPath and ArtworkTempPath properties. - /// - public void SetArtworkPaths() { - if (HasArtwork) { - String artworkFileExt = System.IO.Path.GetExtension(ArtworkUrl); - - // In order to prevent #54 (artworkTempPath used at the same time by another downloading thread), we'll add a random number to the name of the artwork file saved in Temp directory - String randomNumber = App.Random.Next(1, 1000).ToString("00#"); - - // Compute paths where to save artwork - ArtworkTempPath = System.IO.Path.GetTempPath() + "\\" + ParseCoverArtFileName() + randomNumber + artworkFileExt; - ArtworkPath = Path + "\\" + ParseCoverArtFileName() + artworkFileExt; - - if (ArtworkTempPath.Length >= 260 || ArtworkPath.Length >= 260) { - // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) - // Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext - // There may be only one path needed to shorten, but it's better to use the same file name in both places - int fileNameInTempMaxLength = 12 - randomNumber.Length - artworkFileExt.Length; - int fileNameInFolderMaxLength = 12 - artworkFileExt.Length; - ArtworkTempPath = System.IO.Path.GetTempPath() + "\\" + ParseCoverArtFileName().Substring(0, fileNameInTempMaxLength) + randomNumber + artworkFileExt; - ArtworkPath = Path + "\\" + ParseCoverArtFileName().Substring(0, fileNameInFolderMaxLength) + artworkFileExt; - } - } + SetArtworkPaths(); } /// @@ -135,5 +110,31 @@ private String ParseFolderPath(String downloadPath) { return downloadPath; } + + /// + /// Sets the ArtworkPath and ArtworkTempPath properties. + /// + private void SetArtworkPaths() { + if (HasArtwork) { + String artworkFileExt = System.IO.Path.GetExtension(ArtworkUrl); + + // In order to prevent #54 (artworkTempPath used at the same time by another downloading thread), we'll add a random number to the name of the artwork file saved in Temp directory + String randomNumber = App.Random.Next(1, 1000).ToString("00#"); + + // Compute paths where to save artwork + ArtworkTempPath = System.IO.Path.GetTempPath() + "\\" + ParseCoverArtFileName() + randomNumber + artworkFileExt; + ArtworkPath = Path + "\\" + ParseCoverArtFileName() + artworkFileExt; + + if (ArtworkTempPath.Length >= 260 || ArtworkPath.Length >= 260) { + // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) + // Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext + // There may be only one path needed to shorten, but it's better to use the same file name in both places + int fileNameInTempMaxLength = 12 - randomNumber.Length - artworkFileExt.Length; + int fileNameInFolderMaxLength = 12 - artworkFileExt.Length; + ArtworkTempPath = System.IO.Path.GetTempPath() + "\\" + ParseCoverArtFileName().Substring(0, fileNameInTempMaxLength) + randomNumber + artworkFileExt; + ArtworkPath = Path + "\\" + ParseCoverArtFileName().Substring(0, fileNameInFolderMaxLength) + artworkFileExt; + } + } + } } } \ No newline at end of file diff --git a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs index 8014bf13..7e71d63a 100644 --- a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs +++ b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs @@ -883,7 +883,6 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { albums = GetAlbums(urls); // Compute paths for tracks and artworks foreach (Album album in albums) { - album.SetArtworkPaths(); album.SetTracksPath(); } }).ContinueWith(x => { From 5b41d438e3d3349be2f791762a2d4a0e0c77eabc Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 18:19:06 +0200 Subject: [PATCH 13/17] refactor: save track path when creating new Track --- src/BandcampDownloader/Model/Album.cs | 9 ----- .../Model/JSON/JsonTrack.cs | 11 ++--- src/BandcampDownloader/Model/Track.cs | 40 +++++++++++-------- .../UI/Dialogs/WindowMain.xaml.cs | 4 -- 4 files changed, 27 insertions(+), 37 deletions(-) diff --git a/src/BandcampDownloader/Model/Album.cs b/src/BandcampDownloader/Model/Album.cs index ed1fc259..76d86edf 100644 --- a/src/BandcampDownloader/Model/Album.cs +++ b/src/BandcampDownloader/Model/Album.cs @@ -67,15 +67,6 @@ public Album(String artist, String artworkUrl, DateTime releaseDate, String titl SetArtworkPaths(); } - /// - /// Sets the Path property of each Track from the specified folder. - /// - public void SetTracksPath() { - foreach (Track track in Tracks) { - track.SetPath(); - } - } - /// /// Returns the file name to be used for the cover art of the specified album from the file name format saved in /// the UserSettings, by replacing the placeholders strings with their corresponding values. diff --git a/src/BandcampDownloader/Model/JSON/JsonTrack.cs b/src/BandcampDownloader/Model/JSON/JsonTrack.cs index a547aa8d..b5bb67e8 100644 --- a/src/BandcampDownloader/Model/JSON/JsonTrack.cs +++ b/src/BandcampDownloader/Model/JSON/JsonTrack.cs @@ -21,13 +21,10 @@ internal class JsonTrack { public String Title { get; set; } public Track ToTrack(Album album) { - return new Track(album) { - Duration = Duration, - Mp3Url = (File.Url.StartsWith("//") ? "http:" : "") + File.Url, // "//example.com" Uri lacks protocol - Number = Number == 0 ? 1 : Number, // For bandcamp track pages, Number will be 0. Set 1 instead - Title = Title, - Lyrics = Lyrics - }; + String mp3Url = (File.Url.StartsWith("//") ? "http:" : "") + File.Url; // "//example.com" Uri lacks protocol + int number = Number == 0 ? 1 : Number; // For bandcamp track pages, Number will be 0. Set 1 instead + + return new Track(album, Duration, Lyrics, mp3Url, number, Title); } } } \ No newline at end of file diff --git a/src/BandcampDownloader/Model/Track.cs b/src/BandcampDownloader/Model/Track.cs index 2de19062..3eb0eadb 100644 --- a/src/BandcampDownloader/Model/Track.cs +++ b/src/BandcampDownloader/Model/Track.cs @@ -42,24 +42,15 @@ internal class Track { /// /// Initializes a new Track. /// - /// The track album. - public Track(Album album) { + public Track(Album album, Double duration, String lyrics, String mp3Url, int number, String title) { Album = album; - } - - /// - /// Sets the Path property of the current Track. - /// - public void SetPath() { - String fileName = ParseTrackFileName(); - - Path = Album.Path + "\\" + fileName; - if (Path.Length >= 260) { - // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) - // album.Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext - int fileNameMaxLength = 12 - System.IO.Path.GetExtension(Path).Length; - Path = Album.Path + "\\" + fileName.Substring(0, fileNameMaxLength) + System.IO.Path.GetExtension(Path); - } + Duration = duration; + Lyrics = lyrics; + Mp3Url = mp3Url; + Number = number; + Title = title; + // Must be done after other properties are filled! + SetPath(); } /// @@ -77,5 +68,20 @@ private String ParseTrackFileName() { .Replace("{tracknum}", Number.ToString("00")); return fileName.ToAllowedFileName(); } + + /// + /// Sets the Path property of the current Track. + /// + private void SetPath() { + String fileName = ParseTrackFileName(); + + Path = Album.Path + "\\" + fileName; + if (Path.Length >= 260) { + // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) + // album.Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext + int fileNameMaxLength = 12 - System.IO.Path.GetExtension(Path).Length; + Path = Album.Path + "\\" + fileName.Substring(0, fileNameMaxLength) + System.IO.Path.GetExtension(Path); + } + } } } \ No newline at end of file diff --git a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs index 7e71d63a..311ba3bb 100644 --- a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs +++ b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs @@ -881,10 +881,6 @@ private void ButtonStart_Click(object sender, RoutedEventArgs e) { }).ContinueWith(x => { // Get info on albums albums = GetAlbums(urls); - // Compute paths for tracks and artworks - foreach (Album album in albums) { - album.SetTracksPath(); - } }).ContinueWith(x => { // Save files to download (we'll need the list to update the progressBar) _filesDownload = GetFilesToDownload(albums, App.UserSettings.SaveCoverArtInTags || App.UserSettings.SaveCoverArtInFolder); From 3ee5ab37479bd19576757ef0576cc0098a9151df Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 18:22:56 +0200 Subject: [PATCH 14/17] refactor: simplify member access --- src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs index 311ba3bb..e3166f03 100644 --- a/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs +++ b/src/BandcampDownloader/UI/Dialogs/WindowMain.xaml.cs @@ -953,7 +953,7 @@ private void ButtonStop_Click(object sender, RoutedEventArgs e) { } buttonStop.IsEnabled = false; - progressBar.Foreground = System.Windows.Media.Brushes.Red; + progressBar.Foreground = Brushes.Red; progressBar.IsIndeterminate = true; TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None; TaskbarItemInfo.ProgressValue = 0; From 3d0ba0b2b1fd6a8e71b27c1c8a6f588c52d3399e Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 18:43:27 +0200 Subject: [PATCH 15/17] refactor: SetPath method --- src/BandcampDownloader/Model/Track.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/BandcampDownloader/Model/Track.cs b/src/BandcampDownloader/Model/Track.cs index 3eb0eadb..c5c68689 100644 --- a/src/BandcampDownloader/Model/Track.cs +++ b/src/BandcampDownloader/Model/Track.cs @@ -50,7 +50,7 @@ public Track(Album album, Double duration, String lyrics, String mp3Url, int num Number = number; Title = title; // Must be done after other properties are filled! - SetPath(); + Path = ParseTrackFilePath(); } /// @@ -70,18 +70,21 @@ private String ParseTrackFileName() { } /// - /// Sets the Path property of the current Track. + /// Returns the file path to be used for the track from the file name format saved in the UserSettings, by + /// replacing the placeholders strings with their corresponding values. The returned file path DOES contain the extension. /// - private void SetPath() { + private String ParseTrackFilePath() { String fileName = ParseTrackFileName(); - Path = Album.Path + "\\" + fileName; - if (Path.Length >= 260) { + String path = Album.Path + "\\" + fileName; + if (path.Length >= 260) { // Windows doesn't do well with path + filename >= 260 characters (and path >= 248 characters) // album.Path has been shorten to 247 characters before, so we have 12 characters max left for filename.ext - int fileNameMaxLength = 12 - System.IO.Path.GetExtension(Path).Length; - Path = Album.Path + "\\" + fileName.Substring(0, fileNameMaxLength) + System.IO.Path.GetExtension(Path); + int fileNameMaxLength = 12 - System.IO.Path.GetExtension(path).Length; + path = Album.Path + "\\" + fileName.Substring(0, fileNameMaxLength) + System.IO.Path.GetExtension(path); } + + return path; } } } \ No newline at end of file From 9ed0728eea66c6c7b41381249f3e5c8efe977c4d Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 18:56:39 +0200 Subject: [PATCH 16/17] docs: add 0.2.8.2 to CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d7c5e52..fb03e1fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.2.8.2 + +## Bug fixes + +* Fixed the track path stored in playlist files. [#82](https://github.com/Otiel/BandcampDownloader/issues/82) + # 0.2.8.1 ## Bug fixes From 0ce56ea129b769ae4a0583bb41ac9f005e03e0aa Mon Sep 17 00:00:00 2001 From: Otiel Date: Thu, 25 Apr 2019 18:56:55 +0200 Subject: [PATCH 17/17] chore: bump assembly version to 0.2.8.2 --- src/BandcampDownloader/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BandcampDownloader/Properties/AssemblyInfo.cs b/src/BandcampDownloader/Properties/AssemblyInfo.cs index b36acb14..f47b2df1 100644 --- a/src/BandcampDownloader/Properties/AssemblyInfo.cs +++ b/src/BandcampDownloader/Properties/AssemblyInfo.cs @@ -51,6 +51,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.8.1")] -[assembly: AssemblyFileVersion("0.2.8.1")] +[assembly: AssemblyVersion("0.2.8.2")] +[assembly: AssemblyFileVersion("0.2.8.2")] [assembly: GuidAttribute("8C171C7F-9BAC-4EC0-A287-59908B48953F")]