mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-11-04 03:17:00 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const Path = require('path')
 | 
						|
const { encodeUriPath } = require('../../utils/fileUtils')
 | 
						|
 | 
						|
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 ? 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 = Path.join(`${global.RouterBasePath}/s/item/${itemId}`, encodeUriPath(audioFile.metadata.relPath))
 | 
						|
    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 |