mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-09-01 07:30:00 +02:00
Configure more local file data
This commit is contained in:
parent
fec1ec554b
commit
9eca03cfd7
3 changed files with 22 additions and 13 deletions
|
@ -58,7 +58,7 @@ public class AbsDownloader: CAPPlugin {
|
||||||
let localUrl = itemDirectory.appendingPathComponent("\(filename)")
|
let localUrl = itemDirectory.appendingPathComponent("\(filename)")
|
||||||
|
|
||||||
downloadTrack(serverUrl: serverUrl, localUrl: localUrl)
|
downloadTrack(serverUrl: serverUrl, localUrl: localUrl)
|
||||||
return LocalFile(filename, track.mimeType, localUrl)
|
return LocalFile(item.id, filename, track.mimeType, localUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func urlForTrack(item: LibraryItem, track: AudioTrack) -> URL {
|
private func urlForTrack(item: LibraryItem, track: AudioTrack) -> URL {
|
||||||
|
@ -75,7 +75,7 @@ public class AbsDownloader: CAPPlugin {
|
||||||
|
|
||||||
// Create library item directory
|
// Create library item directory
|
||||||
do {
|
do {
|
||||||
try FileManager.default.createDirectory(at: itemDirectory, withIntermediateDirectories: false)
|
try FileManager.default.createDirectory(at: itemDirectory, withIntermediateDirectories: true)
|
||||||
} catch {
|
} catch {
|
||||||
NSLog("Failed to CREATE LI DIRECTORY \(error)")
|
NSLog("Failed to CREATE LI DIRECTORY \(error)")
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import RealmSwift
|
import RealmSwift
|
||||||
|
|
||||||
|
|
||||||
class LocalLibraryItem: Object, Encodable {
|
class LocalLibraryItem: Object, Encodable {
|
||||||
@Persisted(primaryKey: true) var id: String = UUID().uuidString
|
@Persisted(primaryKey: true) var id: String = UUID().uuidString
|
||||||
@Persisted var basePath: String = ""
|
@Persisted var basePath: String = ""
|
||||||
|
|
|
@ -49,7 +49,7 @@ extension LocalLibraryItem {
|
||||||
self.init()
|
self.init()
|
||||||
self.contentUrl = localUrl.absoluteString
|
self.contentUrl = localUrl.absoluteString
|
||||||
self.mediaType = item.mediaType
|
self.mediaType = item.mediaType
|
||||||
self.media = LocalMediaType(item.media)
|
self.media = LocalMediaType(item.media, coverPath: "", files: files)
|
||||||
self.localFiles.append(objectsIn: files)
|
self.localFiles.append(objectsIn: files)
|
||||||
// TODO: self.coverContentURL
|
// TODO: self.coverContentURL
|
||||||
// TODO: self.converAbsolutePath
|
// TODO: self.converAbsolutePath
|
||||||
|
@ -90,11 +90,11 @@ extension LocalMediaType {
|
||||||
try container.encode(autoDownloadEpisodes, forKey: .autoDownloadEpisodes)
|
try container.encode(autoDownloadEpisodes, forKey: .autoDownloadEpisodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
convenience init(_ mediaType: MediaType) {
|
convenience init(_ mediaType: MediaType, coverPath: String, files: [LocalFile]) {
|
||||||
self.init()
|
self.init()
|
||||||
self.libraryItemId = mediaType.libraryItemId
|
self.libraryItemId = mediaType.libraryItemId
|
||||||
self.metadata = LocalMetadata(mediaType.metadata)
|
self.metadata = LocalMetadata(mediaType.metadata)
|
||||||
// TODO: self.coverPath
|
self.coverPath = coverPath
|
||||||
self.tags.append(objectsIn: mediaType.tags ?? [])
|
self.tags.append(objectsIn: mediaType.tags ?? [])
|
||||||
self.audioFiles.append(objectsIn: mediaType.audioFiles!.enumerated().map() {
|
self.audioFiles.append(objectsIn: mediaType.audioFiles!.enumerated().map() {
|
||||||
i, audioFile -> LocalAudioFile in LocalAudioFile(audioFile)
|
i, audioFile -> LocalAudioFile in LocalAudioFile(audioFile)
|
||||||
|
@ -103,11 +103,12 @@ extension LocalMediaType {
|
||||||
i, chapter -> LocalChapter in LocalChapter(chapter)
|
i, chapter -> LocalChapter in LocalChapter(chapter)
|
||||||
})
|
})
|
||||||
self.tracks.append(objectsIn: mediaType.tracks!.enumerated().map() {
|
self.tracks.append(objectsIn: mediaType.tracks!.enumerated().map() {
|
||||||
i, track in LocalAudioTrack(track)
|
i, track in LocalAudioTrack(track, libraryItemId: self.libraryItemId ?? "", filename: files[i].filename ?? "")
|
||||||
})
|
})
|
||||||
self.size = mediaType.size
|
self.size = mediaType.size
|
||||||
self.duration = mediaType.duration
|
self.duration = mediaType.duration
|
||||||
// TODO: self.episodes
|
// TODO: self.episodes
|
||||||
|
// TODO: Handle podcast auto downloads
|
||||||
self.autoDownloadEpisodes = mediaType.autoDownloadEpisodes
|
self.autoDownloadEpisodes = mediaType.autoDownloadEpisodes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,7 +223,7 @@ extension LocalAudioFile {
|
||||||
self.init()
|
self.init()
|
||||||
self.index = audioFile.index
|
self.index = audioFile.index
|
||||||
self.ino = audioFile.ino
|
self.ino = audioFile.ino
|
||||||
// TODO: self.metadata
|
// self.metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func encode(to encoder: Encoder) throws {
|
func encode(to encoder: Encoder) throws {
|
||||||
|
@ -246,6 +247,13 @@ extension LocalAuthor {
|
||||||
try container.encode(name, forKey: .name)
|
try container.encode(name, forKey: .name)
|
||||||
try container.encode(coverPath, forKey: .coverPath)
|
try container.encode(coverPath, forKey: .coverPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convenience init(_ author: Author) {
|
||||||
|
self.init()
|
||||||
|
self.id = author.id
|
||||||
|
self.name = author.name
|
||||||
|
// self.coverPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension LocalChapter {
|
extension LocalChapter {
|
||||||
|
@ -301,16 +309,16 @@ extension LocalAudioTrack {
|
||||||
try container.encode(serverIndex, forKey: .serverIndex)
|
try container.encode(serverIndex, forKey: .serverIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
convenience init(_ track: AudioTrack) {
|
convenience init(_ track: AudioTrack, libraryItemId: String, filename: String) {
|
||||||
self.init()
|
self.init()
|
||||||
self.index = track.index
|
self.index = track.index
|
||||||
self.startOffset = track.startOffset
|
self.startOffset = track.startOffset
|
||||||
self.duration = track.duration
|
self.duration = track.duration
|
||||||
self.title = track.title
|
self.title = track.title
|
||||||
self.contentUrl = track.contentUrl // TODO: Different URL
|
self.contentUrl = "" // TODO: Different URL
|
||||||
self.mimeType = track.mimeType
|
self.mimeType = track.mimeType
|
||||||
// TODO: self.metadata
|
// TODO: self.metadata
|
||||||
// TODO: self.localFileId
|
self.localFileId = "\(libraryItemId)_\(filename.toBase64())"
|
||||||
self.serverIndex = track.serverIndex
|
self.serverIndex = track.serverIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,6 +338,8 @@ extension LocalFileMetadata {
|
||||||
try container.encode(path, forKey: .path)
|
try container.encode(path, forKey: .path)
|
||||||
try container.encode(relPath, forKey: .relPath)
|
try container.encode(relPath, forKey: .relPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: Can we skip this object? */
|
||||||
}
|
}
|
||||||
|
|
||||||
extension LocalFile {
|
extension LocalFile {
|
||||||
|
@ -352,9 +362,9 @@ extension LocalFile {
|
||||||
try container.encode(size, forKey: .size)
|
try container.encode(size, forKey: .size)
|
||||||
}
|
}
|
||||||
|
|
||||||
convenience init(_ filename: String, _ mimeType: String, _ localUrl: URL) {
|
convenience init(_ libraryItemId: String, _ filename: String, _ mimeType: String, _ localUrl: URL) {
|
||||||
self.init()
|
self.init()
|
||||||
self.id = localUrl.absoluteString.toBase64()
|
self.id = "\(libraryItemId)_\(filename.toBase64())"
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.contentUrl = localUrl.absoluteString
|
self.contentUrl = localUrl.absoluteString
|
||||||
self.absolutePath = localUrl.path
|
self.absolutePath = localUrl.path
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue