• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

benrr101 / node-taglib-sharp / 51046570

24 Nov 2024 06:12AM UTC coverage: 92.543% (-0.01%) from 92.553%
51046570

push

appveyor

benrr101
Fix MPEG audio stream detection
ALSO UNCOVER A HUGE BUG IN APE FILE INTEGRATION TESTS??? WTF

3246 of 4127 branches covered (78.65%)

Branch coverage included in aggregate %.

35 of 42 new or added lines in 6 files covered. (83.33%)

1 existing line in 1 file now uncovered.

26750 of 28286 relevant lines covered (94.57%)

471.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.52
/src/mpeg/mpegAudioFile.ts
1
import MpegAudioFileSettings from "./mpegAudioFileSettings";
1✔
2
import MpegAudioHeader from "./mpegAudioHeader";
1✔
3
import SandwichFile from "../sandwich/sandwichFile";
1✔
4
import {CorruptFileError} from "../errors";
1✔
5
import {File, ReadStyle} from "../file";
1✔
6
import {IFileAbstraction} from "../fileAbstraction";
7
import {Properties} from "../properties";
1✔
8
import {TagTypes} from "../tag";
1✔
9
import {NumberUtils} from "../utils";
1✔
10

11
/**
12
 * This class extends {@link SandwichFile} to provide tagging and properties support for
13
 * MPEG-1, MPEG-2, and MPEG-2.5 non-containerized audio files.
14
 */
15
export default class MpegAudioFile extends SandwichFile {
1✔
16
    private static readonly DEFAULT_TAG_LOCATION_MAPPING = new Map<TagTypes, () => boolean>([
1✔
17
        [TagTypes.Ape, () => MpegAudioFileSettings.preferApeTagAtFileEnd],
2✔
18
        [TagTypes.Id3v1, () => true],
1✔
19
        [TagTypes.Id3v2, () => MpegAudioFileSettings.preferId3v2TagAtFileEnd]
2✔
20
    ]);
21

22
    private _firstHeader: MpegAudioHeader;
23

24
    public constructor(file: IFileAbstraction|string, propertiesStyle: ReadStyle) {
25
        super(file, propertiesStyle, MpegAudioFile.DEFAULT_TAG_LOCATION_MAPPING, MpegAudioFileSettings.defaultTagTypes);
3✔
26
    }
27

28
    protected readProperties(readStyle: ReadStyle): Properties {
29
        if (!NumberUtils.hasFlag(readStyle, ReadStyle.Average)) {
3!
30
            return undefined;
3✔
31
        }
32

33
        // @TODO: if readStyle is higher than average, scan the entire file to accurately calculate
34
        //    the duration and bitrate
35

NEW
36
        const searchStart = this.mediaStartPosition;
×
NEW
37
        const searchEnd = searchStart + 0x400;
×
NEW
38
        const streamLength = this.mediaEndPosition - this.mediaStartPosition;
×
39

NEW
40
        this._firstHeader = MpegAudioHeader.fromFile(this, searchStart, searchEnd, streamLength);
×
41
        if (!this._firstHeader) {
×
42
            throw new CorruptFileError("MPEG audio header not found");
×
43
        }
44

45
        return new Properties(this._firstHeader.durationMilliseconds, [this._firstHeader]);
×
46
    }
47
}
48

49
// /////////////////////////////////////////////////////////////////////////
50
// Register the file type
51
[
1✔
52
    "taglib/mp3",
53
    "audio/x-mp3",
54
    "application/x-id3",
55
    "audio/mpeg",
56
    "audio/x-mpeg",
57
    "audio/x-mpeg-3",
58
    "audio/mpeg3",
59
    "audio/mp3",
60
    "taglib/m2a",
61
    "taglib/mp2",
62
    "taglib/mp1",
63
    "audio/x-mp2",
64
    "audio/x-mp1"
65
].forEach((mt) => File.addFileType(mt, MpegAudioFile));
13✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc