Merge pull request #4226 from Vito0912/feat/chapterLookUp

Changes to Chapter-Lookup
This commit is contained in:
advplyr 2025-05-10 16:54:33 -05:00 committed by GitHub
commit 659c671c25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 10 deletions

View File

@ -144,17 +144,18 @@
<div v-if="!chapterData" class="flex flex-col items-center justify-center p-20"> <div v-if="!chapterData" class="flex flex-col items-center justify-center p-20">
<div class="relative"> <div class="relative">
<div class="flex items-end space-x-2"> <div class="flex items-end space-x-2">
<ui-text-input-with-label v-model.trim="asinInput" label="ASIN" /> <ui-text-input-with-label v-model.trim="asinInput" label="ASIN" class="flex-grow" />
<ui-dropdown v-model="regionInput" :label="$strings.LabelRegion" small :items="audibleRegions" class="w-32" /> <ui-dropdown v-model="regionInput" :label="$strings.LabelRegion" small :items="audibleRegions" class="w-20 max-w-20" />
<ui-btn small color="bg-primary" @click="findChapters">{{ $strings.ButtonSearch }}</ui-btn> <ui-btn color="bg-primary" @click="findChapters">{{ $strings.ButtonSearch }}</ui-btn>
</div>
<div class="mt-4">
<ui-checkbox v-model="removeBranding" :label="$strings.LabelRemoveAudibleBranding" small checkbox-bg="bg" label-class="pl-2 text-base text-sm" @click="toggleRemoveBranding" />
</div> </div>
<div class="absolute left-0 mt-1.5 text-error text-s h-5"> <div class="absolute left-0 mt-1.5 text-error text-s h-5">
<p v-if="asinError">{{ asinError }}</p> <p v-if="asinError">{{ asinError }}</p>
<p v-if="asinError">{{ $strings.MessageAsinCheck }}</p> <p v-if="asinError">{{ $strings.MessageAsinCheck }}</p>
</div> </div>
<div class="invisible mt-1 text-xs"></div>
<div class="invisible h-5 mt-1 text-xs"></div>
</div> </div>
</div> </div>
<div v-else class="w-full p-4"> <div v-else class="w-full p-4">
@ -261,6 +262,7 @@ export default {
showFindChaptersModal: false, showFindChaptersModal: false,
chapterData: null, chapterData: null,
asinError: null, asinError: null,
removeBranding: false,
showSecondInputs: false, showSecondInputs: false,
audibleRegions: ['US', 'CA', 'UK', 'AU', 'FR', 'DE', 'JP', 'IT', 'IN', 'ES'], audibleRegions: ['US', 'CA', 'UK', 'AU', 'FR', 'DE', 'JP', 'IT', 'IN', 'ES'],
hasChanges: false hasChanges: false
@ -322,6 +324,9 @@ export default {
this.checkChapters() this.checkChapters()
}, },
toggleRemoveBranding() {
this.removeBranding = !this.removeBranding
},
shiftChapterTimes() { shiftChapterTimes() {
if (!this.shiftAmount || isNaN(this.shiftAmount) || this.newChapters.length <= 1) { if (!this.shiftAmount || isNaN(this.shiftAmount) || this.newChapters.length <= 1) {
return return
@ -331,12 +336,12 @@ export default {
const lastChapter = this.newChapters[this.newChapters.length - 1] const lastChapter = this.newChapters[this.newChapters.length - 1]
if (lastChapter.start + amount > this.mediaDurationRounded) { if (lastChapter.start + amount > this.mediaDurationRounded) {
this.$toast.error('Invalid shift amount. Last chapter start time would extend beyond the duration of this audiobook.') this.$toast.error(this.$strings.ToastChaptersInvalidShiftAmountLast)
return return
} }
if (this.newChapters[0].end + amount <= 0) { if (this.newChapters[1].start + amount <= 0) {
this.$toast.error('Invalid shift amount. First chapter would have zero or negative length.') this.$toast.error(this.$strings.ToastChaptersInvalidShiftAmountStart)
return return
} }
@ -568,7 +573,7 @@ export default {
this.asinError = this.$getString(data.stringKey) this.asinError = this.$getString(data.stringKey)
} else { } else {
console.log('Chapter data', data) console.log('Chapter data', data)
this.chapterData = data this.chapterData = this.removeBranding ? this.removeBrandingFromData(data) : data
} }
}) })
.catch((error) => { .catch((error) => {
@ -578,6 +583,37 @@ export default {
this.showFindChaptersModal = false this.showFindChaptersModal = false
}) })
}, },
removeBrandingFromData(data) {
if (!data) return data
try {
const introDuration = data.brandIntroDurationMs
const outroDuration = data.brandOutroDurationMs
for (let i = 0; i < data.chapters.length; i++) {
const chapter = data.chapters[i]
if (chapter.startOffsetMs < introDuration) {
// This should never happen, as the intro is not longer than the first chapter
// If this happens set to the next second
// Will be 0 for the first chapter anayways
chapter.startOffsetMs = i * 1000
chapter.startOffsetSec = i
} else {
chapter.startOffsetMs -= introDuration
chapter.startOffsetSec = Math.floor(chapter.startOffsetMs / 1000)
}
}
const lastChapter = data.chapters[data.chapters.length - 1]
// If there is an outro that's in the outro duration, remove it
if (lastChapter && lastChapter.lengthMs <= outroDuration) {
data.chapters.pop()
}
return data
} catch {
return data
}
},
resetChapters() { resetChapters() {
const payload = { const payload = {
message: this.$strings.MessageResetChaptersConfirm, message: this.$strings.MessageResetChaptersConfirm,

View File

@ -531,6 +531,7 @@
"LabelReleaseDate": "Release Date", "LabelReleaseDate": "Release Date",
"LabelRemoveAllMetadataAbs": "Remove all metadata.abs files", "LabelRemoveAllMetadataAbs": "Remove all metadata.abs files",
"LabelRemoveAllMetadataJson": "Remove all metadata.json files", "LabelRemoveAllMetadataJson": "Remove all metadata.json files",
"LabelRemoveAudibleBranding": "Remove Audible intro and outro from chapters",
"LabelRemoveCover": "Remove cover", "LabelRemoveCover": "Remove cover",
"LabelRemoveMetadataFile": "Remove metadata files in library item folders", "LabelRemoveMetadataFile": "Remove metadata files in library item folders",
"LabelRemoveMetadataFileHelp": "Remove all metadata.json and metadata.abs files in your {0} folders.", "LabelRemoveMetadataFileHelp": "Remove all metadata.json and metadata.abs files in your {0} folders.",
@ -972,6 +973,8 @@
"ToastCachePurgeFailed": "Failed to purge cache", "ToastCachePurgeFailed": "Failed to purge cache",
"ToastCachePurgeSuccess": "Cache purged successfully", "ToastCachePurgeSuccess": "Cache purged successfully",
"ToastChaptersHaveErrors": "Chapters have errors", "ToastChaptersHaveErrors": "Chapters have errors",
"ToastChaptersInvalidShiftAmountLast": "Invalid shift amount. The last chapter start time would extend beyond the duration of this audiobook.",
"ToastChaptersInvalidShiftAmountStart": "Invalid shift amount. The first chapter would have zero or negative length and would be overwritten by the second chapter. Increase the start duration of second chapter.",
"ToastChaptersMustHaveTitles": "Chapters must have titles", "ToastChaptersMustHaveTitles": "Chapters must have titles",
"ToastChaptersRemoved": "Chapters removed", "ToastChaptersRemoved": "Chapters removed",
"ToastChaptersUpdated": "Chapters updated", "ToastChaptersUpdated": "Chapters updated",