Casvt / Kapowarr

Kapowarr is a software to build and manage a comic book library, fitting in the *arr suite of software.
https://casvt.github.io/Kapowarr/
GNU General Public License v3.0
420 stars 14 forks source link

Support for exporting metadata #50

Open winterborn opened 1 year ago

winterborn commented 1 year ago

When a new series is added to the user's library, a series.json or ComicInfo.xml file should be generated for use in Komga to provide additional metadata about the comics. This would be useful if the book itself does not have this metadata embedded.

Currently, if a specific book does not have metadata embedded nor an external metadata file, no additional metadata for the series / volume / arc etc is shown in Komga.

FaNt4zMa commented 1 year ago

I second this. Komga can't find a poster automatically, it would be nice if it could export the jpg too.

winterborn commented 1 year ago

I may see if I can take a crack at doing this... I will need to check my availability over the next few weeks, but I'll see what I can do for sure.

Casvt commented 1 year ago

If you want to contribute, I have some suggestions/guidance:

  1. Make it an option to automatically do this after downloading in the settings, at Settings -> Media Management (similar to the unzipping setting).
  2. Have a button in the volume view that triggers Kapowarr to do this for a whole volume, regardless of the setting (similar to unzipping).
  3. If you're going to support multiple formats (series.json, ComicInfo.xml, etc.), make an option in the settings for which format is desired.
  4. If a metadata file already exists, it should be updated (basically just delete contents of current file and insert new contents).
  5. The whole file handling (creating file, checking if one exists, writing to it, etc.) should be cross-platform supported (os.path and shutil do most of the work) and should have proper error handling and safety measures built-in (especially if you're going to delete files).
  6. If you want to go all in on implementing it, also trigger metadata exporting when the metadata of the volume/issue is changed after refresh and scan.

Suggestions for how to implement this:

  1. Have a function that acts as an entry point for the feature. volume_id is a required parameter and file is optional, if you want to only process a specific file instead of the whole volume.
  2. Create a task that runs the function with just the volume_id, and the button in the web-ui triggers this task.
  3. If the setting is enabled, post-processing runs the function with also the file supplied.
  4. Inside the function, a list of files is made that need to be processed. If file is supplied, it's just a list with that but otherwise a list with all files of the volume.
  5. Then, inside a for loop, process each file one by one.
  6. Gather all needed metadata and build the content of the file in the format desired.
  7. Generate the location and name of the file. Create the file if it doesn't exist yet, empty it if it does exist.
  8. Fill it with the generated content.

The general structure of the implementation is similar to how unzipping is implemented, so you can check that out.

winterborn commented 1 year ago

Made some initial research progress on this...

It turns out that in order to generate a series.json file for Komga to read properly, the formatting has to be very strict, as per Mylar's guidelines:

Example: Print series with Continuing Status

{
    "metadata": {
        "type": "comicSeries",
        "publisher": "DC Comics",
        "imprint": null,
        "name": "Batman/Fortnite: Zero Point",
        "comicid": 135499,
        "year": 2021,
        "description_text": "Six issue crossover mini-series",
        "description_formatted": null,
        "volume": null,
        "booktype": "Print",
        "collects": null,
        "ComicImage": "https://comicvine.gamespot.com/a/uploads/scale_large/6/67663/7921530-01.jpg",
        "total_issues": 1,
        "publication_run": "June 2021 - Present",
        "status": "Continuing"
    }
}

I have experimented locally to see if my custom series.json files are properly picked up by Komga, which they are, but the metadata is quite limited... It does not seem to properly pass on information about specific issues, or include artist names, colourists, writers etc.

The alternative, is to make use of an embedded ComicInfo.xml, which I believe Mylar achieves through their Comictagger functionality.

Will need to do further investigation to see how this works and what could be ported to Kapowarr... it certainly seems like the better way to do it, grabbing more, rich metadata than the series.json can handle...

Casvt commented 1 year ago

Just a heads up:

You'll have to map the generated metadata files to the volume so that they're handled correctly. However, there is no way to map files to the volume in general without mapping it to issues. That's going to be a problem for you because metadata and cover files are exactly that. I'm going to fix that in issue #79.

It's advised to wait with mapping these metadata files until I've fixed that issue, so that you can make use of it.