mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 19:14:16 +00:00
improve overrides
This commit is contained in:
parent
3b04ef6044
commit
dde659ef01
@ -32,24 +32,23 @@ export default class TrackInstance {
|
|||||||
waitUpdateTimeout = null
|
waitUpdateTimeout = null
|
||||||
|
|
||||||
mediaEvents = {
|
mediaEvents = {
|
||||||
"ended": () => {
|
ended: () => {
|
||||||
this.player.next()
|
this.player.next()
|
||||||
},
|
},
|
||||||
"loadeddata": () => {
|
loadeddata: () => {
|
||||||
this.player.state.loading = false
|
this.player.state.loading = false
|
||||||
},
|
},
|
||||||
"loadedmetadata": () => {
|
loadedmetadata: () => {
|
||||||
// TODO: Detect a livestream and change mode
|
// TODO: Detect a livestream and change mode
|
||||||
// if (instance.media.duration === Infinity) {
|
// if (instance.media.duration === Infinity) {
|
||||||
// instance.manifest.stream = true
|
// instance.manifest.stream = true
|
||||||
|
|
||||||
// this.state.livestream_mode = true
|
// this.state.livestream_mode = true
|
||||||
// }
|
// }
|
||||||
},
|
},
|
||||||
"play": () => {
|
play: () => {
|
||||||
this.player.state.playback_status = "playing"
|
this.player.state.playback_status = "playing"
|
||||||
},
|
},
|
||||||
"playing": () => {
|
playing: () => {
|
||||||
this.player.state.loading = false
|
this.player.state.loading = false
|
||||||
|
|
||||||
this.player.state.playback_status = "playing"
|
this.player.state.playback_status = "playing"
|
||||||
@ -59,13 +58,16 @@ export default class TrackInstance {
|
|||||||
this.waitUpdateTimeout = null
|
this.waitUpdateTimeout = null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pause": () => {
|
pause: () => {
|
||||||
this.player.state.playback_status = "paused"
|
this.player.state.playback_status = "paused"
|
||||||
},
|
},
|
||||||
"durationchange": () => {
|
durationchange: () => {
|
||||||
this.player.eventBus.emit(`player.durationchange`, this.audio.duration)
|
this.player.eventBus.emit(
|
||||||
|
`player.durationchange`,
|
||||||
|
this.audio.duration,
|
||||||
|
)
|
||||||
},
|
},
|
||||||
"waiting": () => {
|
waiting: () => {
|
||||||
if (this.waitUpdateTimeout) {
|
if (this.waitUpdateTimeout) {
|
||||||
clearTimeout(this.waitUpdateTimeout)
|
clearTimeout(this.waitUpdateTimeout)
|
||||||
this.waitUpdateTimeout = null
|
this.waitUpdateTimeout = null
|
||||||
@ -76,7 +78,7 @@ export default class TrackInstance {
|
|||||||
this.player.state.loading = true
|
this.player.state.loading = true
|
||||||
}, 150)
|
}, 150)
|
||||||
},
|
},
|
||||||
"seeked": () => {
|
seeked: () => {
|
||||||
this.player.eventBus.emit(`player.seeked`, this.audio.currentTime)
|
this.player.eventBus.emit(`player.seeked`, this.audio.currentTime)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -104,7 +106,9 @@ export default class TrackInstance {
|
|||||||
this.audio.addEventListener(key, value)
|
this.audio.addEventListener(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.contextElement = this.player.audioContext.createMediaElementSource(this.audio)
|
this.contextElement = this.player.audioContext.createMediaElementSource(
|
||||||
|
this.audio,
|
||||||
|
)
|
||||||
|
|
||||||
this._initialized = true
|
this._initialized = true
|
||||||
|
|
||||||
@ -120,10 +124,13 @@ export default class TrackInstance {
|
|||||||
this.muxerPlayer.destroy()
|
this.muxerPlayer.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastProcessor = this.attachedProcessors[this.attachedProcessors.length - 1]
|
const lastProcessor =
|
||||||
|
this.attachedProcessors[this.attachedProcessors.length - 1]
|
||||||
|
|
||||||
if (lastProcessor) {
|
if (lastProcessor) {
|
||||||
this.attachedProcessors[this.attachedProcessors.length - 1]._destroy(this)
|
this.attachedProcessors[
|
||||||
|
this.attachedProcessors.length - 1
|
||||||
|
]._destroy(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.attachedProcessors = []
|
this.attachedProcessors = []
|
||||||
@ -142,14 +149,19 @@ export default class TrackInstance {
|
|||||||
|
|
||||||
if (this.manifest.service) {
|
if (this.manifest.service) {
|
||||||
if (!this.player.serviceProviders.has(this.manifest.service)) {
|
if (!this.player.serviceProviders.has(this.manifest.service)) {
|
||||||
throw new Error(`Service ${this.manifest.service} is not supported`)
|
throw new Error(
|
||||||
|
`Service ${this.manifest.service} is not supported`,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to resolve source file
|
// try to resolve source file
|
||||||
if (!this.manifest.source) {
|
if (!this.manifest.source) {
|
||||||
console.log("Resolving manifest cause no source defined")
|
console.log("Resolving manifest cause no source defined")
|
||||||
|
|
||||||
this.manifest = await this.player.serviceProviders.resolve(this.manifest.service, this.manifest)
|
this.manifest = await this.player.serviceProviders.resolve(
|
||||||
|
this.manifest.service,
|
||||||
|
this.manifest,
|
||||||
|
)
|
||||||
|
|
||||||
console.log("Manifest resolved", this.manifest)
|
console.log("Manifest resolved", this.manifest)
|
||||||
}
|
}
|
||||||
@ -169,21 +181,18 @@ export default class TrackInstance {
|
|||||||
this.manifest.metadata.title = this.manifest.source.split("/").pop()
|
this.manifest.metadata.title = this.manifest.source.split("/").pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if has overrides
|
// process overrides
|
||||||
const override = await this.manifest.serviceOperations.fetchOverride()
|
const override = await this.manifest.serviceOperations.fetchOverride()
|
||||||
|
|
||||||
if (override) {
|
if (override) {
|
||||||
console.log(`Override found for track ${this.manifest._id}`, override)
|
console.log(
|
||||||
|
`Override found for track ${this.manifest._id}`,
|
||||||
|
override,
|
||||||
|
)
|
||||||
|
|
||||||
this.manifest.overrides = override
|
this.manifest.overrides = override
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: idk why this is here, move somewhere else
|
|
||||||
// try {
|
|
||||||
// this.manifest = await this.manifest.analyzeCoverColor()
|
|
||||||
// } catch (error) {
|
|
||||||
// //x
|
|
||||||
// }
|
|
||||||
|
|
||||||
return this.manifest
|
return this.manifest
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -73,10 +73,6 @@ export default class TrackManifest {
|
|||||||
lyrics_enabled = false
|
lyrics_enabled = false
|
||||||
liked = null
|
liked = null
|
||||||
|
|
||||||
// TODO: implement this server feature to fetch some data from the server,
|
|
||||||
// used for example to fix a incorrect lyrics time
|
|
||||||
overrides = null
|
|
||||||
|
|
||||||
async initialize() {
|
async initialize() {
|
||||||
if (this.params.file) {
|
if (this.params.file) {
|
||||||
this.metadata = await this.analyzeMetadata(
|
this.metadata = await this.analyzeMetadata(
|
||||||
@ -167,11 +163,22 @@ export default class TrackManifest {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.ctx.serviceProviders.operation(
|
const result = await this.ctx.serviceProviders.operation(
|
||||||
"resolveLyrics",
|
"resolveLyrics",
|
||||||
this.service,
|
this.service,
|
||||||
this,
|
this,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
console.log(this.overrides)
|
||||||
|
|
||||||
|
if (this.overrides) {
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
...this.overrides,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
},
|
},
|
||||||
fetchOverride: async () => {
|
fetchOverride: async () => {
|
||||||
if (!this._id) {
|
if (!this._id) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user