Merge branch 'advplyr:master' into master

This commit is contained in:
Rasmus Krämer 2022-04-15 12:22:16 +02:00 committed by GitHub
commit cd5e5099f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 586 additions and 319 deletions

View file

@ -9,7 +9,7 @@ const UserCollection = require('./objects/UserCollection')
const Library = require('./objects/Library')
const Author = require('./objects/entities/Author')
const Series = require('./objects/entities/Series')
const ServerSettings = require('./objects/ServerSettings')
const ServerSettings = require('./objects/settings/ServerSettings')
const PlaybackSession = require('./objects/PlaybackSession')
class Db {

View file

@ -69,19 +69,19 @@ class FolderWatcher extends EventEmitter {
initWatcher(libraries) {
libraries.forEach((lib) => {
if (!lib.disableWatcher) {
if (!lib.settings.disableWatcher) {
this.buildLibraryWatcher(lib)
}
})
}
addLibrary(library) {
if (this.disabled || library.disableWatcher) return
if (this.disabled || library.settings.disableWatcher) return
this.buildLibraryWatcher(library)
}
updateLibrary(library) {
if (this.disabled || library.disableWatcher) return
if (this.disabled || library.settings.disableWatcher) return
var libwatcher = this.libraryWatchers.find(lib => lib.id === library.id)
if (libwatcher) {
libwatcher.name = library.name

View file

@ -1,6 +1,7 @@
const Path = require('path')
const fs = require('fs-extra')
const Logger = require('../Logger')
const filePerms = require('../utils/filePerms')
const { isObject } = require('../utils/index')
@ -37,15 +38,21 @@ class MiscController {
}
// For setting permissions recursively
var firstDirPath = Path.join(folder.fullPath, author)
var outputDirectory = ''
if (series && author) {
outputDirectory = Path.join(folder.fullPath, author, series, title)
} else if (author) {
outputDirectory = Path.join(folder.fullPath, author, title)
} else {
var firstDirPath = ''
if (library.isPodcast) { // Podcasts only in 1 folder
outputDirectory = Path.join(folder.fullPath, title)
firstDirPath = outputDirectory
} else {
firstDirPath = Path.join(folder.fullPath, author)
if (series && author) {
outputDirectory = Path.join(folder.fullPath, author, series, title)
} else if (author) {
outputDirectory = Path.join(folder.fullPath, author, title)
} else {
outputDirectory = Path.join(folder.fullPath, title)
}
}
var exists = await fs.pathExists(outputDirectory)

View file

@ -139,31 +139,30 @@ class PodcastManager {
}
async checkForNewEpisodes() {
var podcastsWithAutoDownload = this.db.libraryItems.find(li => li.mediaType === 'podcast' && li.media.autoDownloadEpisodes)
var podcastsWithAutoDownload = this.db.libraryItems.filter(li => li.mediaType === 'podcast' && li.media.autoDownloadEpisodes)
if (!podcastsWithAutoDownload.length) {
this.cancelCron()
return
}
for (const libraryItem of podcastsWithAutoDownload) {
Logger.info(`[PodcastManager] checkForNewEpisodes Cron for "${libraryItem.media.metadata.title}"`)
const lastEpisodeCheckDate = new Date(libraryItem.media.lastEpisodeCheck || 0)
Logger.info(`[PodcastManager] checkForNewEpisodes Cron for "${libraryItem.media.metadata.title}" - Last episode check: ${lastEpisodeCheckDate}`)
var newEpisodes = await this.checkPodcastForNewEpisodes(libraryItem)
var hasUpdates = false
if (!newEpisodes) { // Failed
libraryItem.media.autoDownloadEpisodes = false
hasUpdates = true
} else if (newEpisodes.length) {
Logger.info(`[PodcastManager] Found ${newEpisodes.length} new episodes for podcast "${libraryItem.media.metadata.title}" - starting download`)
this.downloadPodcastEpisodes(libraryItem, newEpisodes)
hasUpdates = true
} else {
Logger.debug(`[PodcastManager] No new episodes for "${libraryItem.media.metadata.title}"`)
}
if (hasUpdates) {
libraryItem.media.lastEpisodeCheck = Date.now()
libraryItem.updatedAt = Date.now()
await this.db.updateLibraryItem(libraryItem)
this.emitter('item_updated', libraryItem.toJSONExpanded())
}
libraryItem.media.lastEpisodeCheck = Date.now()
libraryItem.updatedAt = Date.now()
await this.db.updateLibraryItem(libraryItem)
this.emitter('item_updated', libraryItem.toJSONExpanded())
}
}

View file

@ -1,4 +1,5 @@
const Folder = require('./Folder')
const LibrarySettings = require('./settings/LibrarySettings')
const { getId } = require('../utils/index')
class Library {
@ -10,9 +11,9 @@ class Library {
this.icon = 'database' // database, podcast, book, audiobook, comic
this.mediaType = 'book' // book, podcast
this.provider = 'google'
this.disableWatcher = false
this.lastScan = 0
this.settings = null
this.createdAt = null
this.lastUpdate = null
@ -25,6 +26,9 @@ class Library {
get folderPaths() {
return this.folders.map(f => f.fullPath)
}
get isPodcast() {
return this.mediaType === 'podcast'
}
construct(library) {
this.id = library.id
@ -34,7 +38,11 @@ class Library {
this.icon = library.icon || 'database'
this.mediaType = library.mediaType
this.provider = library.provider || 'google'
this.disableWatcher = !!library.disableWatcher
this.settings = new LibrarySettings(library.settings)
if (library.settings === undefined) { // LibrarySettings added in v2, migrate settings
this.settings.disableWatcher = !!library.disableWatcher
}
this.createdAt = library.createdAt
this.lastUpdate = library.lastUpdate
@ -62,7 +70,7 @@ class Library {
icon: this.icon,
mediaType: this.mediaType,
provider: this.provider,
disableWatcher: this.disableWatcher,
settings: this.settings.toJSON(),
createdAt: this.createdAt,
lastUpdate: this.lastUpdate
}
@ -89,7 +97,7 @@ class Library {
this.icon = data.icon || 'database'
this.mediaType = data.mediaType || 'book'
this.provider = data.provider || 'google'
this.disableWatcher = !!data.disableWatcher
this.settings = new LibrarySettings(data.settings)
this.createdAt = Date.now()
this.lastUpdate = Date.now()
}
@ -105,10 +113,10 @@ class Library {
}
})
if (payload.disableWatcher !== this.disableWatcher) {
this.disableWatcher = !!payload.disableWatcher
if (payload.settings && this.settings.update(payload.settings)) {
hasUpdates = true
}
if (!isNaN(payload.displayOrder) && payload.displayOrder !== this.displayOrder) {
this.displayOrder = Number(payload.displayOrder)
hasUpdates = true

View file

@ -0,0 +1,34 @@
const { BookCoverAspectRatio } = require('../../utils/constants')
const Logger = require('../../Logger')
class LibrarySettings {
constructor(settings) {
this.disableWatcher = false
if (settings) {
this.construct(settings)
}
}
construct(settings) {
this.disableWatcher = !!settings.disableWatcher
}
toJSON() {
return {
disableWatcher: this.disableWatcher
}
}
update(payload) {
var hasUpdates = false
for (const key in payload) {
if (this[key] !== payload[key]) {
this[key] = payload[key]
hasUpdates = true
}
}
return hasUpdates
}
}
module.exports = LibrarySettings

View file

@ -1,5 +1,5 @@
const { BookCoverAspectRatio, BookshelfView } = require('../utils/constants')
const Logger = require('../Logger')
const { BookCoverAspectRatio, BookshelfView } = require('../../utils/constants')
const Logger = require('../../Logger')
class ServerSettings {
constructor(settings) {