Fix:Encode filename for audio player direct plays

This commit is contained in:
advplyr 2022-03-05 17:28:15 -06:00
parent 9f29b245d7
commit 83976b5549
5 changed files with 17 additions and 21 deletions

View File

@ -96,12 +96,8 @@ export default {
}, },
methods: { methods: {
getRelativePath(path) { getRelativePath(path) {
var filePath = path.replace(/\\/g, '/') var relativePath = path.replace(/\\/g, '/').replace(this.audiobookPath.replace(/\\/g, '/') + '/', '')
var audiobookPath = this.audiobookPath.replace(/\\/g, '/') return this.$encodeUriPath(relativePath)
return filePath
.replace(audiobookPath + '/', '')
.replace(/%/g, '%25')
.replace(/#/g, '%23')
} }
}, },
mounted() {} mounted() {}

View File

@ -71,15 +71,9 @@ export default {
}, },
otherFilesCleaned() { otherFilesCleaned() {
return this.files.map((file) => { return this.files.map((file) => {
var filePath = file.path.replace(/\\/g, '/')
var audiobookPath = this.audiobookPath.replace(/\\/g, '/')
return { return {
...file, ...file,
relativePath: filePath relativePath: this.getRelativePath(file.path)
.replace(audiobookPath + '/', '')
.replace(/%/g, '%25')
.replace(/#/g, '%23')
} }
}) })
}, },
@ -99,6 +93,10 @@ export default {
}, },
clickBar() { clickBar() {
this.showFiles = !this.showFiles this.showFiles = !this.showFiles
},
getRelativePath(path) {
var relativePath = path.replace(/\\/g, '/').replace(this.audiobookPath.replace(/\\/g, '/') + '/', '')
return this.$encodeUriPath(relativePath)
} }
}, },
mounted() {} mounted() {}

View File

@ -75,15 +75,9 @@ export default {
}, },
tracksCleaned() { tracksCleaned() {
return this.tracks.map((track) => { return this.tracks.map((track) => {
var trackPath = track.path.replace(/\\/g, '/')
var audiobookPath = this.audiobookPath.replace(/\\/g, '/')
return { return {
...track, ...track,
relativePath: trackPath relativePath: this.getRelativePath(track.path)
.replace(audiobookPath + '/', '')
.replace(/%/g, '%25')
.replace(/#/g, '%23')
} }
}) })
}, },
@ -100,6 +94,10 @@ export default {
methods: { methods: {
clickBar() { clickBar() {
this.showTracks = !this.showTracks this.showTracks = !this.showTracks
},
getRelativePath(path) {
var relativePath = path.replace(/\\/g, '/').replace(this.audiobookPath.replace(/\\/g, '/') + '/', '')
return this.$encodeUriPath(relativePath)
} }
}, },
mounted() {} mounted() {}

View File

@ -132,7 +132,7 @@ export default class PlayerHandler {
var audioTracks = (this.audiobook.tracks || []).map((track) => { var audioTracks = (this.audiobook.tracks || []).map((track) => {
var audioTrack = new AudioTrack(track) var audioTrack = new AudioTrack(track)
audioTrack.startOffset = runningTotal audioTrack.startOffset = runningTotal
audioTrack.contentUrl = `/lib/${this.audiobook.libraryId}/${this.audiobook.folderId}/${track.path}?token=${this.userToken}` audioTrack.contentUrl = `/lib/${this.audiobook.libraryId}/${this.audiobook.folderId}/${this.ctx.$encodeUriPath(track.path)}?token=${this.userToken}`
audioTrack.mimeType = this.getMimeTypeForTrack(track) audioTrack.mimeType = this.getMimeTypeForTrack(track)
audioTrack.canDirectPlay = !!this.player.playableMimetypes[audioTrack.mimeType] audioTrack.canDirectPlay = !!this.player.playableMimetypes[audioTrack.mimeType]

View File

@ -138,6 +138,10 @@ function xmlToJson(xml) {
} }
Vue.prototype.$xmlToJson = xmlToJson Vue.prototype.$xmlToJson = xmlToJson
Vue.prototype.$encodeUriPath = (path) => {
return path.replace(/\\/g, '/').replace(/%/g, '%25').replace(/#/g, '%23')
}
const encode = (text) => encodeURIComponent(Buffer.from(text).toString('base64')) const encode = (text) => encodeURIComponent(Buffer.from(text).toString('base64'))
Vue.prototype.$encode = encode Vue.prototype.$encode = encode
const decode = (text) => Buffer.from(decodeURIComponent(text), 'base64').toString() const decode = (text) => Buffer.from(decodeURIComponent(text), 'base64').toString()