Start of new data model

This commit is contained in:
advplyr 2022-03-08 19:31:44 -06:00
parent 2b7f53b0a7
commit 65793f7109
18 changed files with 672 additions and 8 deletions

View File

@ -275,7 +275,6 @@ export default {
return 'check_circle' return 'check_circle'
} }
} }
}, }
mounted() {}
} }
</script> </script>

View File

@ -0,0 +1,166 @@
/*
This is an example of a fully expanded book library item
*/
const LibraryItem = require('../server/objects/LibraryItem')
new LibraryItem({
id: 'li_abai123wir',
ino: "55450570412017066",
libraryId: 'lib_1239p1d8',
folderId: 'fol_192ab8901',
path: '/audiobooks/Terry Goodkind/Sword of Truth/1 - Wizards First Rule',
relPath: '/Terry Goodkind/Sword of Truth/1 - Wizards First Rule',
mtimeMs: 1646784672127,
ctimeMs: 1646784672127,
birthtimeMs: 1646784672127,
addedAt: 1646784672127,
lastUpdate: 1646784672127,
lastScan: 1646784672127,
scanVersion: 1.72,
isMissing: false,
entityType: 'book',
entity: { // Book.js
metadata: { // BookMetadata.js
title: 'Wizards First Rule',
subtitle: null,
authors: [
{
id: 'au_42908lkajsfdk',
name: 'Terry Goodkind'
}
],
narrators: ['Sam Tsoutsouvas'],
series: [
{
id: 'se_902384lansf',
name: 'Sword of Truth',
sequence: 1
}
],
genres: ['Fantasy', 'Adventure'],
publishedYear: '1994',
publishedDate: '1994-01-01',
publisher: 'Brilliance Audio',
description: 'In the aftermath of the brutal murder of his father, a mysterious woman...',
isbn: '289374092834',
asin: '19023819203',
language: 'english'
},
tags: ['favorites'],
audioFiles: [
{ // AudioFile.js
ino: "55450570412017066",
index: 1,
metadata: { // FileMetadata.js
filename: 'audiofile.mp3',
ext: '.mp3',
path: '/audiobooks/Terry Goodkind/Sword of Truth/1 - Wizards First Rule/CD01/audiofile.mp3',
relPath: '/CD01/audiofile.mp3',
mtimeMs: 1646784672127,
ctimeMs: 1646784672127,
birthtimeMs: 1646784672127,
size: 1197449516
},
trackNumFromMeta: 1,
discNumFromMeta: null,
trackNumFromFilename: null,
discNumFromFilename: 1,
manuallyVerified: false,
exclude: false,
format: "MP2/3 (MPEG audio layer 2/3)",
duration: 2342342,
bitRate: 324234,
language: null,
codec: 'mp3',
timeBase: "1/14112000",
channels: 1,
channelLayout: "mono",
chapters: [],
embeddedCoverArt: 'jpeg', // Video stream codec ['mjpeg', 'jpeg', 'png'] or null
metatags: { // AudioMetatags.js : (Metatags/ID3 tags - only stores values that are found)
tagAlbum: '',
tagArtist: '',
tagGenre: '',
tagTitle: '',
tagSeries: '',
tagSeriesPart: '',
tagTrack: '',
tagDisc: '',
tagSubtitle: '',
tagAlbumArtist: '',
tagDate: '',
tagComposer: '',
tagPublisher: '',
tagComment: '',
tagDescription: '',
tagEncoder: '',
tagEncodedBy: '',
tagIsbn: '',
tagLanguage: '',
tagASIN: ''
},
addedAt: 1646784672127,
lastUpdate: 1646784672127
}
],
ebookFiles: [
{ // EBookFile.js
ino: "55450570412017066",
metadata: { // FileMetadata.js
filename: 'ebookfile.mobi',
ext: '.mobi',
path: '/audiobooks/Terry Goodkind/Sword of Truth/1 - Wizards First Rule/ebookfile.mobi',
relPath: '/ebookfile.mobi',
mtimeMs: 1646784672127,
ctimeMs: 1646784672127,
birthtimeMs: 1646784672127,
size: 1197449516
},
ebookFormat: 'mobi',
addedAt: 1646784672127,
lastUpdate: 1646784672127
}
],
chapters: [
{
id: 0,
title: 'Chapter 01',
start: 0,
end: 2467.753
}
]
},
libraryFiles: [
{ // LibraryFile.js
ino: "55450570412017066",
metadata: { // FileMetadata.js
filename: 'cover.png',
ext: '.png',
path: '/audiobooks/Terry Goodkind/Sword of Truth/1 - Wizards First Rule/subfolder/cover.png',
relPath: '/subfolder/cover.png',
mtimeMs: 1646784672127,
ctimeMs: 1646784672127,
birthtimeMs: 1646784672127,
size: 1197449516
},
addedAt: 1646784672127,
lastUpdate: 1646784672127
},
{ // LibraryFile.js
ino: "55450570412017066",
metadata: { // FileMetadata.js
filename: 'cover.png',
ext: '.mobi',
path: '/audiobooks/Terry Goodkind/Sword of Truth/1 - Wizards First Rule/ebookfile.mobi',
relPath: '/ebookfile.mobi',
mtimeMs: 1646784672127,
ctimeMs: 1646784672127,
birthtimeMs: 1646784672127,
size: 1197449516
},
addedAt: 1646784672127,
lastUpdate: 1646784672127
}
]
})

View File

@ -9,7 +9,7 @@ const abmetadataGenerator = require('../utils/abmetadataGenerator')
const Logger = require('../Logger') const Logger = require('../Logger')
const Book = require('./Book') const Book = require('./Book')
const AudioTrack = require('./AudioTrack') const AudioTrack = require('./AudioTrack')
const AudioFile = require('./AudioFile') const AudioFile = require('./files/AudioFile')
const AudiobookFile = require('./AudiobookFile') const AudiobookFile = require('./AudiobookFile')
class Audiobook { class Audiobook {

View File

@ -0,0 +1,86 @@
const Logger = require('../Logger')
const LibraryFile = require('./files/LibraryFile')
const Book = require('./entities/Book')
const Podcast = require('./entities/Podcast')
class LibraryItem {
constructor(libraryItem = null) {
this.id = null
this.ino = null // Inode
this.libraryId = null
this.folderId = null
this.path = null
this.relPath = null
this.mtimeMs = null
this.ctimeMs = null
this.birthtimeMs = null
this.addedAt = null
this.lastUpdate = null
this.lastScan = null
this.scanVersion = null
// Entity was scanned and not found
this.isMissing = false
this.entityType = null
this.entity = null
this.libraryFiles = []
if (libraryItem) {
this.construct(libraryItem)
}
}
construct(libraryItem) {
this.id = libraryItem.id
this.ino = libraryItem.ino || null
this.libraryId = libraryItem.libraryId
this.folderId = libraryItem.folderId
this.path = libraryItem.path
this.relPath = libraryItem.relPath
this.mtimeMs = libraryItem.mtimeMs || 0
this.ctimeMs = libraryItem.ctimeMs || 0
this.birthtimeMs = libraryItem.birthtimeMs || 0
this.addedAt = libraryItem.addedAt
this.lastUpdate = libraryItem.lastUpdate || this.addedAt
this.lastScan = libraryItem.lastScan || null
this.scanVersion = libraryItem.scanVersion || null
this.isMissing = !!libraryItem.isMissing
this.entityType = libraryItem.entityType
if (this.entityType === 'book') {
this.entity = new Book(libraryItem.entity)
} else if (this.entityType === 'podcast') {
this.entity = new Podcast(libraryItem.entity)
}
this.libraryFiles = libraryItem.libraryFiles.map(f => new LibraryFile(f))
}
toJSON() {
return {
id: this.id,
ino: this.ino,
libraryId: this.libraryId,
folderId: this.folderId,
path: this.path,
relPath: this.relPath,
mtimeMs: this.mtimeMs,
ctimeMs: this.ctimeMs,
birthtimeMs: this.birthtimeMs,
addedAt: this.addedAt,
lastUpdate: this.lastUpdate,
lastScan: this.lastScan,
scanVersion: this.scanVersion,
isMissing: !!this.isMissing,
entityType: this.entityType,
entity: this.entity.toJSON(),
libraryFiles: this.libraryFiles.map(f => f.toJSON())
}
}
}
module.exports = LibraryItem

View File

@ -0,0 +1,45 @@
class Author {
constructor(author) {
this.id = null
this.asin = null
this.name = null
this.imagePath = null
this.imageFullPath = null
this.addedAt = null
this.updatedAt = null
if (author) {
this.construct(author)
}
}
construct(author) {
this.id = author.id
this.asin = author.asin
this.name = author.name
this.imagePath = author.imagePath
this.imageFullPath = author.imageFullPath
this.addedAt = author.addedAt
this.updatedAt = author.updatedAt
}
toJSON() {
return {
id: this.id,
asin: this.asin,
name: this.name,
imagePath: this.imagePath,
imageFullPath: this.imageFullPath,
addedAt: this.addedAt,
updatedAt: this.updatedAt
}
}
toJSONMinimal() {
return {
id: this.id,
name: this.name
}
}
}
module.exports = Author

View File

@ -0,0 +1,41 @@
const BookMetadata = require('../metadata/BookMetadata')
const AudioFile = require('../files/AudioFile')
const EBookFile = require('../files/EBookFile')
const AudioTrack = require('../AudioTrack')
class Book {
constructor(book) {
this.metadata = null
this.tags = []
this.audioFiles = []
this.ebookFiles = []
this.audioTracks = []
this.chapters = []
if (books) {
this.construct(book)
}
}
construct(book) {
this.metadata = new BookMetadata(book.metadata)
this.tags = [...book.tags]
this.audioFiles = book.audioFiles.map(f => new AudioFile(f))
this.ebookFiles = book.ebookFiles.map(f => new EBookFile(f))
this.audioTracks = book.audioTracks.map(a => new AudioTrack(a))
this.chapters = book.chapters.map(c => ({ ...c }))
}
toJSON() {
return {
metadata: this.metadata.toJSON(),
tags: [...this.tags],
audioFiles: this.audioFiles.map(f => f.toJSON()),
ebookFiles: this.ebookFiles.map(f => f.toJSON()),
audioTracks: this.audioTracks.map(a => a.toJSON()),
chapters: this.chapters.map(c => ({ ...c }))
}
}
}
module.exports = Book

View File

@ -0,0 +1,43 @@
const PodcastEpisode = require('./PodcastEpisode')
const PodcastMetadata = require('../metadata/PodcastMetadata')
class Podcast {
constructor(podcast) {
this.id = null
this.metadata = null
this.cover = null
this.coverFullPath = null
this.episodes = []
this.createdAt = null
this.lastUpdate = null
if (podcast) {
this.construct(podcast)
}
}
construct(podcast) {
this.id = podcast.id
this.metadata = new PodcastMetadata(podcast.metadata)
this.cover = podcast.cover
this.coverFullPath = podcast.coverFullPath
this.episodes = podcast.episodes.map((e) => new PodcastEpisode(e))
this.createdAt = podcast.createdAt
this.lastUpdate = podcast.lastUpdate
}
toJSON() {
return {
id: this.id,
metadata: this.metadata.toJSON(),
cover: this.cover,
coverFullPath: this.coverFullPath,
episodes: this.episodes.map(e => e.toJSON()),
createdAt: this.createdAt,
lastUpdate: this.lastUpdate
}
}
}
module.exports = Podcast

View File

@ -0,0 +1,38 @@
const AudioFile = require('../files/AudioFile')
class PodcastEpisode {
constructor(episode) {
this.id = null
this.podcastId = null
this.episodeNumber = null
this.audioFile = null
this.addedAt = null
this.updatedAt = null
if (episode) {
this.construct(episode)
}
}
construct(episode) {
this.id = episode.id
this.podcastId = episode.podcastId
this.episodeNumber = episode.episodeNumber
this.audioFile = new AudioFile(episode.audioFile)
this.addedAt = episode.addedAt
this.updatedAt = episode.updatedAt
}
toJSON() {
return {
id: this.id,
podcastId: this.podcastId,
episodeNumber: this.episodeNumber,
audioFile: this.audioFile.toJSON(),
addedAt: this.addedAt,
updatedAt: this.updatedAt
}
}
}
module.exports = PodcastEpisode

View File

@ -0,0 +1,40 @@
class Series {
constructor(series) {
this.id = null
this.name = null
this.sequence = null
this.addedAt = null
this.updatedAt = null
if (series) {
this.construct(series)
}
}
construct(series) {
this.id = series.id
this.name = series.name
this.sequence = series.sequence
this.addedAt = series.addedAt
this.updatedAt = series.updatedAt
}
toJSON() {
return {
id: this.id,
name: this.name,
sequence: this.sequence,
addedAt: this.addedAt,
updatedAt: this.updatedAt
}
}
toJSONMinimal() {
return {
id: this.id,
name: this.name,
sequence: this.sequence
}
}
}
module.exports = Series

View File

@ -1,7 +1,7 @@
const { isNullOrNaN } = require('../utils/index') const { isNullOrNaN } = require('../../utils/index')
const Logger = require('../Logger') const Logger = require('../../Logger')
const AudioFileMetadata = require('./AudioFileMetadata') const AudioFileMetadata = require('../metadata/AudioFileMetadata')
class AudioFile { class AudioFile {
constructor(data) { constructor(data) {

View File

@ -0,0 +1,34 @@
const FileMetadata = require('../metadata/FileMetadata')
class EBookFile {
constructor(file) {
this.ino = null
this.metadata = null
this.ebookFormat = null
this.addedAt = null
this.lastUpdate = null
if (file) {
this.construct(file)
}
}
construct(file) {
this.ino = file.ino
this.metadata = new FileMetadata(file)
this.ebookFormat = file.ebookFormat
this.addedAt = file.addedAt
this.lastUpdate = file.lastUpdate
}
toJSON() {
return {
ino: this.ino,
metadata: this.metadata.toJSON(),
ebookFormat: this.ebookFormat,
addedAt: this.addedAt,
lastUpdate: this.lastUpdate
}
}
}
module.exports = EBookFile

View File

@ -0,0 +1,31 @@
const FileMetadata = require('../metadata/FileMetadata')
class LibraryFile {
constructor(file) {
this.ino = null
this.metadata = null
this.addedAt = null
this.updatedAt = null
if (file) {
this.construct(file)
}
}
construct(file) {
this.ino = file.ino
this.metadata = new FileMetadata(file.metadata)
this.addedAt = file.addedAt
this.updatedAt = file.updatedAt
}
toJSON() {
return {
ino: this.ino,
metadata: this.metadata.toJSON(),
addedAt: this.addedAt,
updatedAt: this.updatedAt
}
}
}
module.exports = LibraryFile

View File

@ -0,0 +1,56 @@
class BookMetadata {
constructor(metadata) {
this.title = null
this.subtitle = null
this.authors = []
this.narrators = [] // Array of strings
this.series = []
this.genres = [] // Array of strings
this.publishedYear = null
this.publishedDate = null
this.publisher = null
this.description = null
this.isbn = null
this.asin = null
this.language = null
if (metadata) {
this.construct(metadata)
}
}
construct(metadata) {
this.title = metadata.title
this.subtitle = metadata.subtitle
this.authors = metadata.authors.map(a => ({ ...a }))
this.narrators = [...metadata.narrators]
this.series = metadata.series.map(s => ({ ...s }))
this.genres = [...metadata.genres]
this.publishedYear = metadata.publishedYear
this.publishedDate = metadata.publishedDate
this.publisher = metadata.publisher
this.description = metadata.description
this.isbn = metadata.isbn
this.asin = metadata.asin
this.language = metadata.language
}
toJSON() {
return {
title: this.title,
subtitle: this.subtitle,
authors: this.authors.map(a => ({ ...a })), // Author JSONMinimal with name and id
narrators: [...this.narrators],
series: this.series.map(s => ({ ...s })),
genres: [...this.genres],
publishedYear: this.publishedYear,
publishedDate: this.publishedDate,
publisher: this.publisher,
description: this.description,
isbn: this.isbn,
asin: this.asin,
language: this.language
}
}
}
module.exports = BookMetadata

View File

@ -0,0 +1,41 @@
class FileMetadata {
constructor(metadata) {
this.filename = null
this.ext = null
this.path = null
this.relPath = null
this.size = null
this.mtimeMs = null
this.ctimeMs = null
this.birthtimeMs = null
if (metadata) {
this.construct(metadata)
}
}
construct(metadata) {
this.filename = metadata.filename
this.ext = metadata.ext
this.path = metadata.path
this.relPath = metadata.relPath
this.size = metadata.size
this.mtimeMs = metadata.mtimeMs
this.ctimeMs = metadata.ctimeMs
this.birthtimeMs = metadata.birthtimeMs
}
toJSON() {
return {
filename: this.filename,
ext: this.ext,
path: this.path,
relPath: this.relPath,
size: this.size,
mtimeMs: this.mtimeMs,
ctimeMs: this.ctimeMs,
birthtimeMs: this.birthtimeMs
}
}
}
module.exports = FileMetadata

View File

@ -0,0 +1,44 @@
class PodcastMetadata {
constructor(metadata) {
this.title = null
this.artist = null
this.description = null
this.releaseDate = null
this.genres = []
this.feedUrl = null
this.itunesPageUrl = null
this.itunesId = null
this.itunesArtistId = null
if (metadata) {
this.construct(metadata)
}
}
construct(metadata) {
this.title = metadata.title
this.artist = metadata.artist
this.description = metadata.description
this.releaseDate = metadata.releaseDate
this.genres = [...metadata.genres]
this.feedUrl = metadata.feedUrl
this.itunesPageUrl = metadata.itunesPageUrl
this.itunesId = metadata.itunesId
this.itunesArtistId = metadata.itunesArtistId
}
toJSON() {
return {
title: this.title,
artist: this.artist,
description: this.description,
releaseDate: this.releaseDate,
genres: [...this.genres],
feedUrl: this.feedUrl,
itunesPageUrl: this.itunesPageUrl,
itunesId: this.itunesId,
itunesArtistId: this.itunesArtistId,
}
}
}
module.exports = PodcastMetadata

View File

@ -1,6 +1,6 @@
const Path = require('path') const Path = require('path')
const AudioFile = require('../objects/AudioFile') const AudioFile = require('../objects/files/AudioFile')
const prober = require('../utils/prober') const prober = require('../utils/prober')
const Logger = require('../Logger') const Logger = require('../Logger')

View File

@ -1,4 +1,4 @@
const AudioFileMetadata = require('../objects/AudioFileMetadata') const AudioFileMetadata = require('../objects/metadata/AudioFileMetadata')
class AudioProbeData { class AudioProbeData {
constructor() { constructor() {