Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add, change and fix some mappings #544

Merged
merged 8 commits into from Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ doc-gen/**/*.map
doc-gen/**/*.map
coverage/
.nyc_output/
test/samples/zeroes.flac
27 changes: 27 additions & 0 deletions doc-gen/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@
"totaldiscs": {
"description": "The total number of discs"
},
"movementTotal": {
"description": "The total number of movements"
},
"compilation": {
"description": "Is part of compilation (unofficial iTunes Compilation Flag)"
},
Expand Down Expand Up @@ -298,5 +301,29 @@
},
"technician": {
"description": "Technician who digitized subject"
},
"category": {
"description": "Podcast Category"
},
"hdVideo": {
"description": "iTunes Video Quality (2=Full HD, 1=HD, 0=SD)"
},
"keywords": {
"description": "Podcast Keywords"
},
"movement": {
"description": "Movement"
},
"movementIndex": {
"description": "Movement Index/Total, e.g. `{no: 1, of: 4}`"
},
"podcastId": {
"description": "Podcast Identifier"
},
"showMovement": {
"description": "Show Movement"
},
"stik": {
"description": "iTunes Media Type (1=Normal, 2=Audiobook, 6=Music Video, 9=Movie, 10=TV Show, 11=Booklet, 14=Ringtone, https://github.com/sergiomb2/libmp4v2/wiki/iTunesMetadata#user-content-media-type-stik)"
}
}
213 changes: 111 additions & 102 deletions doc/common_metadata.md

Large diffs are not rendered by default.

27 changes: 23 additions & 4 deletions lib/common/GenericTagTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,16 @@ export type GenericTagId =
| 'replaygain_track_minmax'
| 'replaygain_album_minmax'
| 'replaygain_undo'
| 'description';
| 'description'
| 'category'
| 'hdVideo'
| 'keywords'
| 'movement'
| 'movementIndex'
| 'movementTotal'
| 'podcastId'
| 'showMovement'
| 'stik';

export interface INativeTagMap {
[index: string]: GenericTagId;
Expand Down Expand Up @@ -149,7 +158,7 @@ export const commonTags: ITagInfoMap = {
work: {multiple: false, unique: true},
artistsort: {multiple: false, unique: true},
albumartistsort: {multiple: false, unique: true},
composersort: {multiple: true, unique: true},
composersort: {multiple: false, unique: true},
lyricist: {multiple: true, unique: true},
writer: {multiple: true, unique: true},
conductor: {multiple: true, unique: true},
Expand All @@ -162,7 +171,7 @@ export const commonTags: ITagInfoMap = {
mixer: {multiple: true, unique: true},
label: {multiple: true, unique: true},
grouping: {multiple: false},
subtitle: {multiple: false},
subtitle: {multiple: true},
discsubtitle: {multiple: false},
totaltracks: {multiple: false},
totaldiscs: {multiple: false},
Expand Down Expand Up @@ -231,7 +240,17 @@ export const commonTags: ITagInfoMap = {
replaygain_album_minmax: {multiple: false},
replaygain_undo: {multiple: false},

description: {multiple: true}
description: {multiple: true},

category: {multiple: true},
hdVideo: {multiple: false},
keywords: {multiple: true},
movement: {multiple: false},
movementIndex: {multiple: false},
movementTotal: {multiple: false},
podcastId: {multiple: false},
showMovement: {multiple: false},
stik: {multiple: false}
};

/**
Expand Down
13 changes: 11 additions & 2 deletions lib/common/MetadataCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export class MetadataCollector implements INativeMetadataCollector {

public readonly common: ICommonTagsResult = {
track: {no: null, of: null},
disk: {no: null, of: null}
disk: {no: null, of: null},
movementIndex: {}
};

public readonly quality: IQualityInformation = {
Expand Down Expand Up @@ -190,8 +191,13 @@ export class MetadataCollector implements INativeMetadataCollector {
this.common.disk.of = CommonTagMapper.toIntOrNull(tag.value);
return;

case 'movementTotal':
this.common.movementIndex.of = CommonTagMapper.toIntOrNull(tag.value);
return;

case 'track':
case 'disk':
case 'movementIndex':
const of = this.common[tag.id].of; // store of value, maybe maybe overwritten
this.common[tag.id] = CommonTagMapper.normalizeTrack(tag.value);
this.common[tag.id].of = of != null ? of : this.common[tag.id].of;
Expand Down Expand Up @@ -238,7 +244,10 @@ export class MetadataCollector implements INativeMetadataCollector {
break;

case 'gapless': // iTunes gap-less flag
tag.value = tag.value === '1'; // boolean
case 'compilation':
case 'podcast':
case 'showMovement':
tag.value = tag.value === '1' || tag.value === 1; // boolean
break;

case 'isrc': // Only keep unique values
Expand Down
15 changes: 15 additions & 0 deletions lib/id3v2/FrameParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export class FrameParser {
switch (type !== 'TXXX' && type[0] === 'T' ? 'T*' : type) {
case 'T*': // 4.2.1. Text information frames - details
case 'IPLS': // v2.3: Involved people list
case 'MVIN':
case 'MVNM':
case 'PCS':
case 'PCST':
const text = common.decodeString(b.slice(1), encoding).replace(/\x00+$/, '');
switch (type) {
case 'TMCL': // Musician credits list
Expand All @@ -72,6 +76,12 @@ export class FrameParser {
// id3v2.3 defines that TCOM, TEXT, TOLY, TOPE & TPE1 values are separated by /
output = this.splitValue(type, text);
break;
case 'PCS':
case 'PCST':
// TODO: Why `default` not results `1` but `''`?
output = this.major >= 4 ? this.splitValue(type, text) : [text];
output = (Array.isArray(output) && output[0] === '') ? 1 : 0;
break;
default:
output = this.major >= 4 ? this.splitValue(type, text) : [text];
}
Expand Down Expand Up @@ -224,6 +234,11 @@ export class FrameParser {
break;
}

case 'WFD':
case 'WFED':
output = common.decodeString(b.slice(offset + 1, common.findZero(b, offset + 1, length, encoding)), encoding);
break;

case 'MCDI': {
// Music CD identifier
output = b.slice(0, length);
Expand Down
18 changes: 14 additions & 4 deletions lib/id3v2/ID3v22TagMapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {INativeTagMap} from '../common/GenericTagTypes';
import {CommonTagMapper} from '../common/GenericTagMapper';
import {CaseInsensitiveTagMap} from '../common/CaseInsensitiveTagMap';

/**
* ID3v2.2 tag mappings
Expand All @@ -18,7 +18,7 @@ export const id3v22TagMap: INativeTagMap = {
TCM: 'composer',

TOR: 'originaldate',
TOT: 'work',
TOT: 'originalalbum',
TXT: 'lyricist',
TP3: 'conductor',
TPB: 'label',
Expand All @@ -35,10 +35,20 @@ export const id3v22TagMap: INativeTagMap = {
'COM:iTunNORM': ,
'COM:iTunSMPB': 'encoder delay',
'COM:iTunes_CDDB_IDs'
*/
*/,

PCS: 'podcast',
TCP: "compilation",
TDR: 'date',
TS2: 'albumartistsort',
TSA: 'albumsort',
TSC: 'composersort',
TSP: 'artistsort',
TST: 'titlesort',
WFD: 'podcasturl'
};

export class ID3v22TagMapper extends CommonTagMapper {
export class ID3v22TagMapper extends CaseInsensitiveTagMap {

public constructor() {
super(['ID3v2.2'], id3v22TagMap);
Expand Down
12 changes: 11 additions & 1 deletion lib/id3v2/ID3v24TagMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,17 @@ const id3v24TagMap: INativeTagMap = {
"TXXX:REPLAYGAIN_ALBUM_GAIN": "replaygain_album_gain",
"TXXX:MP3GAIN_MINMAX": "replaygain_track_minmax",
"TXXX:MP3GAIN_ALBUM_MINMAX": "replaygain_album_minmax",
"TXXX:MP3GAIN_UNDO": "replaygain_undo"
"TXXX:MP3GAIN_UNDO": "replaygain_undo",

MVNM: "movement",
MVIN: "movementIndex",
PCST: "podcast",
TCAT: "category",
TDES: "description",
TDRL: "date",
TGID: "podcastId",
TKWD: "keywords",
WFED: "podcasturl"
};

export class ID3v24TagMapper extends CaseInsensitiveTagMap {
Expand Down
20 changes: 16 additions & 4 deletions lib/mp4/MP4TagMapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {INativeTagMap} from '../common/GenericTagTypes';
import {CommonTagMapper} from '../common/GenericTagMapper';
import {CaseInsensitiveTagMap} from '../common/CaseInsensitiveTagMap';

/**
* Ref: https://github.com/sergiomb2/libmp4v2/wiki/iTunesMetadata
Expand All @@ -15,6 +15,7 @@ const mp4TagMap: INativeTagMap = {
'©alb': 'album',
'©day': 'date',
'©cmt': 'comment',
'©com': 'comment',
trkn: 'track',
disk: 'disk',
'©gen': 'genre',
Expand Down Expand Up @@ -56,6 +57,7 @@ const mp4TagMap: INativeTagMap = {
'----:com.apple.iTunes:SCRIPT': 'script',
'----:com.apple.iTunes:LANGUAGE': 'language',
cprt: 'copyright',
'©cpy': 'copyright',
'----:com.apple.iTunes:LICENSE': 'license',
'©too': 'encodedby',
pgap: 'gapless',
Expand Down Expand Up @@ -91,13 +93,23 @@ const mp4TagMap: INativeTagMap = {
'----:com.apple.iTunes:ORIGINALDATE': 'originaldate',
'----:com.apple.iTunes:ORIGINALYEAR': 'originalyear',
// '----:com.apple.iTunes:PERFORMER': 'performer'
desc: 'description',
ldes: 'description'
desc: 'subtitle',
ldes: 'description',
'©mvn': 'movement',
'©mvi': 'movementIndex',
'©mvc': 'movementTotal',
'©wrk': 'work',
catg: 'category',
egid: 'podcastId',
hdvd: 'hdVideo',
keyw: 'keywords',
shwm: 'showMovement',
stik: 'stik'
};

export const tagType = 'iTunes';

export class MP4TagMapper extends CommonTagMapper {
export class MP4TagMapper extends CaseInsensitiveTagMap {

public constructor() {
super([tagType], mp4TagMap);
Expand Down
57 changes: 53 additions & 4 deletions lib/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ export interface ICommonTagsResult {
*/
albumartistsort?: string;
/**
* Composer(s), formatted for alphabetic ordering
* Composer, formatted for alphabetic ordering
*/
composersort?: string[];
composersort?: string;
/**
* Lyricist(s)
*/
Expand Down Expand Up @@ -164,10 +164,12 @@ export interface ICommonTagsResult {
label?: string[];
grouping?: string[];
subtitle?: string[];
description?: string[];
discsubtitle?: string[];
totaltracks?: string;
totaldiscs?: string;
compilation?: string;
movementTotal?: number;
compilation?: boolean;
rating?: IRating[];
bpm?: number;
/**
Expand Down Expand Up @@ -206,7 +208,7 @@ export interface ICommonTagsResult {
* TV network
*/
tvNetwork?: string,
podcast?: string;
podcast?: boolean;
podcasturl?: string;
releasestatus?: string;
releasetype?: string[];
Expand Down Expand Up @@ -297,6 +299,53 @@ export interface ICommonTagsResult {
* Ref: https://docs.microsoft.com/en-us/windows/win32/wmformat/wm-initialkey
*/
key?: string;

/**
* Podcast Category
*/
category?: string[];
/**
* iTunes Video Quality
*
* 2: Full HD
* 1: HD
* 0: SD
*/
hdVideo?: number;
/**
* Podcast Keywords
*/
keywords?: string[];
/**
* Movement
*/
movement?: string;
/**
* Movement Index/Total
*/
movementIndex: { no?: number, of?: number };
/**
* Podcast Identifier
*/
podcastId?: string;
/**
* Show Movement
*/
showMovement?: boolean;
/**
* iTunes Media Type
*
* 1: Normal
* 2: Audiobook
* 6: Music Video
* 9: Movie
* 10: TV Show
* 11: Booklet
* 14: Ringtone
*
* https://github.com/sergiomb2/libmp4v2/wiki/iTunesMetadata#user-content-media-type-stik
*/
stik?: number;
}

export interface IRatio {
Expand Down
Binary file added test/samples/mp3/pr-544-id3v24.mp3
Binary file not shown.
Binary file added test/samples/mp4/pr-544.m4a
Binary file not shown.
Loading