From edc45addc9e91969542a147b8d2836740a8d4620 Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 26 Nov 2021 18:27:18 -0600 Subject: [PATCH] Change:Sleep timer shake to extend time 15m and fade out audio #44 #10, Change:Audio player show time remaining accounting for current playback speed #40, Fix:highlighted current chapter, Update api endpoints --- android/app/build.gradle | 4 +- .../audiobookshelf/app/AudiobookManager.kt | 2 +- .../com/audiobookshelf/app/MainActivity.kt | 38 ++++++ .../com/audiobookshelf/app/MyNativeAudio.kt | 5 +- .../app/PlayerNotificationService.kt | 108 +++++++++++++----- .../com/audiobookshelf/app/ShakeDetector.kt | 67 +++++++++++ components/app/AudioPlayer.vue | 56 +++++++-- components/app/AudioPlayerContainer.vue | 76 ++++-------- components/modals/SearchModal.vue | 2 +- components/modals/SleepTimerModal.vue | 11 +- components/tables/collection/BookTableRow.vue | 4 +- package.json | 2 +- pages/audiobook/_id/index.vue | 6 +- pages/collection/_id.vue | 2 +- pages/search.vue | 2 +- store/libraries.js | 2 +- store/user.js | 2 +- 17 files changed, 272 insertions(+), 117 deletions(-) create mode 100644 android/app/src/main/java/com/audiobookshelf/app/ShakeDetector.kt diff --git a/android/app/build.gradle b/android/app/build.gradle index 9c9cf2c8..28213273 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "com.audiobookshelf.app" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 46 - versionName "0.9.27-beta" + versionCode 47 + versionName "0.9.28-beta" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/android/app/src/main/java/com/audiobookshelf/app/AudiobookManager.kt b/android/app/src/main/java/com/audiobookshelf/app/AudiobookManager.kt index 764314ac..c1a8bddc 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/AudiobookManager.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/AudiobookManager.kt @@ -132,7 +132,7 @@ class AudiobookManager { } fun openStream(audiobook:Audiobook, streamListener:OnStreamData) { - var url = "$serverUrl/api/audiobook/${audiobook.id}/stream" + var url = "$serverUrl/api/books/${audiobook.id}/stream" val request = Request.Builder() .url(url).addHeader("Authorization", "Bearer $token") .build() diff --git a/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt b/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt index 435d2931..3f97f0fa 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt @@ -5,6 +5,8 @@ import android.app.DownloadManager import android.app.SearchManager import android.content.* import android.content.pm.PackageManager +import android.hardware.Sensor +import android.hardware.SensorManager import android.os.* import android.util.Log import androidx.activity.result.contract.ActivityResultContracts @@ -27,6 +29,11 @@ class MainActivity : BridgeActivity() { val storageHelper = SimpleStorageHelper(this) val storage = SimpleStorage(this) + // The following are used for the shake detection + private var mSensorManager: SensorManager? = null + private var mAccelerometer: Sensor? = null + private var mShakeDetector: ShakeDetector? = null + val broadcastReceiver = object: BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { when (intent?.action) { @@ -54,6 +61,24 @@ class MainActivity : BridgeActivity() { addAction(DownloadManager.ACTION_NOTIFICATION_CLICKED) } registerReceiver(broadcastReceiver, filter) + + initSensor() + } + + override fun onResume() { + super.onResume() + + Log.d(tag, "onResume Register sensor listener") + mSensorManager!!.registerListener( + mShakeDetector, + mAccelerometer, + SensorManager.SENSOR_DELAY_UI + ) + } + + override fun onPause() { + mSensorManager!!.unregisterListener(mShakeDetector) + super.onPause() } override fun onDestroy() { @@ -128,6 +153,19 @@ class MainActivity : BridgeActivity() { storageHelper.onRequestPermissionsResult(requestCode, permissions, grantResults) } + private fun initSensor() { + // ShakeDetector initialization + mSensorManager = getSystemService(SENSOR_SERVICE) as SensorManager + mAccelerometer = mSensorManager!!.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) + mShakeDetector = ShakeDetector() + mShakeDetector!!.setOnShakeListener(object : ShakeDetector.OnShakeListener { + override fun onShake(count: Int) { + Log.d(tag, "PHONE SHAKE! $count") + foregroundService.handleShake() + } + }) + } + // override fun onUserInteraction() { // super.onUserInteraction() // Log.d(tag, "USER INTERACTION") diff --git a/android/app/src/main/java/com/audiobookshelf/app/MyNativeAudio.kt b/android/app/src/main/java/com/audiobookshelf/app/MyNativeAudio.kt index 3a199533..551024ba 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/MyNativeAudio.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/MyNativeAudio.kt @@ -38,6 +38,9 @@ class MyNativeAudio : Plugin() { override fun onSleepTimerEnded(currentPosition:Long) { emit("onSleepTimerEnded", currentPosition) } + override fun onSleepTimerSet(sleepTimerEndTime:Long) { + emit("onSleepTimerSet", sleepTimerEndTime) + } }) } mainActivity.pluginCallback = foregroundServiceReady @@ -81,7 +84,6 @@ class MyNativeAudio : Plugin() { fun getCurrentTime(call: PluginCall) { Handler(Looper.getMainLooper()).post() { var currentTime = playerNotificationService.getCurrentTime() - Log.d(tag, "Get Current Time $currentTime") val ret = JSObject() ret.put("value", currentTime) call.resolve(ret) @@ -95,7 +97,6 @@ class MyNativeAudio : Plugin() { var lastPauseTime = playerNotificationService.getTheLastPauseTime() Log.d(tag, "Get Last Pause Time $lastPauseTime") var currentTime = playerNotificationService.getCurrentTime() - Log.d(tag, "Get Current Time $currentTime") //if (!isPlaying) currentTime -= playerNotificationService.calcPauseSeekBackTime() var id = playerNotificationService.getCurrentAudiobookId() Log.d(tag, "Get Current id $id") diff --git a/android/app/src/main/java/com/audiobookshelf/app/PlayerNotificationService.kt b/android/app/src/main/java/com/audiobookshelf/app/PlayerNotificationService.kt index 48647965..b66ab10b 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/PlayerNotificationService.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/PlayerNotificationService.kt @@ -49,9 +49,11 @@ import okhttp3.OkHttpClient import org.json.JSONObject import java.util.* import kotlin.concurrent.schedule +import kotlin.math.roundToInt const val NOTIFICATION_LARGE_ICON_SIZE = 144 // px +const val SLEEP_EXTENSION_TIME = 900000L // 15m class PlayerNotificationService : MediaBrowserServiceCompat() { @@ -64,6 +66,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { fun onMetadata(metadata: JSObject) fun onPrepare(audiobookId: String, playWhenReady: Boolean) fun onSleepTimerEnded(currentPosition: Long) + fun onSleepTimerSet(sleepTimerEndTime:Long) } @@ -101,7 +104,8 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { private var onSeekBack: Boolean = false private var sleepTimerTask:TimerTask? = null - private var sleepChapterTime:Long = 0L + private var sleepTimerRunning:Boolean = false + private var sleepTimerEndTime:Long = 0L private lateinit var audiobookManager:AudiobookManager private var newConnectionListener:SessionListener? = null @@ -490,7 +494,12 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { handleMediaButtonClickCount() } KeyEvent.KEYCODE_MEDIA_PLAY -> { - if (0 == mediaButtonClickCount) play() + if (0 == mediaButtonClickCount) { + play() + if (sleepTimerRunning) { + extendSleepTime() + } + } handleMediaButtonClickCount() } KeyEvent.KEYCODE_MEDIA_PAUSE -> { @@ -511,7 +520,12 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { if (0 == mediaButtonClickCount) pause() handleMediaButtonClickCount() } else { - if (0 == mediaButtonClickCount) play() + if (0 == mediaButtonClickCount) { + play() + if (sleepTimerRunning) { + extendSleepTime() + } + } handleMediaButtonClickCount() } } @@ -759,7 +773,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { fun getCurrentTime() : Long { - return mPlayer.currentPosition + return currentPlayer.currentPosition } fun getTheLastPauseTime() : Long { @@ -767,7 +781,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { } fun getDuration() : Long { - return mPlayer.duration + return currentPlayer.duration } fun calcPauseSeekBackTime() : Long { @@ -989,57 +1003,89 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { fun setSleepTimer(time: Long, isChapterTime: Boolean) : Boolean { Log.d(tag, "Setting Sleep Timer for $time is chapter time $isChapterTime") sleepTimerTask?.cancel() - sleepChapterTime = 0L + sleepTimerRunning = false + var currentTime = getCurrentTime() if (isChapterTime) { - // Validate time - if (currentPlayer.isPlaying) { - if (currentPlayer.currentPosition >= time) { - Log.d(tag, "Invalid setSleepTimer chapter time is already passed") - return false - } + if (currentTime > time) { + Log.d(tag, "Invalid sleep timer - current time is already passed chapter time $time") + return false } + sleepTimerEndTime = time + } else { + sleepTimerEndTime = currentTime + time + } - sleepChapterTime = time - sleepTimerTask = Timer("SleepTimer", false).schedule(0L, 1000L) { - Handler(Looper.getMainLooper()).post() { - if (currentPlayer.isPlaying && currentPlayer.currentPosition > sleepChapterTime) { + if (sleepTimerEndTime > getDuration()) { + sleepTimerEndTime = getDuration() + } + + Log.d(tag, "SLEEP VOLUME ${currentPlayer.volume} | ${currentPlayer.deviceVolume}") +// if (isChapterTime) { +// sleepChapterTime = time + listener?.onSleepTimerSet(sleepTimerEndTime) + + sleepTimerRunning = true + sleepTimerTask = Timer("SleepTimer", false).schedule(0L, 1000L) { + Handler(Looper.getMainLooper()).post() { + if (currentPlayer.isPlaying) { + var sleepTimeRemaining = sleepTimerEndTime - getCurrentTime() + var sleepTimeSecondsRemaining = ((sleepTimeRemaining / 1000).toDouble()).roundToInt() + Log.d(tag, "Sleep TIMER time remaining $sleepTimeSecondsRemaining s") + + if (sleepTimeRemaining <= 0) { Log.d(tag, "Sleep Timer Pausing Player on Chapter") currentPlayer.pause() listener?.onSleepTimerEnded(currentPlayer.currentPosition) sleepTimerTask?.cancel() + sleepTimerRunning = false + } else if (sleepTimeSecondsRemaining <= 30) { + // Start fading out audio + var volume = sleepTimeSecondsRemaining / 30F + Log.d(tag, "SLEEP VOLUME FADE $volume | ${sleepTimeSecondsRemaining}s remaining") + currentPlayer.volume = volume } } } - } else { - sleepTimerTask = Timer("SleepTimer", false).schedule(time) { - Log.d(tag, "Sleep Timer Done") - Handler(Looper.getMainLooper()).post() { - if (currentPlayer.isPlaying) { - Log.d(tag, "Sleep Timer Pausing Player") - currentPlayer.pause() - } - listener?.onSleepTimerEnded(currentPlayer.currentPosition) - } - } } return true } fun getSleepTimerTime():Long? { - var time = sleepTimerTask?.scheduledExecutionTime() - Log.d(tag, "Sleep Timer execution time $time") - return time + return sleepTimerEndTime } fun cancelSleepTimer() { Log.d(tag, "Canceling Sleep Timer") sleepTimerTask?.cancel() sleepTimerTask = null - sleepChapterTime = 0L + sleepTimerEndTime = 0 + sleepTimerRunning = false + listener?.onSleepTimerSet(0) } + private fun extendSleepTime() { + if (!sleepTimerRunning) return + currentPlayer.volume = 1F + sleepTimerEndTime += SLEEP_EXTENSION_TIME + if (sleepTimerEndTime > getDuration()) sleepTimerEndTime = getDuration() + listener?.onSleepTimerSet(sleepTimerEndTime) + } + + fun handleShake() { + Log.d(tag, "HANDLE SHAKE HERE") + if (sleepTimerRunning) { + Log.d(tag, "Sleep Timer is Running, EXTEND TIME") + extendSleepTime() + } + } + + + /* + CAST STUFF + */ + private inner class CastSessionAvailabilityListener : SessionAvailabilityListener { /** diff --git a/android/app/src/main/java/com/audiobookshelf/app/ShakeDetector.kt b/android/app/src/main/java/com/audiobookshelf/app/ShakeDetector.kt new file mode 100644 index 00000000..ac2b31b9 --- /dev/null +++ b/android/app/src/main/java/com/audiobookshelf/app/ShakeDetector.kt @@ -0,0 +1,67 @@ +package com.audiobookshelf.app + +import android.hardware.Sensor +import android.hardware.SensorEvent +import android.hardware.SensorEventListener +import android.hardware.SensorManager +import java.lang.Math.sqrt +import kotlin.math.sqrt + +class ShakeDetector : SensorEventListener { + private var mListener: OnShakeListener? = null + private var mShakeTimestamp: Long = 0 + private var mShakeCount = 0 + fun setOnShakeListener(listener: OnShakeListener?) { + mListener = listener + } + + interface OnShakeListener { + fun onShake(count: Int) + } + + override fun onAccuracyChanged( + sensor: Sensor, + accuracy: Int + ) { // ignore + } + + override fun onSensorChanged(event: SensorEvent) { + if (mListener != null) { + val x = event.values[0] + val y = event.values[1] + val z = event.values[2] + val gX = x / SensorManager.GRAVITY_EARTH + val gY = y / SensorManager.GRAVITY_EARTH + val gZ = z / SensorManager.GRAVITY_EARTH + // gForce will be close to 1 when there is no movement. + val gForce: Float = sqrt(gX * gX + gY * gY + gZ * gZ) + if (gForce > SHAKE_THRESHOLD_GRAVITY) { + val now = System.currentTimeMillis() + // ignore shake events too close to each other (500ms) + if (mShakeTimestamp + SHAKE_SLOP_TIME_MS > now) { + return + } + // reset the shake count after 3 seconds of no shakes + if (mShakeTimestamp + SHAKE_COUNT_RESET_TIME_MS < now) { + mShakeCount = 0 + } + mShakeTimestamp = now + mShakeCount++ + mListener!!.onShake(mShakeCount) + } + } + } + + companion object { + /* + * The gForce that is necessary to register as shake. + * Must be greater than 1G (one earth gravity unit). + * You can install "G-Force", by Blake La Pierre + * from the Google Play Store and run it to see how + * many G's it takes to register a shake + */ + private const val SHAKE_THRESHOLD_GRAVITY = 2.7f + private const val SHAKE_SLOP_TIME_MS = 500 + private const val SHAKE_COUNT_RESET_TIME_MS = 3000 + } +} diff --git a/components/app/AudioPlayer.vue b/components/app/AudioPlayer.vue index 93ee40be..a271c38e 100644 --- a/components/app/AudioPlayer.vue +++ b/components/app/AudioPlayer.vue @@ -32,8 +32,7 @@
-

-{{ $secondsToTimestamp(timeLeftInChapter) }}

-

{{ Math.ceil(sleepTimeoutCurrentTime / 1000 / 60) }}m

+

{{ sleepTimeRemainingPretty }}

format_list_bulleted @@ -54,17 +53,17 @@
-
+
-

0:00

+

0:00

{{ currentChapterTitle }}

-

{{ totalDurationPretty }}

+

{{ timeRemainingPretty }}

@@ -76,6 +75,7 @@ import MyNativeAudio from '@/plugins/my-native-audio' export default { props: { + playing: Boolean, audiobook: { type: Object, default: () => {} @@ -90,8 +90,7 @@ export default { }, loading: Boolean, sleepTimerRunning: Boolean, - sleepTimeoutCurrentTime: Number, - sleepTimerEndOfChapterTime: Number + sleepTimerEndTime: Number }, data() { return { @@ -127,6 +126,14 @@ export default { } }, computed: { + isPlaying: { + get() { + return this.playing + }, + set(val) { + this.$emit('update:playing', val) + } + }, book() { return this.audiobook.book || {} }, @@ -156,9 +163,31 @@ export default { totalDurationPretty() { return this.$secondsToTimestamp(this.totalDuration) }, + timeRemaining() { + return (this.totalDuration - this.currentTime) / this.currentPlaybackRate + }, + timeRemainingPretty() { + if (this.timeRemaining < 0) { + return this.$secondsToTimestamp(this.timeRemaining * -1) + } + return '-' + this.$secondsToTimestamp(this.timeRemaining) + }, timeLeftInChapter() { if (!this.currentChapter) return 0 return this.currentChapter.end - this.currentTime + }, + sleepTimeRemaining() { + if (!this.sleepTimerEndTime) return 0 + return Math.max(0, this.sleepTimerEndTime / 1000 - this.currentTime) + }, + sleepTimeRemainingPretty() { + if (!this.sleepTimeRemaining) return '0s' + var secondsRemaining = Math.round(this.sleepTimeRemaining) + if (secondsRemaining > 91) { + return Math.ceil(secondsRemaining / 60) + 'm' + } else { + return secondsRemaining + 's' + } } }, methods: { @@ -269,9 +298,6 @@ export default { if (this.loading) return MyNativeAudio.seekForward({ amount: '10000' }) }, - // sendStreamUpdate() { - // this.$emit('updateTime', this.currentTime) - // }, setStreamReady() { this.readyTrackWidth = this.trackWidth this.$refs.readyTrack.style.width = this.trackWidth + 'px' @@ -310,6 +336,7 @@ export default { console.error('Invalid no played track ref') return } + this.$emit('updateTime', this.currentTime) if (this.seekLoading) { this.seekLoading = false @@ -354,6 +381,12 @@ export default { }, clickTrack(e) { if (this.loading) return + if (!this.showFullscreen) { + // Track not clickable on mini-player + return + } + if (e) e.stopPropagation() + var offsetX = e.offsetX var perc = offsetX / this.trackWidth var time = perc * this.totalDuration @@ -462,10 +495,12 @@ export default { play() { MyNativeAudio.playPlayer() this.startPlayInterval() + this.isPlaying = true }, pause() { MyNativeAudio.pausePlayer() this.stopPlayInterval() + this.isPlaying = false }, startPlayInterval() { this.startListenTimeInterval() @@ -474,6 +509,7 @@ export default { this.playInterval = setInterval(async () => { var data = await MyNativeAudio.getCurrentTime() this.currentTime = Number((data.value / 1000).toFixed(2)) + this.timeupdate() }, 1000) }, diff --git a/components/app/AudioPlayerContainer.vue b/components/app/AudioPlayerContainer.vue index 46cb9710..33bd810c 100644 --- a/components/app/AudioPlayerContainer.vue +++ b/components/app/AudioPlayerContainer.vue @@ -3,18 +3,19 @@
- +
@@ -35,6 +36,7 @@ import MyNativeAudio from '@/plugins/my-native-audio' export default { data() { return { + isPlaying: false, audioPlayerReady: false, stream: null, download: null, @@ -45,10 +47,10 @@ export default { playbackSpeed: 1, showChapterModal: false, currentTime: 0, - sleepTimeoutCurrentTime: 0, isSleepTimerRunning: false, - sleepTimerEndOfChapterTime: 0, + sleepTimerEndTime: 0, onSleepTimerEndedListener: null, + onSleepTimerSetListener: null, sleepInterval: null, currentEndOfChapterTime: 0, totalDuration: 0 @@ -138,6 +140,10 @@ export default { if (this.cover.startsWith('http')) return this.cover var coverSrc = this.$store.getters['audiobooks/getBookCoverSrc'](this.audiobook) return coverSrc + }, + sleepTimeRemaining() { + if (!this.sleepTimerEndTime) return 0 + return Math.max(0, this.sleepTimerEndTime / 1000 - this.currentTime) } }, methods: { @@ -154,16 +160,24 @@ export default { }, onSleepTimerEnded({ value: currentPosition }) { this.isSleepTimerRunning = false - if (this.sleepInterval) clearInterval(this.sleepInterval) - if (currentPosition) { console.log('Sleep Timer Ended Current Position: ' + currentPosition) var currentTime = Math.floor(currentPosition / 1000) this.updateTime(currentTime) } }, + onSleepTimerSet({ value: sleepTimerEndTime }) { + console.log('SLEEP TIMER SET', sleepTimerEndTime) + if (sleepTimerEndTime === 0) { + console.log('Sleep timer canceled') + this.isSleepTimerRunning = false + } else { + this.isSleepTimerRunning = true + } + + this.sleepTimerEndTime = sleepTimerEndTime + }, showSleepTimer() { - console.log('show sleep timer') if (this.currentChapter) { this.currentEndOfChapterTime = Math.floor(this.currentChapter.end) } else { @@ -171,60 +185,16 @@ export default { } this.showSleepTimerModal = true }, - async getSleepTimerTime() { - var res = await MyNativeAudio.getSleepTimerTime() - if (res && res.value) { - var time = Number(res.value) - return time - Date.now() - } - return 0 - }, async selectSleepTimeout({ time, isChapterTime }) { console.log('Setting sleep timer', time, isChapterTime) var res = await MyNativeAudio.setSleepTimer({ time: String(time), isChapterTime }) if (!res.success) { return this.$toast.error('Sleep timer did not set, invalid time') } - if (isChapterTime) { - this.sleepTimerEndOfChapterTime = time - this.isSleepTimerRunning = true - } else { - this.sleepTimerEndOfChapterTime = 0 - this.setSleepTimeoutTimer(time) - } }, async cancelSleepTimer() { console.log('Canceling sleep timer') await MyNativeAudio.cancelSleepTimer() - this.isSleepTimerRunning = false - this.sleepTimerEndOfChapterTime = 0 - if (this.sleepInterval) clearInterval(this.sleepInterval) - }, - async syncSleepTimer() { - var time = await this.getSleepTimerTime() - this.setSleepTimeoutTimer(time) - }, - setSleepTimeoutTimer(startTime) { - if (this.sleepInterval) clearInterval(this.sleepInterval) - - this.sleepTimeoutCurrentTime = startTime - this.isSleepTimerRunning = true - var elapsed = 0 - this.sleepInterval = setInterval(() => { - this.sleepTimeoutCurrentTime = Math.max(0, this.sleepTimeoutCurrentTime - 1000) - - if (this.sleepTimeoutCurrentTime <= 0) { - clearInterval(this.sleepInterval) - return - } - - // Sync with the actual time from android Timer - elapsed++ - if (elapsed > 5) { - clearInterval(this.sleepInterval) - this.syncSleepTimer() - } - }, 1000) }, clickChapterBtn() { if (!this.chapters.length) return @@ -477,6 +447,7 @@ export default { }, mounted() { this.onSleepTimerEndedListener = MyNativeAudio.addListener('onSleepTimerEnded', this.onSleepTimerEnded) + this.onSleepTimerSetListener = MyNativeAudio.addListener('onSleepTimerSet', this.onSleepTimerSet) this.playbackSpeed = this.$store.getters['user/getUserSetting']('playbackRate') console.log(`[AudioPlayerContainer] Init Playback Speed: ${this.playbackSpeed}`) @@ -487,6 +458,7 @@ export default { }, beforeDestroy() { if (this.onSleepTimerEndedListener) this.onSleepTimerEndedListener.remove() + if (this.onSleepTimerSetListener) this.onSleepTimerSetListener.remove() if (this.$server.socket) { this.$server.socket.off('stream_open', this.streamOpen) diff --git a/components/modals/SearchModal.vue b/components/modals/SearchModal.vue index 3ed2efb9..e4ca742b 100644 --- a/components/modals/SearchModal.vue +++ b/components/modals/SearchModal.vue @@ -68,7 +68,7 @@ export default { return } this.isFetching = true - var results = await this.$axios.$get(`/api/audiobooks?q=${value}`).catch((error) => { + var results = await this.$axios.$get(`/api/books?q=${value}`).catch((error) => { console.error('Search error', error) return [] }) diff --git a/components/modals/SleepTimerModal.vue b/components/modals/SleepTimerModal.vue index bcf6e06c..1cd47f63 100644 --- a/components/modals/SleepTimerModal.vue +++ b/components/modals/SleepTimerModal.vue @@ -23,8 +23,7 @@
-

EOC: {{ endOfChapterTimePretty }}

-

{{ timeRemainingPretty }}

+

{{ timeRemainingPretty }}

Cancel Timer
@@ -38,8 +37,7 @@ export default { value: Boolean, currentTime: Number, sleepTimerRunning: Boolean, - currentEndOfChapterTime: Number, - endOfChapterTimeSet: Number + currentEndOfChapterTime: Number }, data() { return {} @@ -57,10 +55,7 @@ export default { return [1, 15, 30, 45, 60, 75, 90, 120] }, timeRemainingPretty() { - return this.$secondsToTimestamp(this.currentTime / 1000) - }, - endOfChapterTimePretty() { - return this.$secondsToTimestamp(this.endOfChapterTimeSet / 1000) + return this.$secondsToTimestamp(this.currentTime) } }, methods: { diff --git a/components/tables/collection/BookTableRow.vue b/components/tables/collection/BookTableRow.vue index ab83d5dd..8e8afee3 100644 --- a/components/tables/collection/BookTableRow.vue +++ b/components/tables/collection/BookTableRow.vue @@ -89,7 +89,7 @@ export default { } this.isProcessingReadUpdate = true this.$axios - .$patch(`/api/user/audiobook/${this.book.id}`, updatePayload) + .$patch(`/api/me/audiobook/${this.book.id}`, updatePayload) .then(() => { this.isProcessingReadUpdate = false this.$toast.success(`"${this.bookTitle}" Marked as ${updatePayload.isRead ? 'Read' : 'Not Read'}`) @@ -104,7 +104,7 @@ export default { this.processingRemove = true this.$axios - .$delete(`/api/collection/${this.collectionId}/book/${this.book.id}`) + .$delete(`/api/collections/${this.collectionId}/book/${this.book.id}`) .then((updatedCollection) => { console.log(`Book removed from collection`, updatedCollection) this.$toast.success('Book removed from collection') diff --git a/package.json b/package.json index 59bc2e7e..e5955473 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "audiobookshelf-app", - "version": "v0.9.27-beta", + "version": "v0.9.28-beta", "author": "advplyr", "scripts": { "dev": "nuxt --hostname localhost --port 1337", diff --git a/pages/audiobook/_id/index.vue b/pages/audiobook/_id/index.vue index 442e94f6..a50275db 100644 --- a/pages/audiobook/_id/index.vue +++ b/pages/audiobook/_id/index.vue @@ -59,7 +59,7 @@ export default { var audiobook = null if (app.$server.connected) { - audiobook = await app.$axios.$get(`/api/audiobook/${audiobookId}`).catch((error) => { + audiobook = await app.$axios.$get(`/api/books/${audiobookId}`).catch((error) => { console.error('Failed', error) return false }) @@ -229,7 +229,7 @@ export default { if (this.$server.connected) { await this.$axios - .$patch(`/api/user/audiobook/${this.audiobookId}/reset-progress`) + .$patch(`/api/me/audiobook/${this.audiobookId}/reset-progress`) .then(() => { console.log('Progress reset complete') this.$toast.success(`Your progress was reset`) @@ -245,7 +245,7 @@ export default { audiobookUpdated() { console.log('Audiobook Updated - Fetch full audiobook') this.$axios - .$get(`/api/audiobook/${this.audiobookId}`) + .$get(`/api/books/${this.audiobookId}`) .then((audiobook) => { this.audiobook = audiobook }) diff --git a/pages/collection/_id.vue b/pages/collection/_id.vue index f63ebdee..d7c467ab 100644 --- a/pages/collection/_id.vue +++ b/pages/collection/_id.vue @@ -42,7 +42,7 @@ export default { return redirect(`/connect?redirect=${route.path}`) } - var collection = await app.$axios.$get(`/api/collection/${params.id}`).catch((error) => { + var collection = await app.$axios.$get(`/api/collections/${params.id}`).catch((error) => { console.error('Failed', error) return false }) diff --git a/pages/search.vue b/pages/search.vue index 173196bd..9f8a4853 100644 --- a/pages/search.vue +++ b/pages/search.vue @@ -49,7 +49,7 @@ export default { return } this.isFetching = true - var results = await this.$axios.$get(`/api/audiobooks?q=${value}`).catch((error) => { + var results = await this.$axios.$get(`/api/books?q=${value}`).catch((error) => { console.error('Search error', error) return [] }) diff --git a/store/libraries.js b/store/libraries.js index 41c89517..af164210 100644 --- a/store/libraries.js +++ b/store/libraries.js @@ -28,7 +28,7 @@ export const actions = { } return this.$axios - .$get(`/api/library/${libraryId}`) + .$get(`/api/libraries/${libraryId}`) .then((data) => { commit('addUpdate', data) commit('setCurrentLibrary', libraryId) diff --git a/store/user.js b/store/user.js index 1a8d842f..1a6a693e 100644 --- a/store/user.js +++ b/store/user.js @@ -42,7 +42,7 @@ export const actions = { var updatePayload = { ...payload } - return this.$axios.$patch('/api/user/settings', updatePayload).then((result) => { + return this.$axios.$patch('/api/me/settings', updatePayload).then((result) => { if (result.success) { commit('setSettings', result.settings) return true