public static async Task <string> AudioFileToMP3(string filePath, bool deleteOriginal = true) { if (!File.Exists(filePath)) { throw new Exception("Couldn't locate file to convert."); } //Save file to the same location with changed extension string outputFilePath = Path.ChangeExtension(filePath, ".mp3"); outputFilePath = MusicTagging.ReplaceInvalidChars(outputFilePath); //replace any invalid chars in filePath with valid outputFilePath = MusicTagging.UpdateFileNameForDuplicates(outputFilePath); //add "copy" to filename if file exists //------------ Set library directory -------------- MusicConverting.setFFMPEGPath(); //get info of input file IMediaInfo mediaInfo = await MediaInfo.Get(filePath); IStream audioStream = mediaInfo.AudioStreams.FirstOrDefault(); //------------ do the conversion ---------------- await convertAudio(audioStream, outputFilePath); if (deleteOriginal) { File.Delete(filePath); //delete the original file } return(outputFilePath); }
public const string FFmpegLibraryPath_Linux = @"/usr/bin"; //linux location public static async Task <string> YoutubeAudioToMP3(string audioLink, string audioFormat, TimeSpan audioDuration, string filePath) { //Save file to the same location with changed extension string outputFilePath = Path.ChangeExtension(filePath, ".mp3"); outputFilePath = MusicTagging.ReplaceInvalidChars(outputFilePath); //replace any invalid chars in filePath with valid outputFilePath = MusicTagging.UpdateFileNameForDuplicates(outputFilePath); //add "copy" to filename if file exists //------------ Set library directory -------------- MusicConverting.setFFMPEGPath(); //----- Get youtube video audio stream ----------------- IStream audioStream = new WebStream(new Uri(audioLink), audioFormat, audioDuration); //--- do the conversion ---------------- await convertAudio(audioStream, outputFilePath); return(outputFilePath); }