mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-11-20 07:21:30 +01:00
Fix crash when probing audio files by updating start/end chapter data type to Long #128, remove unused files and generic database save/load methods
This commit is contained in:
1 parent
d5b69be7c1
commit
52fd8ac5e8
11 files changed
+33
-108
No files matched your search
@@ -2,11 +2,6 @@ package com.audiobookshelf.app.data
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import com.fasterxml.jackson.annotation.JsonInclude
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import com.fasterxml.jackson.core.json.JsonReadFeature
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||
import com.fasterxml.jackson.databind.jsonschema.JsonSerializableSchema
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
data class AudioProbeStream(
|
||||
@@ -27,15 +22,15 @@ data class AudioProbeChapterTags(
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
data class AudioProbeChapter(
|
||||
val id:Int,
|
||||
val start:Int,
|
||||
val end:Int,
|
||||
val start:Long,
|
||||
val end:Long,
|
||||
val tags:AudioProbeChapterTags?
|
||||
) {
|
||||
@JsonIgnore
|
||||
fun getBookChapter():BookChapter {
|
||||
var startS = start / 1000.0
|
||||
var endS = end / 1000.0
|
||||
var title = tags?.title ?: "Chapter $id"
|
||||
val startS = start / 1000.0
|
||||
val endS = end / 1000.0
|
||||
val title = tags?.title ?: "Chapter $id"
|
||||
return BookChapter(id, startS, endS, title)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class Podcast(
|
||||
) : MediaType(metadata, coverPath) {
|
||||
@JsonIgnore
|
||||
override fun getAudioTracks():List<AudioTrack> {
|
||||
var tracks = episodes?.map { it.audioTrack }
|
||||
val tracks = episodes?.map { it.audioTrack }
|
||||
return tracks?.filterNotNull() ?: mutableListOf()
|
||||
}
|
||||
@JsonIgnore
|
||||
@@ -98,7 +98,7 @@ class Podcast(
|
||||
// Add new episodes
|
||||
audioTracks.forEach { at ->
|
||||
if (episodes?.find{ it.audioTrack?.localFileId == at.localFileId } == null) {
|
||||
var newEpisode = PodcastEpisode("local_" + at.localFileId,episodes?.size ?: 0 + 1,null,null,at.title,null,null,null,at,at.duration,0, null)
|
||||
val newEpisode = PodcastEpisode("local_" + at.localFileId,episodes?.size ?: 0 + 1,null,null,at.title,null,null,null,at,at.duration,0, null)
|
||||
episodes?.add(newEpisode)
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ class Podcast(
|
||||
}
|
||||
@JsonIgnore
|
||||
override fun addAudioTrack(audioTrack:AudioTrack) {
|
||||
var newEpisode = PodcastEpisode("local_" + audioTrack.localFileId,episodes?.size ?: 0 + 1,null,null,audioTrack.title,null,null,null,audioTrack,audioTrack.duration,0, null)
|
||||
val newEpisode = PodcastEpisode("local_" + audioTrack.localFileId,episodes?.size ?: 0 + 1,null,null,audioTrack.title,null,null,null,audioTrack,audioTrack.duration,0, null)
|
||||
episodes?.add(newEpisode)
|
||||
|
||||
var index = 1
|
||||
@@ -132,7 +132,7 @@ class Podcast(
|
||||
}
|
||||
@JsonIgnore
|
||||
fun addEpisode(audioTrack:AudioTrack, episode:PodcastEpisode) {
|
||||
var newEpisode = PodcastEpisode("local_" + episode.id,episodes?.size ?: 0 + 1,episode.episode,episode.episodeType,episode.title,episode.subtitle,episode.description,null,audioTrack,audioTrack.duration,0, episode.id)
|
||||
val newEpisode = PodcastEpisode("local_" + episode.id,episodes?.size ?: 0 + 1,episode.episode,episode.episodeType,episode.title,episode.subtitle,episode.description,null,audioTrack,audioTrack.duration,0, episode.id)
|
||||
episodes?.add(newEpisode)
|
||||
|
||||
var index = 1
|
||||
|
||||
@@ -17,9 +17,9 @@ class DbManager {
|
||||
}
|
||||
|
||||
fun getLocalLibraryItems(mediaType:String? = null):MutableList<LocalLibraryItem> {
|
||||
var localLibraryItems:MutableList<LocalLibraryItem> = mutableListOf()
|
||||
val localLibraryItems:MutableList<LocalLibraryItem> = mutableListOf()
|
||||
Paper.book("localLibraryItems").allKeys.forEach {
|
||||
var localLibraryItem:LocalLibraryItem? = Paper.book("localLibraryItems").read(it)
|
||||
val localLibraryItem:LocalLibraryItem? = Paper.book("localLibraryItems").read(it)
|
||||
if (localLibraryItem != null && (mediaType.isNullOrEmpty() || mediaType == localLibraryItem.mediaType)) {
|
||||
localLibraryItems.add(localLibraryItem)
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class DbManager {
|
||||
}
|
||||
|
||||
fun getLocalLibraryItemsInFolder(folderId:String):List<LocalLibraryItem> {
|
||||
var localLibraryItems = getLocalLibraryItems()
|
||||
val localLibraryItems = getLocalLibraryItems()
|
||||
return localLibraryItems.filter {
|
||||
it.folderId == folderId
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class DbManager {
|
||||
}
|
||||
|
||||
fun getAllLocalFolders():List<LocalFolder> {
|
||||
var localFolders:MutableList<LocalFolder> = mutableListOf()
|
||||
val localFolders:MutableList<LocalFolder> = mutableListOf()
|
||||
Paper.book("localFolders").allKeys.forEach { localFolderId ->
|
||||
Paper.book("localFolders").read<LocalFolder>(localFolderId)?.let {
|
||||
localFolders.add(it)
|
||||
@@ -75,7 +75,7 @@ class DbManager {
|
||||
}
|
||||
|
||||
fun removeLocalFolder(folderId:String) {
|
||||
var localLibraryItems = getLocalLibraryItemsInFolder(folderId)
|
||||
val localLibraryItems = getLocalLibraryItemsInFolder(folderId)
|
||||
localLibraryItems.forEach {
|
||||
Paper.book("localLibraryItems").delete(it.id)
|
||||
}
|
||||
@@ -91,7 +91,7 @@ class DbManager {
|
||||
}
|
||||
|
||||
fun getDownloadItems():List<AbsDownloader.DownloadItem> {
|
||||
var downloadItems:MutableList<AbsDownloader.DownloadItem> = mutableListOf()
|
||||
val downloadItems:MutableList<AbsDownloader.DownloadItem> = mutableListOf()
|
||||
Paper.book("downloadItems").allKeys.forEach { downloadItemId ->
|
||||
Paper.book("downloadItems").read<AbsDownloader.DownloadItem>(downloadItemId)?.let {
|
||||
downloadItems.add(it)
|
||||
@@ -108,7 +108,7 @@ class DbManager {
|
||||
return Paper.book("localMediaProgress").read(localMediaProgressId)
|
||||
}
|
||||
fun getAllLocalMediaProgress():List<LocalMediaProgress> {
|
||||
var mediaProgress:MutableList<LocalMediaProgress> = mutableListOf()
|
||||
val mediaProgress:MutableList<LocalMediaProgress> = mutableListOf()
|
||||
Paper.book("localMediaProgress").allKeys.forEach { localMediaProgressId ->
|
||||
Paper.book("localMediaProgress").read<LocalMediaProgress>(localMediaProgressId)?.let {
|
||||
mediaProgress.add(it)
|
||||
@@ -126,14 +126,14 @@ class DbManager {
|
||||
|
||||
// Make sure all local file ids still exist
|
||||
fun cleanLocalLibraryItems() {
|
||||
var localLibraryItems = getLocalLibraryItems()
|
||||
val localLibraryItems = getLocalLibraryItems()
|
||||
|
||||
localLibraryItems.forEach { lli ->
|
||||
var hasUpates = false
|
||||
|
||||
// Check local files
|
||||
lli.localFiles = lli.localFiles.filter { localFile ->
|
||||
var file = File(localFile.absolutePath)
|
||||
val file = File(localFile.absolutePath)
|
||||
if (!file.exists()) {
|
||||
Log.d(tag, "cleanLocalLibraryItems: Local file ${localFile.absolutePath} was removed from library item ${lli.media.metadata.title}")
|
||||
hasUpates = true
|
||||
@@ -143,7 +143,7 @@ class DbManager {
|
||||
|
||||
// Check audio tracks and episodes
|
||||
if (lli.isPodcast) {
|
||||
var podcast = lli.media as Podcast
|
||||
val podcast = lli.media as Podcast
|
||||
podcast.episodes = podcast.episodes?.filter { ep ->
|
||||
if (lli.localFiles.find { lf -> lf.id == ep.audioTrack?.localFileId } == null) {
|
||||
Log.d(tag, "cleanLocalLibraryItems: Podcast episode ${ep.title} was removed from library item ${lli.media.metadata.title}")
|
||||
@@ -152,7 +152,7 @@ class DbManager {
|
||||
ep.audioTrack != null && lli.localFiles.find { lf -> lf.id == ep.audioTrack?.localFileId } != null
|
||||
} as MutableList<PodcastEpisode>
|
||||
} else {
|
||||
var book = lli.media as Book
|
||||
val book = lli.media as Book
|
||||
book.tracks = book.tracks?.filter { track ->
|
||||
if (lli.localFiles.find { lf -> lf.id == track.localFileId } == null) {
|
||||
Log.d(tag, "cleanLocalLibraryItems: Audio track ${track.title} was removed from library item ${lli.media.metadata.title}")
|
||||
@@ -164,7 +164,7 @@ class DbManager {
|
||||
|
||||
// Check cover still there
|
||||
lli.coverAbsolutePath?.let {
|
||||
var coverFile = File(it)
|
||||
val coverFile = File(it)
|
||||
|
||||
if (!coverFile.exists()) {
|
||||
Log.d(tag, "cleanLocalLibraryItems: Cover $it was removed from library item ${lli.media.metadata.title}")
|
||||
@@ -183,10 +183,10 @@ class DbManager {
|
||||
|
||||
// Remove any local media progress where the local media item is not found
|
||||
fun cleanLocalMediaProgress() {
|
||||
var localMediaProgress = getAllLocalMediaProgress()
|
||||
var localLibraryItems = getLocalLibraryItems()
|
||||
val localMediaProgress = getAllLocalMediaProgress()
|
||||
val localLibraryItems = getLocalLibraryItems()
|
||||
localMediaProgress.forEach {
|
||||
var matchingLLI = localLibraryItems.find { lli -> lli.id == it.localLibraryItemId }
|
||||
val matchingLLI = localLibraryItems.find { lli -> lli.id == it.localLibraryItemId }
|
||||
if (matchingLLI == null) {
|
||||
Log.d(tag, "cleanLocalMediaProgress: No matching local library item for local media progress ${it.id} - removing")
|
||||
Paper.book("localMediaProgress").delete(it.id)
|
||||
@@ -195,8 +195,8 @@ class DbManager {
|
||||
Log.d(tag, "cleanLocalMediaProgress: Podcast media progress has no episode id - removing")
|
||||
Paper.book("localMediaProgress").delete(it.id)
|
||||
} else {
|
||||
var podcast = matchingLLI.media as Podcast
|
||||
var matchingLEp = podcast.episodes?.find { ep -> ep.id == it.localEpisodeId }
|
||||
val podcast = matchingLLI.media as Podcast
|
||||
val matchingLEp = podcast.episodes?.find { ep -> ep.id == it.localEpisodeId }
|
||||
if (matchingLEp == null) {
|
||||
Log.d(tag, "cleanLocalMediaProgress: Podcast media progress for episode ${it.localEpisodeId} not found - removing")
|
||||
Paper.book("localMediaProgress").delete(it.id)
|
||||
@@ -212,15 +212,4 @@ class DbManager {
|
||||
fun getLocalPlaybackSession(playbackSessionId:String):PlaybackSession? {
|
||||
return Paper.book("localPlaybackSession").read(playbackSessionId)
|
||||
}
|
||||
|
||||
fun saveObject(db:String, key:String, value:JSONObject) {
|
||||
Log.d(tag, "Saving Object $key ${value.toString()}")
|
||||
Paper.book(db).write(key, value)
|
||||
}
|
||||
|
||||
fun loadObject(db:String, key:String):JSONObject? {
|
||||
var json: JSONObject? = Paper.book(db).read(key)
|
||||
Log.d(tag, "Loaded Object $key $json")
|
||||
return json
|
||||
}
|
||||
}
|
||||
@@ -288,38 +288,4 @@ class AbsDatabase : Plugin() {
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Generic Webview calls to db
|
||||
//
|
||||
@PluginMethod
|
||||
fun saveFromWebview(call: PluginCall) {
|
||||
var db = call.getString("db", "").toString()
|
||||
var key = call.getString("key", "").toString()
|
||||
var value = call.getObject("value")
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
if (db == "" || key == "" || value == null) {
|
||||
Log.d(tag, "saveFromWebview Invalid key/value")
|
||||
} else {
|
||||
var json = value as JSONObject
|
||||
DeviceManager.dbManager.saveObject(db, key, json)
|
||||
}
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun loadFromWebview(call:PluginCall) {
|
||||
var db = call.getString("db", "").toString()
|
||||
var key = call.getString("key", "").toString()
|
||||
if (db == "" || key == "") {
|
||||
Log.d(tag, "loadFromWebview Invalid Key")
|
||||
call.resolve()
|
||||
return
|
||||
}
|
||||
var json = DeviceManager.dbManager.loadObject(db, key)
|
||||
var jsobj = JSObject.fromJSONObject(json)
|
||||
call.resolve(jsobj)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -9,13 +9,13 @@ install! 'cocoapods', :disable_input_output_paths => true
|
||||
def capacitor_pods
|
||||
pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
|
||||
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
|
||||
pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app'
|
||||
pod 'CapacitorDialog', :path => '../../node_modules/@capacitor/dialog'
|
||||
pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics'
|
||||
pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network'
|
||||
pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
|
||||
pod 'CapacitorStorage', :path => '../../node_modules/@capacitor/storage'
|
||||
pod 'RobingenzCapacitorAppUpdate', :path => '../../node_modules/@robingenz/capacitor-app-update'
|
||||
pod 'CapacitorApp', :path => '..\..\node_modules\@capacitor\app'
|
||||
pod 'CapacitorDialog', :path => '..\..\node_modules\@capacitor\dialog'
|
||||
pod 'CapacitorHaptics', :path => '..\..\node_modules\@capacitor\haptics'
|
||||
pod 'CapacitorNetwork', :path => '..\..\node_modules\@capacitor\network'
|
||||
pod 'CapacitorStatusBar', :path => '..\..\node_modules\@capacitor\status-bar'
|
||||
pod 'CapacitorStorage', :path => '..\..\node_modules\@capacitor\storage'
|
||||
pod 'RobingenzCapacitorAppUpdate', :path => '..\..\node_modules\@robingenz\capacitor-app-update'
|
||||
end
|
||||
|
||||
target 'App' do
|
||||
|
||||
@@ -6,28 +6,6 @@ const isWeb = Capacitor.getPlatform() == 'web'
|
||||
class DbService {
|
||||
constructor() { }
|
||||
|
||||
// Please dont use this, it is not implemented in ios (maybe key: primary value: any ?)
|
||||
save(db, key, value) {
|
||||
if (isWeb) return
|
||||
return AbsDatabase.saveFromWebview({ db, key, value }).then(() => {
|
||||
console.log('Saved data', db, key, JSON.stringify(value))
|
||||
}).catch((error) => {
|
||||
console.error('Failed to save data', error)
|
||||
})
|
||||
}
|
||||
|
||||
// Please dont use this, it is not implemented in ios
|
||||
load(db, key) {
|
||||
if (isWeb) return null
|
||||
return AbsDatabase.loadFromWebview({ db, key }).then((data) => {
|
||||
console.log('Loaded data', db, key, JSON.stringify(data))
|
||||
return data
|
||||
}).catch((error) => {
|
||||
console.error('Failed to load', error)
|
||||
return null
|
||||
})
|
||||
}
|
||||
|
||||
getDeviceData() {
|
||||
return AbsDatabase.getDeviceData().then((data) => {
|
||||
console.log('Loaded device data', JSON.stringify(data))
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
/*! Sortable 1.8.4 - MIT | git://github.com/SortableJS/Sortable.git */
|
||||
|
||||
!function (t) { "use strict"; "function" == typeof define && define.amd ? define(t) : "undefined" != typeof module && void 0 !== module.exports ? module.exports = t() : window.Sortable = t() }(function () { "use strict"; if ("undefined" == typeof window || !window.document) return function () { throw new Error("Sortable.js requires a window with a document") }; var U, V, f, u, q, G, h, X, Y, A, K, n, Z, Q, l, s, c, p, k, J, $, tt, et, ot, g, nt, I = [], B = !1, v = !1, it = !1, d = [], rt = !1, at = !1, m = [], i = /\s+/g, lt = "Sortable" + (new Date).getTime(), b = window, st = b.document, w = b.parseInt, ct = b.setTimeout, e = b.jQuery || b.Zepto, o = b.Polymer, r = { capture: !1, passive: !1 }, dt = !!navigator.userAgent.match(/(?:Trident.*rv[ :]?11\.|msie|iemobile)/i), _ = !!navigator.userAgent.match(/Edge/i), y = !!navigator.userAgent.match(/firefox/i), D = !(!navigator.userAgent.match(/safari/i) || navigator.userAgent.match(/chrome/i) || navigator.userAgent.match(/android/i)), S = !!navigator.userAgent.match(/iP(ad|od|hone)/i), T = _ || dt ? "cssFloat" : "float", a = "draggable" in st.createElement("div"), C = function () { if (dt) return !1; var t = st.createElement("x"); return t.style.cssText = "pointer-events:auto", "auto" === t.style.pointerEvents }(), ht = !1, E = !1, ut = Math.abs, x = Math.min, N = Math.max, M = [], P = function (t, e) { var o = Dt(t), n = w(o.width) - w(o.paddingLeft) - w(o.paddingRight) - w(o.borderLeftWidth) - w(o.borderRightWidth), i = Mt(t, 0, e), r = Mt(t, 1, e), a = i && Dt(i), l = r && Dt(r), s = a && w(a.marginLeft) + w(a.marginRight) + Lt(i).width, c = l && w(l.marginLeft) + w(l.marginRight) + Lt(r).width; if ("flex" === o.display) return "column" === o.flexDirection || "column-reverse" === o.flexDirection ? "vertical" : "horizontal"; if ("grid" === o.display) return o.gridTemplateColumns.split(" ").length <= 1 ? "vertical" : "horizontal"; if (i && "none" !== a.float) { var d = "left" === a.float ? "left" : "right"; return !r || "both" !== l.clear && l.clear !== d ? "horizontal" : "vertical" } return i && ("block" === a.display || "flex" === a.display || "table" === a.display || "grid" === a.display || n <= s && "none" === o[T] || r && "none" === o[T] && n < s + c) ? "vertical" : "horizontal" }, O = function (t, e) { if (!t || !t.getBoundingClientRect) return H(); var o = t, n = !1; do { if (o.clientWidth < o.scrollWidth || o.clientHeight < o.scrollHeight) { var i = Dt(o); if (o.clientWidth < o.scrollWidth && ("auto" == i.overflowX || "scroll" == i.overflowX) || o.clientHeight < o.scrollHeight && ("auto" == i.overflowY || "scroll" == i.overflowY)) { if (!o || !o.getBoundingClientRect || o === st.body) return H(); if (n || e) return o; n = !0 } } } while (o = o.parentNode); return H() }, H = function () { return dt ? st.documentElement : st.scrollingElement }, ft = function (t, e, o) { t.scrollLeft += e, t.scrollTop += o }, R = It(function (o, t, e, n) { if (t.scroll) { var i = e ? e[lt] : window, r = t.scrollSensitivity, a = t.scrollSpeed, l = o.clientX, s = o.clientY, c = H(), d = !1; Y !== e && (L(), X = t.scroll, A = t.scrollFn, !0 === X && (X = O(e, !0), Y = X)); var h = 0, u = X; do { var f, p, g, v, m, b, w, _, y, D = u, S = Lt(D), T = S.top, C = S.bottom, E = S.left, x = S.right, N = S.width, M = S.height; if (f = D.scrollWidth, p = D.scrollHeight, g = Dt(D), _ = D.scrollLeft, y = D.scrollTop, w = D === c ? (b = N < f && ("auto" === g.overflowX || "scroll" === g.overflowX || "visible" === g.overflowX), M < p && ("auto" === g.overflowY || "scroll" === g.overflowY || "visible" === g.overflowY)) : (b = N < f && ("auto" === g.overflowX || "scroll" === g.overflowX), M < p && ("auto" === g.overflowY || "scroll" === g.overflowY)), v = b && (ut(x - l) <= r && _ + N < f) - (ut(E - l) <= r && !!_), m = w && (ut(C - s) <= r && y + M < p) - (ut(T - s) <= r && !!y), !I[h]) for (var P = 0; P <= h; P++)I[P] || (I[P] = {}); I[h].vx == v && I[h].vy == m && I[h].el === D || (I[h].el = D, I[h].vx = v, I[h].vy = m, clearInterval(I[h].pid), !D || 0 == v && 0 == m || (d = !0, I[h].pid = setInterval(function () { n && 0 === this.layer && (mt.active._emulateDragOver(!0), mt.active._onTouchMove(k, !0)); var t = I[this.layer].vy ? I[this.layer].vy * a : 0, e = I[this.layer].vx ? I[this.layer].vx * a : 0; "function" == typeof A && "continue" !== A.call(i, e, t, o, k, I[this.layer].el) || ft(I[this.layer].el, e, t) }.bind({ layer: h }), 24))), h++ } while (t.bubbleScroll && u !== c && (u = O(u, !1))); B = d } }, 30), L = function () { I.forEach(function (t) { clearInterval(t.pid) }), I = [] }, W = function (t) { function s(a, l) { return function (t, e, o, n) { var i = t.options.group.name && e.options.group.name && t.options.group.name === e.options.group.name; if (null == a && (l || i)) return !0; if (null == a || !1 === a) return !1; if (l && "clone" === a) return a; if ("function" == typeof a) return s(a(t, e, o, n), l)(t, e, o, n); var r = (l ? t : e).options.group.name; return !0
Line truncated
|
||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 122 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 151 KiB |
Reference in new issue
Block a user