/// <summary> /// Get track info from the filename /// </summary> /// <param name = "mintracklen">Min track length</param> /// <param name = "maxtracklen">Max track length</param> /// <param name = "filename">Filename from which to extract the requested info</param> /// <param name = "audioService">Audio audioService to read tags</param> /// <returns>Track to be analyzed further / null if the track is not eligible</returns> public static Track GetTrackInfo(int mintracklen, int maxtracklen, string filename, BassAudioService audioService) { TAG_INFO tags = audioService.GetTagInfoFromFile(filename); //get file tags string artist, title; double duration; if (tags == null) { /*The song does not contain any tags*/ artist = "Unknown"; title = "Unknown"; duration = 60; } else { /*The song contains related tags*/ artist = tags.artist; title = tags.title; duration = tags.duration; } if (String.IsNullOrEmpty(artist)) /*assign a name to music files that don't have tags*/ artist = "Unknown"; if (String.IsNullOrEmpty(title)) /*assign a title to music files that don't have tags*/ title = "Unknown"; if (duration < mintracklen || duration > maxtracklen) /*check the duration of a music file*/ return null; Track track = new Track { Artist = artist, Title = title, TrackLength = duration, Path = Path.GetFullPath(filename) }; return track; }
public void GetTagInfoFromFileTest() { string name = MethodBase.GetCurrentMethod().Name; using (BassAudioService audioService = new BassAudioService()) { TAG_INFO tags = audioService.GetTagInfoFromFile(Path.GetFullPath(PathToMp3)); Assert.IsNotNull(tags); Assert.IsNotNull(tags.artist); Assert.IsNotNull(tags.title); Assert.IsNotNull(tags.duration); } }
private void ProcessFiles() { Action finishDel = delegate { buttonStop.Enabled = false; buttonPause.Enabled = false; buttonStartConversion.Enabled = true; stopped = false; }; Process process = new Process { StartInfo = { FileName = "ffmpeg.exe", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardInput = true, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false } }; Action del = delegate { labelCurrentProcessed.Text = currentProceesedFiles.ToString(); labelSkipped.Text = skipped.ToString(); richTextBox1.AppendText(process.StandardError.ReadToEnd() + "\n"); richTextBox1.Focus(); richTextBox1.SelectionStart = richTextBox1.Text.Length; }; using (BassAudioService audioService = new BassAudioService()) { foreach (string f in fileList) { if (stopped) { Invoke(finishDel); Thread.CurrentThread.Abort(); } while (pause) { if (stopped) { Invoke(finishDel); Thread.CurrentThread.Abort(); } Thread.Sleep(1000); } TAG_INFO tags = null; try { //Read Tags from the file tags = audioService.GetTagInfoFromFile(f); } catch { skipped++; currentProceesedFiles++; Invoke(del); continue; } //Compose the output name of the wav file if (String.IsNullOrEmpty(tags.title) || tags.title.Length == 0) { //Skip file skipped++; currentProceesedFiles++; Invoke(del); continue; } string artist = ""; if (String.IsNullOrEmpty(tags.artist)) { if (tags.composer == null) { skipped++; currentProceesedFiles++; Invoke(del); continue; } artist = tags.composer; } else artist = tags.artist; string outfilename = tags.title + " + " + artist + ".wav"; string outfile = outputPath + "\\" + outfilename; string arguments = "-i \"" + f + "\" -ac 1 -ar " + samplingRate + " -ab " + bitRate + " \"" + outfile + "\""; process.StartInfo.Arguments = arguments; process.Start(); process.StandardInput.Write("n"); currentProceesedFiles++; Invoke(del); } } Invoke(finishDel); }