private IEnumerable <string> GroupByIdentical(string[] audioPaths) { List <List <string> > dupes = new List <List <string> >(); foreach (string audioPath in audioPaths) { bool set = false; foreach (var dupe in dupes) { string oldePath = dupe[0]; if (LocalCommon.AudioIdenticalLocal(oldePath, audioPath)) { dupe.Add(audioPath); set = true; break; } } if (!set) { dupes.Add(new List <string> { audioPath }); } } int groupId = 0; foreach (var dupe in dupes) { if (dupe.Count == 1) { continue; } foreach (string s in dupe) { yield return($"{groupId}\t{s}"); } groupId++; } }
protected override void ItemTransfer(string inputPath, string outputPath) { string intermediaPath = Path.Combine(WorkFolder, Guid.NewGuid() + ".wav"); try { if (ExistingFileDict.ContainsKey(outputPath)) { Console.WriteLine($"File exists: {outputPath}"); return; } string ext = inputPath.Split('.').Last().ToLower(); if (ext.ToLower() == "ds_store" || ext.ToLower() == "pdf") { return; } Sanity.Requires(ValidExtSet.Contains(ext), $"Invalid extension: {ext}"); ConvertToWave(inputPath, intermediaPath, outputPath); Wave w = new Wave(); w.ShallowParse(outputPath); string reportLine = $"{inputPath.Split('\\').Last()}\t{outputPath.Split('\\').Last()}\t{w.AudioLength}"; string key = w.DataChunk.Length.ToString(); lock (LockObj) { if (FileSizeDict.ContainsKey(key)) { foreach (string existingFilePath in FileSizeDict[key]) { if (LocalCommon.AudioIdenticalLocal(existingFilePath, outputPath)) { ErrorList.Add($"{outputPath}\t{existingFilePath}"); if (File.Exists(outputPath)) { File.Delete(outputPath); } return; } } FileSizeDict[key].Add(outputPath); } else { FileSizeDict[key] = new List <string> { outputPath } }; try { string outputTimeStampPath = outputPath.Replace(".wav", ".txt"); if (File.Exists(outputTimeStampPath)) { File.Delete(outputTimeStampPath); } SetTimeStamp(outputPath, outputTimeStampPath); CheckTimeStamp(outputTimeStampPath); Sanity.Requires(File.Exists(outputTimeStampPath)); string outputTextGridPath = outputPath.Replace(".wav", ".textgrid"); if (File.Exists(outputTextGridPath)) { File.Delete(outputTextGridPath); } TextGrid.TimeStampToTextGrid(outputTimeStampPath, outputTextGridPath); } catch { ErrorList.Add($"{outputPath}\tNo time stamp file."); } ReportList.Add(reportLine); NewFileList.Add($"{key}\t{outputPath}"); if (File.Exists(intermediaPath)) { File.Delete(intermediaPath); } } } catch (CommonException e) { string errorMessage = $"{inputPath}\t{e.Message}"; ErrorList.Add(errorMessage); Logger.WriteLineWithLock(errorMessage); if (File.Exists(intermediaPath)) { File.Delete(intermediaPath); } if (File.Exists(outputPath)) { File.Delete(outputPath); } } }