Completed
Push — master ( d25395...d83c14 )
by Jan
15s queued 14s
created

src/definitions/FrameIdentifiers.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 217
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 199
mnd 0
bc 0
fnc 1
dl 0
loc 217
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A FrameIdentifiers.ts ➔ swapKeyValue 0 4 1
1
const FrameIdentifiersV2 = {
2
    album:                  "TAL",
3
    bpm:                    "TBP",
4
    composer:               "TCM",
5
    genre:                  "TCO",
6
    copyright:              "TCR",
7
    date:                   "TDA",
8
    playlistDelay:          "TDY",
9
    encodedBy:              "TEN",
10
    textWriter:             "TEXT",
11
    fileType:               "TFT",
12
    time:                   "TIM",
13
    contentGroup:           "TT1",
14
    title:                  "TT2",
15
    subtitle:               "TT3",
16
    initialKey:             "TKE",
17
    language:               "TLA",
18
    length:                 "TLE",
19
    mediaType:              "TMT",
20
    originalTitle:          "TOT",
21
    originalFilename:       "TOF",
22
    originalTextwriter:     "TOL",
23
    originalArtist:         "TOA",
24
    originalYear:           "TOR",
25
    artist:                 "TP1",
26
    performerInfo:          "TP2",
27
    conductor:              "TP3",
28
    remixArtist:            "TP4",
29
    partOfSet:              "TPA",
30
    publisher:              "TPB",
31
    trackNumber:            "TRK",
32
    recordingDates:         "TRD",
33
    size:                   "TSI",
34
    ISRC:                   "TRC",
35
    encodingTechnology:     "TSS",
36
    year:                   "TYE",
37
    image:                  "PIC",
38
    commercialUrl:          "WCM",
39
    copyrightUrl:           "WCP",
40
    fileUrl:                "WAF",
41
    artistUrl:              "WAR",
42
    audioSourceUrl:         "WAS",
43
    publisherUrl:           "WPB",
44
    userDefinedUrl:         "WXX"
45
} as const
46
47
const FrameIdentifiersV3 = {
48
    album:                  "TALB",
49
    bpm:                    "TBPM",
50
    composer:               "TCOM",
51
    genre:                  "TCON",
52
    copyright:              "TCOP",
53
    date:                   "TDAT",
54
    playlistDelay:          "TDLY",
55
    encodedBy:              "TENC",
56
    textWriter:             "TEXT",
57
    fileType:               "TFLT",
58
    time:                   "TIME",
59
    contentGroup:           "TIT1",
60
    title:                  "TIT2",
61
    subtitle:               "TIT3",
62
    initialKey:             "TKEY",
63
    language:               "TLAN",
64
    length:                 "TLEN",
65
    mediaType:              "TMED",
66
    originalTitle:          "TOAL",
67
    originalFilename:       "TOFN",
68
    originalTextwriter:     "TOLY",
69
    originalArtist:         "TOPE",
70
    originalYear:           "TORY",
71
    fileOwner:              "TOWN",
72
    artist:                 "TPE1",
73
    performerInfo:          "TPE2",
74
    conductor:              "TPE3",
75
    remixArtist:            "TPE4",
76
    partOfSet:              "TPOS",
77
    publisher:              "TPUB",
78
    trackNumber:            "TRCK",
79
    recordingDates:         "TRDA",
80
    internetRadioName:      "TRSN",
81
    internetRadioOwner:     "TRSO",
82
    size:                   "TSIZ",
83
    ISRC:                   "TSRC",
84
    encodingTechnology:     "TSSE",
85
    year:                   "TYER",
86
    comment:                "COMM",
87
    image:                  "APIC",
88
    unsynchronisedLyrics:   "USLT",
89
    synchronisedLyrics:     "SYLT",
90
    userDefinedText:        "TXXX",
91
    popularimeter:          "POPM",
92
    private:                "PRIV",
93
    chapter:                "CHAP",
94
    tableOfContents:        "CTOC",
95
    userDefinedUrl:         "WXXX",
96
    commercialUrl:          "WCOM",
97
    copyrightUrl:           "WCOP",
98
    fileUrl:                "WOAF",
99
    artistUrl:              "WOAR",
100
    audioSourceUrl:         "WOAS",
101
    radioStationUrl:        "WORS",
102
    paymentUrl:             "WPAY",
103
    publisherUrl:           "WPUB",
104
    eventTimingCodes:       "ETCO",
105
    commercialFrame:        "COMR",
106
    uniqueFileIdentifier:   "UFID"
107
} as const
108
109
/**
110
 * v4 removes some text frames compared to v3: TDAT, TIME, TRDA, TSIZ, TYER
111
 * It adds the text frames: TDEN, TDOR, TDRC, TDRL, TDTG, TIPL, TMCL, TMOO,
112
 * TPRO, TSOA, TSOP, TSOT, TSST
113
 *
114
 * Removed other frames: CHAP, CTOC
115
 */
116
const FrameIdentifiersV4 = {
117
    image:                  "APIC",
118
    comment:                "COMM",
119
    commercialFrame:        "COMR",
120
    eventTimingCodes:       "ETCO",
121
    private:                "PRIV",
122
    popularimeter:          "POPM",
123
    synchronisedLyrics:     "SYLT",
124
    album:                  "TALB",
125
    bpm:                    "TBPM",
126
    composer:               "TCOM",
127
    genre:                  "TCON",
128
    copyright:              "TCOP",
129
    encodingTime:           "TDEN",
130
    playlistDelay:          "TDLY",
131
    originalReleaseTime:    "TDOR",
132
    recordingTime:          "TDRC",
133
    releaseTime:            "TDRL",
134
    taggingTime:            "TDTG",
135
    encodedBy:              "TENC",
136
    textWriter:             "TEXT",
137
    fileType:               "TFLT",
138
    involvedPeopleList:     "TIPL",
139
    contentGroup:           "TIT1",
140
    title:                  "TIT2",
141
    subtitle:               "TIT3",
142
    initialKey:             "TKEY",
143
    language:               "TLAN",
144
    length:                 "TLEN",
145
    musicianCreditsList:    "TMCL",
146
    mediaType:              "TMED",
147
    mood:                   "TMOO",
148
    originalTitle:          "TOAL",
149
    originalFilename:       "TOFN",
150
    originalTextwriter:     "TOLY",
151
    originalArtist:         "TOPE",
152
    fileOwner:              "TOWN",
153
    artist:                 "TPE1",
154
    performerInfo:          "TPE2",
155
    conductor:              "TPE3",
156
    remixArtist:            "TPE4",
157
    partOfSet:              "TPOS",
158
    producedNotice:         "TPRO",
159
    publisher:              "TPUB",
160
    trackNumber:            "TRCK",
161
    internetRadioName:      "TRSN",
162
    internetRadioOwner:     "TRSO",
163
    albumSortOrder:         "TSOA",
164
    performerSortOrder:     "TSOP",
165
    titleSortOrder:         "TSOT",
166
    ISRC:                   "TSRC",
167
    encodingTechnology:     "TSSE",
168
    setSubtitle:            "TSST",
169
    userDefinedText:        "TXXX",
170
    unsynchronisedLyrics:   "USLT",
171
    commercialUrl:          "WCOM",
172
    copyrightUrl:           "WCOP",
173
    fileUrl:                "WOAF",
174
    artistUrl:              "WOAR",
175
    audioSourceUrl:         "WOAS",
176
    radioStationUrl:        "WORS",
177
    paymentUrl:             "WPAY",
178
    publisherUrl:           "WPUB",
179
    userDefinedUrl:         "WXXX"
180
} as const
181
182
/**
183
 * Alias to identifier
184
 */
185
export const FRAME_IDENTIFIERS = {
186
    v2: FrameIdentifiersV2,
187
    v3: FrameIdentifiersV3,
188
    v4: FrameIdentifiersV4,
189
    v34: {
190
        ...FrameIdentifiersV3,
191
        ...FrameIdentifiersV4
192
    }
193
} as const
194
195
/**
196
 * Identifier to Alias
197
 */
198
export const FRAME_ALIASES = {
199
    v2: swapKeyValue(FrameIdentifiersV2),
200
    v3: swapKeyValue(FrameIdentifiersV3),
201
    v4: swapKeyValue(FrameIdentifiersV4),
202
    v34: {
203
        ...swapKeyValue(FrameIdentifiersV3),
204
        ...swapKeyValue(FrameIdentifiersV4)
205
    }
206
} as const
207
208
function swapKeyValue<
209
    T extends Record<string, string>,
210
    R = { [K in keyof T as T[K]]: K }
211
>(object: T): R {
212
    return Object.entries(object).reduce<Record<string, string>>(
213
        (result, [key, value])  => (result[value] = key, result),
214
        {}
215
    ) as unknown as R
216
}
217