[Enhancement]: Prefer cover.jpg if available #888

Closed
opened 2026-04-24 23:25:07 +02:00 by adam · 4 comments
Owner

Originally created by @ceramicwhite on GitHub (Jan 12, 2023).

If a title added has a 'Book Title.jpg' & a 'cover.jpg' with Store covers with item: On, prefer cover.jpg first as that is the one the user likely chose to update the book with.

Originally created by @ceramicwhite on GitHub (Jan 12, 2023). If a title added has a `'Book Title.jpg'` & a `'cover.jpg'` with `Store covers with item: On`, prefer cover.jpg first as that is the one the user likely chose to update the book with.
adam added the enhancement label 2026-04-24 23:25:07 +02:00
adam closed this issue 2026-04-24 23:25:08 +02:00
Author
Owner

@rosystain commented on GitHub (Jan 13, 2023):

I have the same problem.
If there are some pictures be along with 'cover.jpg', ABS may not choose the 'cover.jpg' as its cover sometimes.

@rosystain commented on GitHub (Jan 13, 2023): I have the same problem. If there are some pictures be along with `'cover.jpg'`, ABS may not choose the `'cover.jpg'` as its cover sometimes.
Author
Owner

@Linden-Ryuujin commented on GitHub (Feb 20, 2023):

It might take me a little time to get code checked out and ready to submit a pull request, but I've run into this issue as well and had a play around with jSFiddler. A starter fix would something like this:

https://github.com/advplyr/audiobookshelf/blob/master/server/objects/LibraryItem.js#L445

    // Set cover image if not set
    const imageFiles = this.libraryFiles.filter(lf => lf.fileType === 'image')
    if (imageFiles.length && !this.media.coverPath) {
      this.media.coverPath = (imageFiles.find(iFile => /\/cover\.[^.\/]*$/.test(iFile.metadata.path)))
      if (!this.media.coverPath) {
	 this.media.coverPath= imageFiles[0].metadata.path
      }
      Logger.debug('[LibraryItem] Set media cover path', this.media.coverPath)
      hasUpdated = true
    }

Long term it might be good to have it controlled by a setting, but this would return the first image file named cover with any extension I think, and then fallback to the current behaviour if that fails. If anyone else is already looking at this, feel free to steal that as a starting point.

@Linden-Ryuujin commented on GitHub (Feb 20, 2023): It might take me a little time to get code checked out and ready to submit a pull request, but I've run into this issue as well and had a play around with jSFiddler. A starter fix would something like this: https://github.com/advplyr/audiobookshelf/blob/master/server/objects/LibraryItem.js#L445 ```js // Set cover image if not set const imageFiles = this.libraryFiles.filter(lf => lf.fileType === 'image') if (imageFiles.length && !this.media.coverPath) { this.media.coverPath = (imageFiles.find(iFile => /\/cover\.[^.\/]*$/.test(iFile.metadata.path))) if (!this.media.coverPath) { this.media.coverPath= imageFiles[0].metadata.path } Logger.debug('[LibraryItem] Set media cover path', this.media.coverPath) hasUpdated = true } ``` Long term it might be good to have it controlled by a setting, but this would return the first image file named `cover` with any extension I think, and then fallback to the current behaviour if that fails. If anyone else is already looking at this, feel free to steal that as a starting point.
Author
Owner

@ceramicwhite commented on GitHub (Feb 20, 2023):

In the meantime I just ran this from inside /Audiobooks folder to clean up my library.

If cover.jpg exists delete other .jpg, otherwise rename .jpg to cover.jpg

find . -mindepth 2 -type f -name "*.jpg" -exec sh -c '
  for file do
    dir="$(dirname "$file")"
    if [ -e "$dir/cover.jpg" ]; then
      if [ "$file" != "$dir/cover.jpg" ]; then
        rm "$file"
      fi
    else
      mv "$file" "$dir/cover.jpg"
    fi
  done' sh {} +
@ceramicwhite commented on GitHub (Feb 20, 2023): In the meantime I just ran this from inside `/Audiobooks` folder to clean up my library. If cover.jpg exists delete other .jpg, otherwise rename .jpg to cover.jpg ``` find . -mindepth 2 -type f -name "*.jpg" -exec sh -c ' for file do dir="$(dirname "$file")" if [ -e "$dir/cover.jpg" ]; then if [ "$file" != "$dir/cover.jpg" ]; then rm "$file" fi else mv "$file" "$dir/cover.jpg" fi done' sh {} + ```
Author
Owner

@advplyr commented on GitHub (Mar 6, 2023):

Updated in v2.2.16

@advplyr commented on GitHub (Mar 6, 2023): Updated in [v2.2.16](https://github.com/advplyr/audiobookshelf/releases/tag/v2.2.16)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#888