-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
372 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.commonFieldsPlugin = void 0; | ||
/** 记录第一个 metadata 的公共字段, 后续可省略 */ | ||
const commonFieldsPlugin = () => { | ||
let firstMetadata; | ||
return ({ metadata, index }) => { | ||
if (index === 0) { | ||
firstMetadata = metadata; | ||
} | ||
if (index > 0) { | ||
const albumDataFields = [ | ||
'album', | ||
'albumOrder', | ||
'albumArtists', | ||
'genres', | ||
'year', | ||
'coverImage', | ||
]; | ||
albumDataFields.forEach(field => { | ||
if (!metadata[field]) { | ||
metadata[field] = firstMetadata[field]; | ||
} | ||
}); | ||
} | ||
}; | ||
}; | ||
exports.commonFieldsPlugin = commonFieldsPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetchCoverPlugin = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
/** 处理封面图片 */ | ||
const fetchCoverPlugin = ({ cover, config }) => { | ||
let firstCoverBuffer = undefined; | ||
const downloadRemoteCover = async (url) => { | ||
return axios_1.default.get(url, { | ||
responseType: 'arraybuffer', | ||
timeout: config.timeout * 1000, | ||
}); | ||
}; | ||
return async ({ metadata, index }) => { | ||
if (index === 0) { | ||
if (cover !== undefined) { | ||
firstCoverBuffer = cover; | ||
} | ||
else if (typeof metadata.coverImage === 'string') { | ||
const response = await downloadRemoteCover(metadata.coverImage); | ||
firstCoverBuffer = response.data; | ||
} | ||
metadata.coverImage = firstCoverBuffer; | ||
} | ||
if (index > 0) { | ||
if (metadata.coverImage === undefined && firstCoverBuffer !== undefined) { | ||
metadata.coverImage = firstCoverBuffer; | ||
} | ||
else if (typeof metadata.coverImage === 'string') { | ||
const response = await downloadRemoteCover(metadata.coverImage); | ||
metadata.coverImage = response.data; | ||
} | ||
} | ||
}; | ||
}; | ||
exports.fetchCoverPlugin = fetchCoverPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.inferNumberPlugin = void 0; | ||
/** 自动推测 trackNumber 和 discNumber */ | ||
const inferNumberPlugin = () => { | ||
let cachedTrackNumber = 1; | ||
let cachedDiscNumber = 1; | ||
return ({ metadata }) => { | ||
if (metadata.discNumber && parseInt(metadata.discNumber) !== cachedDiscNumber) { | ||
cachedDiscNumber = parseInt(metadata.discNumber); | ||
cachedTrackNumber = 1; | ||
} | ||
if (!metadata.discNumber) { | ||
metadata.discNumber = cachedDiscNumber.toString(); | ||
} | ||
if (!metadata.trackNumber) { | ||
metadata.trackNumber = cachedTrackNumber.toString(); | ||
} | ||
cachedTrackNumber++; | ||
}; | ||
}; | ||
exports.inferNumberPlugin = inferNumberPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.omitArtistsPlugin = void 0; | ||
/** 省略 artists 且带有 composers 时, 使用 composers 填充 artists */ | ||
const omitArtistsPlugin = () => { | ||
return ({ metadata }) => { | ||
if (!metadata.artists && metadata.composers) { | ||
metadata.artists = metadata.composers; | ||
} | ||
}; | ||
}; | ||
exports.omitArtistsPlugin = omitArtistsPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Metadata } from '../metadata' | ||
import { LocalJsonPlugin } from './local-json' | ||
|
||
/** 记录第一个 metadata 的公共字段, 后续可省略 */ | ||
export const commonFieldsPlugin: LocalJsonPlugin = () => { | ||
let firstMetadata: Metadata | ||
return ({ metadata, index }) => { | ||
if (index === 0) { | ||
firstMetadata = metadata | ||
} | ||
if (index > 0) { | ||
const albumDataFields = [ | ||
'album', | ||
'albumOrder', | ||
'albumArtists', | ||
'genres', | ||
'year', | ||
'coverImage', | ||
] | ||
albumDataFields.forEach(field => { | ||
if (!metadata[field]) { | ||
metadata[field] = firstMetadata[field] | ||
} | ||
}) | ||
} | ||
} | ||
} |
Oops, something went wrong.