예제 #1
0
        public void Test_Mp3_1()
        {
            var fn = @"Targets\Singles\01-Phantom.mp3";

            using (var fs = new FileStream(fn, FileMode.Open))
            {
                var hdr = new byte[0x2C];
                fs.Read(hdr, 0, hdr.Length);

                Mp3Format.Model mp3Model = Mp3Format.CreateModel(fs, hdr, fn);
                Mp3Format       mp3      = mp3Model.Data;

                Assert.IsNotNull(mp3);
                Assert.AreEqual(Severity.Warning, mp3.Issues.MaxSeverity);
                Assert.AreEqual(2, mp3.Issues.Items.Count);
                Assert.IsTrue(mp3.HasId3v1Phantom);

                var repairMessage = mp3Model.RepairPhantomTag(true);
                Assert.IsNull(repairMessage);

                mp3Model.CalcHashes(Hashes.Intrinsic, Validations.None);
                Assert.IsFalse(mp3.IsBadHeader);
                Assert.IsFalse(mp3.IsBadData);
            }
        }
예제 #2
0
        public void UnitMp3_BadCRC()
        {
            var fName1 = @"Targets\Singles\02-WalkedOn.mp3";

            using (Stream fs = new FileStream(fName1, FileMode.Open))
            {
                var hdr = new byte[0x2C];
                fs.Read(hdr, 0, hdr.Length);

                Mp3Format.Model mp3Model = Mp3Format.CreateModel(fs, hdr, fName1);

                mp3Model.CalcHashes(Hashes.Intrinsic, Validations.None);
                Assert.IsTrue(mp3Model.Data.IsBadData);
                Assert.AreEqual(Severity.Error, mp3Model.Data.Issues.MaxSeverity);
            }
        }
예제 #3
0
            private void ValidateMp3s(Hashes fileHash)
            {
                Bind.mp3Models = new List <Mp3Format.Model>();
                int id3v1Count = 0, id3v23Count = 0, id3v24Count = 0;

                foreach (FileInfo mp3Info in Bind.mp3Infos)
                {
                    Owner.SetCurrentFile(mp3Info.Name, Granularity.Verbose);
                    using (var ffs = new FileStream(mp3Info.FullName, FileMode.Open, FileAccess.Read))
                    {
                        var             buf      = new byte[0x2C];
                        int             got      = ffs.Read(buf, 0, buf.Length);
                        Mp3Format.Model mp3Model = Mp3Format.CreateModel(ffs, buf, mp3Info.FullName);
                        if (mp3Model == null)
                        {
                            Bind.MaxTrackSeverity = Severity.Error;
                            Owner.ReportLine("Doesn't seem to be a MP3.", Severity.Error, Bind.Signature != null);
                        }
                        else
                        {
                            Mp3Format mp3 = mp3Model.Data;
                            mp3Model.CalcHashes(Hashes.Intrinsic | Owner.Data.HashFlags | fileHash, Owner.Data.ValidationFlags);
                            if (mp3.IsBadHeader)
                            {
                                ++Owner.Data.Mp3Format.TotalHeaderErrors;
                            }
                            if (mp3.IsBadData)
                            {
                                ++Owner.Data.Mp3Format.TotalDataErrors;
                            }

                            if (mp3.Lame != null)
                            {
                                if (Bind.RipProfile == null)
                                {
                                    Bind.RipProfile = mp3.Lame.Profile;
                                }
                                else if (Bind.RipProfile != mp3.Lame.Profile)
                                {
                                    mp3Model.IssueModel.Add($"Profile {mp3.Lame.Profile} inconsistent with rip profile of {Bind.RipProfile}.");
                                }
                            }

                            if (mp3.HasId3v1)
                            {
                                ++id3v1Count;
                            }
                            if (mp3.HasId3v2)
                            {
                                if (mp3.Id3v2Major == 3)
                                {
                                    ++id3v23Count;
                                }
                                else if (mp3.Id3v2Major == 4)
                                {
                                    ++id3v24Count;
                                }
                            }

                            IssueTags tags = Owner.Data.IsFussy? IssueTags.Fussy : IssueTags.None;
                            mp3Model.IssueModel.Escalate(IssueTags.HasApe, tags | IssueTags.Substandard | IssueTags.Overstandard);

                            if (Bind.MaxTrackSeverity < mp3.Issues.MaxSeverity)
                            {
                                Bind.MaxTrackSeverity = mp3.Issues.MaxSeverity;
                            }

                            Bind.mp3Models.Add(mp3Model);
                            Owner.ReportFormat(mp3, Bind.Signature != null);
                        }

                        ++Owner.Data.Mp3Format.TrueTotal;
                        ++Owner.Data.TotalFiles;

                        if (mp3Model != null)
                        {
                            mp3Model.ClearFile();
                        }
                        if (Bind.MaxTrackSeverity >= Severity.Fatal)
                        {
                            return;
                        }
                    }
                }

                if (new string[] { "V2", "V0", "C320" }.Any(x => x == Bind.RipProfile))
                {
                    LogModel.IssueModel.Add($"All tracks profile {Bind.RipProfile}.", Severity.Noise);
                }
                else
                {
                    LogModel.IssueModel.Add($"Profile {Bind.RipProfile} is substandard.", Severity.Error, IssueTags.Substandard);
                }

                if (id3v1Count > 0 && id3v1Count != Bind.mp3Infos.Length)
                {
                    LogModel.IssueModel.Add("Tracks have incomplete ID3v1 tagging.");
                }

                if (id3v23Count > 0 && id3v24Count > 0)
                {
                    LogModel.IssueModel.Add("Tracks inconsistently tagged both ID3v2.3 and ID3v2.4.");
                }
            }