mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
improve music release
This commit is contained in:
parent
e0ae3ca064
commit
31fe2c1e71
@ -12,6 +12,23 @@ const AllowedUpdateFields = [
|
|||||||
|
|
||||||
export default class Release {
|
export default class Release {
|
||||||
static async create(payload) {
|
static async create(payload) {
|
||||||
|
if (!payload.title) {
|
||||||
|
throw new OperationError(400, "Release title is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!payload.list) {
|
||||||
|
throw new OperationError(400, "Release list is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure list is an array of strings with tracks ids only
|
||||||
|
playload.list = playload.list.map((item) => {
|
||||||
|
if (typeof item !== "string") {
|
||||||
|
item = item._id
|
||||||
|
}
|
||||||
|
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
|
||||||
const release = new MusicRelease({
|
const release = new MusicRelease({
|
||||||
user_id: payload.user_id,
|
user_id: payload.user_id,
|
||||||
created_at: Date.now(),
|
created_at: Date.now(),
|
||||||
@ -48,13 +65,21 @@ export default class Release {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure list is an array of strings with tracks ids only
|
||||||
|
release.list = release.list.map((item) => {
|
||||||
|
if (typeof item !== "string") {
|
||||||
|
item = item._id
|
||||||
|
}
|
||||||
|
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
|
||||||
release = await MusicRelease.findByIdAndUpdate(id, release)
|
release = await MusicRelease.findByIdAndUpdate(id, release)
|
||||||
|
|
||||||
return release
|
return release
|
||||||
}
|
}
|
||||||
|
|
||||||
static async fullfillItemData(release) {
|
static async fullfillItemData(release) {
|
||||||
|
|
||||||
return release
|
return release
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,6 +15,8 @@ export default async (payload = {}) => {
|
|||||||
return await ModifyTrack(payload._id, payload)
|
return await ModifyTrack(payload._id, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let metadata = Object()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const sourceStream = await axios({
|
const sourceStream = await axios({
|
||||||
url: payload.source,
|
url: payload.source,
|
||||||
@ -24,25 +26,26 @@ export default async (payload = {}) => {
|
|||||||
|
|
||||||
stream = sourceStream.data
|
stream = sourceStream.data
|
||||||
headers = sourceStream.headers
|
headers = sourceStream.headers
|
||||||
} catch (error) {
|
|
||||||
throw new OperationError(500, `Failed to process fetching source: ${error.message}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const fileMetadata = await MusicMetadata.parseStream(stream, {
|
const streamMetadata = await MusicMetadata.parseStream(stream, {
|
||||||
mimeType: headers["content-type"],
|
mimeType: headers["content-type"],
|
||||||
})
|
})
|
||||||
|
|
||||||
let metadata = {
|
metadata = {
|
||||||
format: fileMetadata.format.codec,
|
...metadata,
|
||||||
channels: fileMetadata.format.numberOfChannels,
|
format: streamMetadata.format.codec,
|
||||||
sampleRate: fileMetadata.format.sampleRate,
|
channels: streamMetadata.format.numberOfChannels,
|
||||||
bits: fileMetadata.format.bitsPerSample,
|
sampleRate: streamMetadata.format.sampleRate,
|
||||||
lossless: fileMetadata.format.lossless,
|
bits: streamMetadata.format.bitsPerSample,
|
||||||
duration: fileMetadata.format.duration,
|
lossless: streamMetadata.format.lossless,
|
||||||
|
duration: streamMetadata.format.duration,
|
||||||
|
|
||||||
title: fileMetadata.common.title,
|
title: streamMetadata.common.title,
|
||||||
artists: fileMetadata.common.artists,
|
artists: streamMetadata.common.artists,
|
||||||
album: fileMetadata.common.album,
|
album: streamMetadata.common.album,
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// sowy :(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof payload.metadata === "object") {
|
if (typeof payload.metadata === "object") {
|
||||||
@ -52,6 +55,16 @@ export default async (payload = {}) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metadata.format = metadata.format.toUpperCase()
|
||||||
|
|
||||||
|
if (
|
||||||
|
metadata.format === "FLAC" ||
|
||||||
|
metadata.format === "WAV" ||
|
||||||
|
metadata.format === "ALAC"
|
||||||
|
) {
|
||||||
|
metadata.lossless = true
|
||||||
|
}
|
||||||
|
|
||||||
const obj = {
|
const obj = {
|
||||||
title: payload.title,
|
title: payload.title,
|
||||||
album: payload.album,
|
album: payload.album,
|
||||||
@ -70,6 +83,10 @@ export default async (payload = {}) => {
|
|||||||
obj.artists.push(payload.artists)
|
obj.artists.push(payload.artists)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof payload.artist === "string") {
|
||||||
|
obj.artists.push(payload.artist)
|
||||||
|
}
|
||||||
|
|
||||||
if (obj.artists.length === 0 || !obj.artists) {
|
if (obj.artists.length === 0 || !obj.artists) {
|
||||||
obj.artists = metadata.artists
|
obj.artists = metadata.artists
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user