private async Task DownloadToFile(MetadataTask task, string pathToSave) { YouTubeVideo vid = task.SelectedVideo.YoutubeVideo; long totalDownloaded = 0; string tempFile = $"{pathToSave}.tmp"; string mp3File = $"{pathToSave}.mp3"; try { task.Status = MetadataState.RUNNING; task.Message = String.Format(Properties.Resources.COMMAND_MSG_URI_SEARCH); using (ChunkDownloader client = new ChunkDownloader()) { client.OnProgress += (new ProgressHandler(task)).HandleProgress; totalDownloaded = await client.DownloadToFile(vid.Uri, tempFile); } task.Message = String.Format(Properties.Resources.COMMAND_MSG_START_MP3, tempFile); FFMpegConverter converter = new FFMpegConverter(); converter.ConvertProgress += (new ConvertProgressHandler(task)).HandleProgress; converter.ConvertMedia(tempFile, mp3File, "mp3"); System.IO.File.Delete(tempFile); task.Status = MetadataState.METADATA; task.Message = String.Format(Properties.Resources.COMMAND_MSG_END_MP3, mp3File); } catch (Exception ex) { task.Status = MetadataState.ERROR; task.Message = ex.Message + Environment.NewLine + ex.StackTrace; } }
private async Task DownloadToFile(MetadataTask task, string pathToSave) { YouTubeVideo vid = task.SelectedVideo.YoutubeVideo; long totalDownloaded = 0; try { task.Status = MetadataState.RUNNING; task.Message = Properties.Resources.COMMAND_MSG_URI_SEARCH; using (ChunkDownloader client = new ChunkDownloader()) { client.OnProgress += (new ProgressHandler(task)).HandleProgress; totalDownloaded = await client.DownloadToFile(vid.Uri, pathToSave); } task.Status = MetadataState.METADATA; task.Message = String.Format(Properties.Resources.COMMAND_MSG_SUCCESS_DOWNLOAD, totalDownloaded.GetBeautifiedByteSize(), pathToSave); } catch (Exception ex) { task.Status = MetadataState.ERROR; task.Message = ex.Message + Environment.NewLine + ex.StackTrace; } }