public override async void EndOfTrack(SpotifySession session) { session.PlayerPlay(false); wr.Close(); // Move File string album = downloadingTrack.Album().Name(); album = filterForFileName(album); var dir = downloadPath + album + "\\"; if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); string song = GetTrackFullName(downloadingTrack); song = filterForFileName(song); var fileName = dir + song + ".mp3"; try { File.Move("downloading", fileName); FileInfo fileInfo = new FileInfo(fileName); String path = fileInfo.DirectoryName; } catch (Exception e) { File.Delete("downloading"); LogString("Track deleted because the track already exists! Path: " + fileName + " Track Name:" + SpotifyDownloader.GetTrackFullName(downloadingTrack)); base.EndOfTrack(session); if (OnDownloadProgress != null) OnDownloadProgress(100); if (OnDownloadComplete != null) OnDownloadComplete(); return; } try { // Tag var u = new UltraID3(); //u.GetMPEGTrackInfo(); u.Read(fileName); u.Artist = GetTrackArtistsNames(downloadingTrack); u.Title = downloadingTrack.Name(); u.Album = downloadingTrack.Album().Name(); var imageID = downloadingTrack.Album().Cover(ImageSize.Large); var image = SpotifySharp.Image.Create(session, imageID); await WaitForBool(image.IsLoaded); var tc = TypeDescriptor.GetConverter(typeof(Bitmap)); var bmp = (Bitmap)tc.ConvertFrom(image.Data()); var pictureFrame = new ID3v23PictureFrame(bmp, PictureTypes.CoverFront, "image", TextEncodingTypes.ISO88591); u.ID3v2Tag.Frames.Add(pictureFrame); u.Write(); base.EndOfTrack(session); } catch (Exception e) { }; LogString("Track downloaded and saved! Path: " + fileName + " Track Name:" + SpotifyDownloader.GetTrackFullName(downloadingTrack)); if (OnDownloadProgress != null) OnDownloadProgress(100); if (OnDownloadComplete != null) OnDownloadComplete(); }
public override async void EndOfTrack(SpotifySession session) { session.PlayerPlay(false); wr.Close(); // Move File var dir = downloadPath + escape(downloadingTrack.Album().Name()) + "\\"; if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); var fileName = dir + escape(GetTrackFullName(downloadingTrack)) + ".mp3"; if(GetDownloadType() == DownloadType.OVERWRITE && File.Exists(fileName)) File.Delete(fileName); File.Move("downloading", fileName); // Tag var u = new UltraID3(); u.Read(fileName); u.Artist = GetTrackArtistsNames(downloadingTrack); u.Title = downloadingTrack.Name(); u.Album = downloadingTrack.Album().Name(); u.TrackNum = (short)downloadingTrack.Index(); var imageID = downloadingTrack.Album().Cover(ImageSize.Large); var image = SpotifySharp.Image.Create(session, imageID); await WaitForBool(image.IsLoaded); var tc = TypeDescriptor.GetConverter(typeof(Bitmap)); var bmp = (Bitmap)tc.ConvertFrom(image.Data()); var pictureFrame = new ID3v23PictureFrame(bmp, PictureTypes.CoverFront, "image", TextEncodingTypes.ISO88591); u.ID3v2Tag.Frames.Add(pictureFrame); u.Write(); base.EndOfTrack(session); if (OnDownloadProgress != null) OnDownloadProgress(100); if (OnDownloadComplete != null) OnDownloadComplete(true); }