Add track cover extraction and upload support

This commit is contained in:
SrGooglo 2025-04-24 07:44:50 +00:00
parent 8b76dfc364
commit 87f750cc8b
2 changed files with 27 additions and 35 deletions

View File

@ -176,8 +176,7 @@ class TracksManager extends React.Component {
const trackManifest = new TrackManifest({
uid: uid,
file: change.file,
onChange: this.modifyTrackByUid,
file: change.file.originFileObj,
})
this.addTrackToList(trackManifest)
@ -205,6 +204,23 @@ class TracksManager extends React.Component {
trackManifest.source = change.file.response.url
trackManifest = await trackManifest.initialize()
// if has a cover, Upload
if (trackManifest._coverBlob) {
console.log(
`[${trackManifest.uid}] Founded cover, uploading...`,
)
const coverFile = new File(
[trackManifest._coverBlob],
"cover.jpg",
{ type: trackManifest._coverBlob.type },
)
const coverUpload =
await app.cores.remoteStorage.uploadFile(coverFile)
trackManifest.cover = coverUpload.url
}
await this.modifyTrackByUid(uid, trackManifest)
break

View File

@ -51,33 +51,28 @@ export default class TrackManifest {
_id = null // used for api requests
uid = null // used for internal
cover =
"https://storage.ragestudio.net/comty-static-assets/default_song.png"
title = "Untitled"
album = "Unknown"
artist = "Unknown"
cover = null // set default cover url
source = null
metadata = {}
// set default service to default
service = "default"
// Extended from db
liked = null
async initialize() {
if (!this.params.file) {
return this
}
const analyzedMetadata = await parseBlob(
this.params.file.originFileObj,
{
skipPostHeaders: true,
},
).catch(() => ({}))
const analyzedMetadata = await parseBlob(this.params.file, {
skipPostHeaders: true,
}).catch(() => ({}))
this.metadata.format = analyzedMetadata.format.codec
if (analyzedMetadata.format) {
this.metadata.format = analyzedMetadata.format.codec
}
if (analyzedMetadata.common) {
this.title = analyzedMetadata.common.title ?? this.title
@ -88,32 +83,13 @@ export default class TrackManifest {
if (analyzedMetadata.common.picture) {
const cover = analyzedMetadata.common.picture[0]
const coverFile = new File([cover.data], "cover", {
type: cover.format,
})
const coverUpload =
await app.cores.remoteStorage.uploadFile(coverFile)
this.cover = coverUpload.url
this._coverBlob = new Blob([cover.data], { type: cover.format })
this.cover = URL.createObjectURL(this._coverBlob)
}
this.handleChanges({
cover: this.cover,
title: this.title,
artist: this.artist,
album: this.album,
})
return this
}
handleChanges = (changes) => {
if (typeof this.params.onChange === "function") {
this.params.onChange(this.uid, changes)
}
}
analyzeCoverColor = async () => {
const fac = new FastAverageColor()