mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-04 02:05:06 +02:00
Add: Filter and side rail button to show books with issues #132, Add: realtime updates for audiobook progress
This commit is contained in:
parent
874c910e24
commit
335bbac81d
14 changed files with 96 additions and 30 deletions
|
@ -86,7 +86,6 @@ class Server {
|
|||
clientEmitter(userId, ev, data) {
|
||||
var clients = this.getClientsForUser(userId)
|
||||
if (!clients.length) {
|
||||
console.log('clients', clients)
|
||||
return Logger.error(`[Server] clientEmitter - no clients found for user ${userId}`)
|
||||
}
|
||||
clients.forEach((client) => {
|
||||
|
@ -247,7 +246,7 @@ class Server {
|
|||
socket.on('close_stream', () => this.streamManager.closeStreamRequest(socket))
|
||||
socket.on('stream_update', (payload) => this.streamManager.streamUpdate(socket, payload))
|
||||
|
||||
socket.on('progress_update', (payload) => this.audiobookProgressUpdate(socket.sheepClient, payload))
|
||||
socket.on('progress_update', (payload) => this.audiobookProgressUpdate(socket, payload))
|
||||
|
||||
// Downloading
|
||||
socket.on('download', (payload) => this.downloadManager.downloadSocketRequest(socket, payload))
|
||||
|
@ -451,12 +450,20 @@ class Server {
|
|||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
audiobookProgressUpdate(client, progressPayload) {
|
||||
audiobookProgressUpdate(socket, progressPayload) {
|
||||
var client = socket.sheepClient
|
||||
if (!client || !client.user) {
|
||||
Logger.error('[Server] audiobookProgressUpdate invalid socket client')
|
||||
return
|
||||
}
|
||||
client.user.updateAudiobookProgress(progressPayload.audiobookId, progressPayload)
|
||||
var hasUpdates = client.user.updateAudiobookProgress(progressPayload.audiobookId, progressPayload)
|
||||
if (hasUpdates) {
|
||||
var userAudiobook = client.user.getAudiobookJSON(progressPayload.audiobookId)
|
||||
socket.emit('current_user_audiobook_update', {
|
||||
id: progressPayload.audiobookId,
|
||||
data: userAudiobook || null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async authenticateSocket(socket, token) {
|
||||
|
|
|
@ -153,8 +153,15 @@ class StreamManager {
|
|||
Logger.error('Invalid User for client', client)
|
||||
return
|
||||
}
|
||||
client.user.updateAudiobookProgressFromStream(client.stream)
|
||||
var userAudiobook = client.user.updateAudiobookProgressFromStream(client.stream)
|
||||
this.db.updateEntity('user', client.user)
|
||||
|
||||
if (userAudiobook) {
|
||||
socket.emit('current_user_audiobook_update', {
|
||||
id: userAudiobook.audiobookId,
|
||||
data: userAudiobook.toJSON()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = StreamManager
|
|
@ -193,16 +193,14 @@ class Audiobook {
|
|||
lastUpdate: this.lastUpdate,
|
||||
duration: this.totalDuration,
|
||||
size: this.totalSize,
|
||||
hasBookMatch: !!this.book,
|
||||
hasMissingParts: this.missingParts ? this.missingParts.length : 0,
|
||||
hasInvalidParts: this.invalidParts ? this.invalidParts.length : 0,
|
||||
// numEbooks: this.ebooks.length,
|
||||
ebooks: this.ebooks.map(ebook => ebook.toJSON()),
|
||||
numEbooks: this.ebooks.length,
|
||||
numTracks: this.tracks.length,
|
||||
chapters: this.chapters || [],
|
||||
isMissing: !!this.isMissing,
|
||||
isInvalid: !!this.isInvalid
|
||||
isInvalid: !!this.isInvalid,
|
||||
hasMissingParts: this.missingParts ? this.missingParts.length : 0,
|
||||
hasInvalidParts: this.invalidParts ? this.invalidParts.length : 0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +230,9 @@ class Audiobook {
|
|||
tracks: this.tracksToJSON(),
|
||||
chapters: this.chapters || [],
|
||||
isMissing: !!this.isMissing,
|
||||
isInvalid: !!this.isInvalid
|
||||
isInvalid: !!this.isInvalid,
|
||||
hasMissingParts: this.missingParts ? this.missingParts.length : 0,
|
||||
hasInvalidParts: this.invalidParts ? this.invalidParts.length : 0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ class Stream extends EventEmitter {
|
|||
|
||||
get clientProgress() {
|
||||
if (!this.clientCurrentTime) return 0
|
||||
var prog = Math.max(1, this.clientCurrentTime / this.totalDuration)
|
||||
var prog = Math.min(1, this.clientCurrentTime / this.totalDuration)
|
||||
return Number(prog.toFixed(3))
|
||||
}
|
||||
|
||||
|
@ -248,6 +248,7 @@ class Stream extends EventEmitter {
|
|||
this.ffmpeg.inputOption('-seek_timestamp 1')
|
||||
this.ffmpeg.inputFormat('concat')
|
||||
this.ffmpeg.inputOption('-safe 0')
|
||||
// this.ffmpeg.inputOption('-segment_time_metadata 1')
|
||||
|
||||
if (this.startTime > 0) {
|
||||
const shiftedStartTime = this.startTime - trackStartTime
|
||||
|
@ -259,7 +260,7 @@ class Stream extends EventEmitter {
|
|||
this.ffmpeg.inputOption('-noaccurate_seek')
|
||||
}
|
||||
|
||||
const logLevel = process.env.NODE_ENV === 'production' ? 'error' : 'warning'
|
||||
const logLevel = process.env.NODE_ENV === 'production' ? 'error' : 'error'
|
||||
const audioCodec = (this.hlsSegmentType === 'fmp4' || this.tracksAudioFileType === 'opus') ? 'aac' : 'copy'
|
||||
this.ffmpeg.addOption([
|
||||
`-loglevel ${logLevel}`,
|
||||
|
@ -270,7 +271,6 @@ class Stream extends EventEmitter {
|
|||
'-f hls',
|
||||
"-copyts",
|
||||
"-avoid_negative_ts make_non_negative",
|
||||
// '-start_at_zero',
|
||||
"-max_delay 5000000",
|
||||
"-max_muxing_queue_size 2048",
|
||||
`-hls_time 6`,
|
||||
|
|
|
@ -203,6 +203,7 @@ class User {
|
|||
this.audiobooks[stream.audiobookId] = new AudiobookProgress()
|
||||
}
|
||||
this.audiobooks[stream.audiobookId].updateFromStream(stream)
|
||||
return this.audiobooks[stream.audiobookId]
|
||||
}
|
||||
|
||||
updateAudiobookProgress(audiobook, updatePayload) {
|
||||
|
@ -267,5 +268,9 @@ class User {
|
|||
if (!this.librariesAccessible) return false
|
||||
return this.librariesAccessible.includes(libraryId)
|
||||
}
|
||||
|
||||
getAudiobookJSON(audiobookId) {
|
||||
return this.audiobooks[audiobookId] ? this.audiobooks[audiobookId].toJSON() : null
|
||||
}
|
||||
}
|
||||
module.exports = User
|
Loading…
Add table
Add a link
Reference in a new issue