aboutsummaryrefslogtreecommitdiff
path: root/cli/library/command.py
blob: 1c4d20ca9e589bbbd5c74557684bd5865084b0ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import glob
import json
import os
import tomllib

def run(books_library):
    print(get(books_library))

def get(books_library):
    metadatas = []

    for path in glob.glob(f'{books_library}/**/metadata.toml', recursive=True):
        with open(path, 'rb') as f:
            directory = os.path.dirname(os.path.realpath(path))
            metadata = tomllib.load(f)
            for p in glob.glob(f'{directory}/cover.*'):
                metadata['cover'] = p
                break
            metadatas.append(metadata)

    return json.dumps(metadatas)