mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-11-03 10:57:03 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
class AudioTrack {
 | 
						|
  constructor() {
 | 
						|
    this.index = null
 | 
						|
    this.startOffset = null
 | 
						|
    this.duration = null
 | 
						|
    this.title = null
 | 
						|
    this.contentUrl = null
 | 
						|
    this.mimeType = null
 | 
						|
    this.codec = null
 | 
						|
    this.metadata = null
 | 
						|
  }
 | 
						|
 | 
						|
  toJSON() {
 | 
						|
    return {
 | 
						|
      index: this.index,
 | 
						|
      startOffset: this.startOffset,
 | 
						|
      duration: this.duration,
 | 
						|
      title: this.title,
 | 
						|
      contentUrl: this.contentUrl,
 | 
						|
      mimeType: this.mimeType,
 | 
						|
      codec: this.codec,
 | 
						|
      metadata: this.metadata?.toJSON() || null
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  setData(itemId, audioFile, startOffset) {
 | 
						|
    this.index = audioFile.index
 | 
						|
    this.startOffset = startOffset
 | 
						|
    this.duration = audioFile.duration
 | 
						|
    this.title = audioFile.metadata.filename || ''
 | 
						|
 | 
						|
    this.contentUrl = `/api/items/${itemId}/file/${audioFile.ino}`
 | 
						|
    this.mimeType = audioFile.mimeType
 | 
						|
    this.codec = audioFile.codec || null
 | 
						|
    this.metadata = audioFile.metadata.clone()
 | 
						|
  }
 | 
						|
 | 
						|
  setFromStream(title, duration, contentUrl) {
 | 
						|
    this.index = 1
 | 
						|
    this.startOffset = 0
 | 
						|
    this.duration = duration
 | 
						|
    this.title = title
 | 
						|
    this.contentUrl = contentUrl
 | 
						|
    this.mimeType = 'application/vnd.apple.mpegurl'
 | 
						|
  }
 | 
						|
}
 | 
						|
module.exports = AudioTrack
 |