mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-21 02:41:30 +00:00
Remove autoGenerateChapters flag, migration and version bump
This commit is contained in:
parent
0227302fc0
commit
8710816a6f
8 changed files with 6 additions and 167 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "audiobookshelf-client",
|
"name": "audiobookshelf-client",
|
||||||
"version": "2.34.0",
|
"version": "2.33.0",
|
||||||
"buildNumber": 1,
|
"buildNumber": 1,
|
||||||
"description": "Self-hosted audiobook and podcast client",
|
"description": "Self-hosted audiobook and podcast client",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "audiobookshelf",
|
"name": "audiobookshelf",
|
||||||
"version": "2.34.0",
|
"version": "2.33.0",
|
||||||
"buildNumber": 1,
|
"buildNumber": 1,
|
||||||
"description": "Self-hosted audiobook and podcast server",
|
"description": "Self-hosted audiobook and podcast server",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ class PodcastManager {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const podcastEpisode = await Database.podcastEpisodeModel.createFromRssPodcastEpisode(this.currentDownload.rssPodcastEpisode, libraryItem.media.id, libraryItem.media.autoGenerateChapters, audioFile)
|
const podcastEpisode = await Database.podcastEpisodeModel.createFromRssPodcastEpisode(this.currentDownload.rssPodcastEpisode, libraryItem.media.id, audioFile)
|
||||||
|
|
||||||
libraryItem.libraryFiles.push(libraryFile.toJSON())
|
libraryItem.libraryFiles.push(libraryFile.toJSON())
|
||||||
// Re-calculating library item size because this wasnt being updated properly for podcasts in v2.20.0 and below
|
// Re-calculating library item size because this wasnt being updated properly for podcasts in v2.20.0 and below
|
||||||
|
|
|
||||||
|
|
@ -1,83 +0,0 @@
|
||||||
const util = require('util')
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef MigrationContext
|
|
||||||
* @property {import('sequelize').QueryInterface} queryInterface - a suquelize QueryInterface object.
|
|
||||||
* @property {import('../Logger')} logger - a Logger object.
|
|
||||||
*
|
|
||||||
* @typedef MigrationOptions
|
|
||||||
* @property {MigrationContext} context - an object containing the migration context.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const migrationVersion = '2.34.0'
|
|
||||||
const migrationName = `${migrationVersion}-add-auto-generate-podcast-chapters`
|
|
||||||
const loggerPrefix = `[${migrationVersion} migration]`
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This upward migration adds a boolean autoGenerateChapters column to the podcasts table and defaults it to false.
|
|
||||||
*
|
|
||||||
* @param {MigrationOptions} options - an object containing the migration context.
|
|
||||||
* @returns {Promise<void>} - A promise that resolves when the migration is complete.
|
|
||||||
*/
|
|
||||||
async function up({ context: { queryInterface, logger } }) {
|
|
||||||
logger.info(`${loggerPrefix} UPGRADE BEGIN: ${migrationName}`)
|
|
||||||
|
|
||||||
await addColumn(queryInterface, logger, 'podcasts', 'autoGenerateChapters', { type: queryInterface.sequelize.Sequelize.BOOLEAN, allowNull: false, defaultValue: false })
|
|
||||||
|
|
||||||
logger.info(`${loggerPrefix} UPGRADE END: ${migrationName}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This downward migration removes the autoGenerateChapters column on the podcasts table,
|
|
||||||
*
|
|
||||||
* @param {MigrationOptions} options - an object containing the migration context.
|
|
||||||
* @returns {Promise<void>} - A promise that resolves when the migration is complete.
|
|
||||||
*/
|
|
||||||
async function down({ context: { queryInterface, logger } }) {
|
|
||||||
logger.info(`${loggerPrefix} DOWNGRADE BEGIN: ${migrationName}`)
|
|
||||||
|
|
||||||
await removeColumn(queryInterface, logger, 'podcasts', 'autoGenerateChapters')
|
|
||||||
|
|
||||||
logger.info(`${loggerPrefix} DOWNGRADE END: ${migrationName}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility function to add a column to a table. If the column already exists, it logs a message and continues.
|
|
||||||
*
|
|
||||||
* @param {import('sequelize').QueryInterface} queryInterface - a suquelize QueryInterface object.
|
|
||||||
* @param {import('../Logger')} logger - a Logger object.
|
|
||||||
* @param {string} table - the name of the table to add the column to.
|
|
||||||
* @param {string} column - the name of the column to add.
|
|
||||||
* @param {Object} options - the options for the column.
|
|
||||||
*/
|
|
||||||
async function addColumn(queryInterface, logger, table, column, options) {
|
|
||||||
logger.info(`${loggerPrefix} adding column "${column}" to table "${table}"`)
|
|
||||||
const tableDescription = await queryInterface.describeTable(table)
|
|
||||||
if (!tableDescription[column]) {
|
|
||||||
await queryInterface.addColumn(table, column, options)
|
|
||||||
logger.info(`${loggerPrefix} added column "${column}" to table "${table}"`)
|
|
||||||
} else {
|
|
||||||
logger.info(`${loggerPrefix} column "${column}" already exists in table "${table}"`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility function to remove a column from a table. If the column does not exist, it logs a message and continues.
|
|
||||||
*
|
|
||||||
* @param {import('sequelize').QueryInterface} queryInterface - a suquelize QueryInterface object.
|
|
||||||
* @param {import('../Logger')} logger - a Logger object.
|
|
||||||
* @param {string} table - the name of the table to remove the column from.
|
|
||||||
* @param {string} column - the name of the column to remove.
|
|
||||||
*/
|
|
||||||
async function removeColumn(queryInterface, logger, table, column) {
|
|
||||||
logger.info(`${loggerPrefix} removing column "${column}" from table "${table}"`)
|
|
||||||
const tableDescription = await queryInterface.describeTable(table)
|
|
||||||
if (tableDescription[column]) {
|
|
||||||
await queryInterface.sequelize.query(`ALTER TABLE ${table} DROP COLUMN ${column}`)
|
|
||||||
logger.info(`${loggerPrefix} removed column "${column}" from table "${table}"`)
|
|
||||||
} else {
|
|
||||||
logger.info(`${loggerPrefix} column "${column}" does not exist in table "${table}"`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { up, down }
|
|
||||||
|
|
@ -53,8 +53,6 @@ class Podcast extends Model {
|
||||||
this.maxEpisodesToKeep
|
this.maxEpisodesToKeep
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
this.maxNewEpisodesToDownload
|
this.maxNewEpisodesToDownload
|
||||||
/** @type {boolean} */
|
|
||||||
this.autoGenerateChapters
|
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
this.coverPath
|
this.coverPath
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
|
|
@ -108,7 +106,6 @@ class Podcast extends Model {
|
||||||
explicit: !!payload.metadata.explicit,
|
explicit: !!payload.metadata.explicit,
|
||||||
autoDownloadEpisodes: !!payload.autoDownloadEpisodes,
|
autoDownloadEpisodes: !!payload.autoDownloadEpisodes,
|
||||||
autoDownloadSchedule: autoDownloadSchedule || global.ServerSettings.podcastEpisodeSchedule,
|
autoDownloadSchedule: autoDownloadSchedule || global.ServerSettings.podcastEpisodeSchedule,
|
||||||
autoGenerateChapters: !!payload.autoGenerateChapters,
|
|
||||||
lastEpisodeCheck: new Date(),
|
lastEpisodeCheck: new Date(),
|
||||||
maxEpisodesToKeep: 0,
|
maxEpisodesToKeep: 0,
|
||||||
maxNewEpisodesToDownload: 3,
|
maxNewEpisodesToDownload: 3,
|
||||||
|
|
@ -148,7 +145,6 @@ class Podcast extends Model {
|
||||||
autoDownloadEpisodes: DataTypes.BOOLEAN,
|
autoDownloadEpisodes: DataTypes.BOOLEAN,
|
||||||
autoDownloadSchedule: DataTypes.STRING,
|
autoDownloadSchedule: DataTypes.STRING,
|
||||||
lastEpisodeCheck: DataTypes.DATE,
|
lastEpisodeCheck: DataTypes.DATE,
|
||||||
autoGenerateChapters: DataTypes.BOOLEAN,
|
|
||||||
maxEpisodesToKeep: DataTypes.INTEGER,
|
maxEpisodesToKeep: DataTypes.INTEGER,
|
||||||
maxNewEpisodesToDownload: DataTypes.INTEGER,
|
maxNewEpisodesToDownload: DataTypes.INTEGER,
|
||||||
coverPath: DataTypes.STRING,
|
coverPath: DataTypes.STRING,
|
||||||
|
|
@ -277,10 +273,6 @@ class Podcast extends Model {
|
||||||
this.autoDownloadSchedule = payload.autoDownloadSchedule
|
this.autoDownloadSchedule = payload.autoDownloadSchedule
|
||||||
hasUpdates = true
|
hasUpdates = true
|
||||||
}
|
}
|
||||||
if (payload.autoGenerateChapters !== undefined && payload.autoGenerateChapters !== this.autoGenerateChapters) {
|
|
||||||
this.autoGenerateChapters = !!payload.autoGenerateChapters
|
|
||||||
hasUpdates = true
|
|
||||||
}
|
|
||||||
if (typeof payload.lastEpisodeCheck === 'number' && payload.lastEpisodeCheck !== this.lastEpisodeCheck?.valueOf()) {
|
if (typeof payload.lastEpisodeCheck === 'number' && payload.lastEpisodeCheck !== this.lastEpisodeCheck?.valueOf()) {
|
||||||
this.lastEpisodeCheck = payload.lastEpisodeCheck
|
this.lastEpisodeCheck = payload.lastEpisodeCheck
|
||||||
hasUpdates = true
|
hasUpdates = true
|
||||||
|
|
@ -449,7 +441,6 @@ class Podcast extends Model {
|
||||||
autoDownloadEpisodes: this.autoDownloadEpisodes,
|
autoDownloadEpisodes: this.autoDownloadEpisodes,
|
||||||
autoDownloadSchedule: this.autoDownloadSchedule,
|
autoDownloadSchedule: this.autoDownloadSchedule,
|
||||||
lastEpisodeCheck: this.lastEpisodeCheck?.valueOf() || null,
|
lastEpisodeCheck: this.lastEpisodeCheck?.valueOf() || null,
|
||||||
autoGenerateChapters: this.autoGenerateChapters,
|
|
||||||
maxEpisodesToKeep: this.maxEpisodesToKeep,
|
maxEpisodesToKeep: this.maxEpisodesToKeep,
|
||||||
maxNewEpisodesToDownload: this.maxNewEpisodesToDownload
|
maxNewEpisodesToDownload: this.maxNewEpisodesToDownload
|
||||||
}
|
}
|
||||||
|
|
@ -466,7 +457,6 @@ class Podcast extends Model {
|
||||||
autoDownloadEpisodes: this.autoDownloadEpisodes,
|
autoDownloadEpisodes: this.autoDownloadEpisodes,
|
||||||
autoDownloadSchedule: this.autoDownloadSchedule,
|
autoDownloadSchedule: this.autoDownloadSchedule,
|
||||||
lastEpisodeCheck: this.lastEpisodeCheck?.valueOf() || null,
|
lastEpisodeCheck: this.lastEpisodeCheck?.valueOf() || null,
|
||||||
autoGenerateChapters: this.autoGenerateChapters,
|
|
||||||
maxEpisodesToKeep: this.maxEpisodesToKeep,
|
maxEpisodesToKeep: this.maxEpisodesToKeep,
|
||||||
maxNewEpisodesToDownload: this.maxNewEpisodesToDownload,
|
maxNewEpisodesToDownload: this.maxNewEpisodesToDownload,
|
||||||
size: this.size
|
size: this.size
|
||||||
|
|
@ -491,7 +481,6 @@ class Podcast extends Model {
|
||||||
autoDownloadEpisodes: this.autoDownloadEpisodes,
|
autoDownloadEpisodes: this.autoDownloadEpisodes,
|
||||||
autoDownloadSchedule: this.autoDownloadSchedule,
|
autoDownloadSchedule: this.autoDownloadSchedule,
|
||||||
lastEpisodeCheck: this.lastEpisodeCheck?.valueOf() || null,
|
lastEpisodeCheck: this.lastEpisodeCheck?.valueOf() || null,
|
||||||
autoGenerateChapters: this.autoGenerateChapters,
|
|
||||||
maxEpisodesToKeep: this.maxEpisodesToKeep,
|
maxEpisodesToKeep: this.maxEpisodesToKeep,
|
||||||
maxNewEpisodesToDownload: this.maxNewEpisodesToDownload,
|
maxNewEpisodesToDownload: this.maxNewEpisodesToDownload,
|
||||||
size: this.size
|
size: this.size
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,9 @@ class PodcastEpisode extends Model {
|
||||||
*
|
*
|
||||||
* @param {import('../utils/podcastUtils').RssPodcastEpisode} rssPodcastEpisode
|
* @param {import('../utils/podcastUtils').RssPodcastEpisode} rssPodcastEpisode
|
||||||
* @param {string} podcastId
|
* @param {string} podcastId
|
||||||
* @param {boolean} autoGenerateChapters
|
|
||||||
* @param {import('../objects/files/AudioFile')} audioFile
|
* @param {import('../objects/files/AudioFile')} audioFile
|
||||||
*/
|
*/
|
||||||
static async createFromRssPodcastEpisode(rssPodcastEpisode, podcastId, autoGenerateChapters, audioFile) {
|
static async createFromRssPodcastEpisode(rssPodcastEpisode, podcastId, audioFile) {
|
||||||
const podcastEpisode = {
|
const podcastEpisode = {
|
||||||
index: null,
|
index: null,
|
||||||
season: rssPodcastEpisode.season,
|
season: rssPodcastEpisode.season,
|
||||||
|
|
@ -88,8 +87,8 @@ class PodcastEpisode extends Model {
|
||||||
podcastEpisode.chapters = audioFile.chapters.map((ch) => ({ ...ch }))
|
podcastEpisode.chapters = audioFile.chapters.map((ch) => ({ ...ch }))
|
||||||
} else if (rssPodcastEpisode.chapters?.length) {
|
} else if (rssPodcastEpisode.chapters?.length) {
|
||||||
podcastEpisode.chapters = rssPodcastEpisode.chapters.map((ch) => ({ ...ch }))
|
podcastEpisode.chapters = rssPodcastEpisode.chapters.map((ch) => ({ ...ch }))
|
||||||
} else if (autoGenerateChapters) {
|
} else {
|
||||||
Logger.info("[PodcastEpisode] New episode doesn't have chapters, attempting to generate them from timestamps", rssPodcastEpisode.title)
|
Logger.debug("[PodcastEpisode] New episode doesn't have chapters, attempting to generate them from timestamps", rssPodcastEpisode.title)
|
||||||
try {
|
try {
|
||||||
podcastEpisode.chapters = parsePodcastDescriptionForChapters.parse(podcastEpisode.description, podcastEpisode.audioFile.duration)
|
podcastEpisode.chapters = parsePodcastDescriptionForChapters.parse(podcastEpisode.description, podcastEpisode.audioFile.duration)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,6 @@ module.exports.parse = (podcastDescription, audioDurationSecs) => {
|
||||||
throw new Error('Audio duration must not be null')
|
throw new Error('Audio duration must not be null')
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.info('Description!', podcastDescription)
|
|
||||||
|
|
||||||
// This number is arbitrary, but there have been examples where descriptions of the chapter are on the same line as the chapter title
|
// This number is arbitrary, but there have been examples where descriptions of the chapter are on the same line as the chapter title
|
||||||
// This results in a unpleasant UX where the chapter is very long, it's also possible that an overly long chapter title is the result of a parsing failure
|
// This results in a unpleasant UX where the chapter is very long, it's also possible that an overly long chapter title is the result of a parsing failure
|
||||||
const maxChapterTitleLength = 200
|
const maxChapterTitleLength = 200
|
||||||
|
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
const chai = require('chai')
|
|
||||||
const sinon = require('sinon')
|
|
||||||
const { expect } = chai
|
|
||||||
|
|
||||||
const { DataTypes, Sequelize } = require('sequelize')
|
|
||||||
const Logger = require('../../../server/Logger')
|
|
||||||
|
|
||||||
const { up, down } = require('../../../server/migrations/v2.34.0-add-auto-generate-podcast-chapters')
|
|
||||||
|
|
||||||
describe('Migration v2.34.0-add-auto-generate-podcast-chapters', () => {
|
|
||||||
let sequelize
|
|
||||||
let queryInterface
|
|
||||||
let loggerInfoStub
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
sequelize = new Sequelize({ dialect: 'sqlite', storage: ':memory:', logging: false })
|
|
||||||
queryInterface = sequelize.getQueryInterface()
|
|
||||||
loggerInfoStub = sinon.stub(Logger, 'info')
|
|
||||||
|
|
||||||
await queryInterface.createTable('podcasts', {
|
|
||||||
id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, unique: true },
|
|
||||||
title: { type: DataTypes.STRING, allowNull: false },
|
|
||||||
titleIgnorePrefix: { type: DataTypes.STRING, allowNull: false }
|
|
||||||
})
|
|
||||||
|
|
||||||
await queryInterface.bulkInsert('podcasts', [
|
|
||||||
{ id: 1, title: 'The Podcast 1', titleIgnorePrefix: 'Podcast 1, The' },
|
|
||||||
{ id: 2, title: 'The Podcast 2', titleIgnorePrefix: 'Podcast 2, The' }
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
sinon.restore()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('up', () => {
|
|
||||||
it('should add autoGenerateChapters column to podcasts', async () => {
|
|
||||||
await up({ context: { queryInterface, logger: Logger } })
|
|
||||||
|
|
||||||
const [podcasts] = await queryInterface.sequelize.query('SELECT * FROM podcasts')
|
|
||||||
expect(podcasts).to.deep.equal([
|
|
||||||
{ id: 1, autoGenerateChapters: 0, title: 'The Podcast 1', titleIgnorePrefix: 'Podcast 1, The' },
|
|
||||||
{ id: 2, autoGenerateChapters: 0, title: 'The Podcast 2', titleIgnorePrefix: 'Podcast 2, The' }
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('down', () => {
|
|
||||||
it('should remove autoGenerateChapters column from podcasts', async () => {
|
|
||||||
await up({ context: { queryInterface, logger: Logger } })
|
|
||||||
try {
|
|
||||||
await down({ context: { queryInterface, logger: Logger } })
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
const [podcasts] = await queryInterface.sequelize.query('SELECT * FROM podcasts')
|
|
||||||
expect(podcasts).to.deep.equal([
|
|
||||||
{ id: 1, title: 'The Podcast 1', titleIgnorePrefix: 'Podcast 1, The' },
|
|
||||||
{ id: 2, title: 'The Podcast 2', titleIgnorePrefix: 'Podcast 2, The' }
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue