Files
auto-archiver/src/auto_archiver/modules/json_enricher/json_enricher.py
2025-06-17 16:06:04 +01:00

20 lines
603 B
Python

import json
from loguru import logger
import os
from auto_archiver.core import Enricher
from auto_archiver.core import Media, Metadata
class JsonEnricher(Enricher):
def enrich(self, to_enrich: Metadata) -> None:
url = to_enrich.get_url()
logger.debug(f"JSON Enricher for {url=}")
item_path = os.path.join(self.tmp_dir, "metadata.json")
with open(item_path, mode="w", encoding="utf-8") as outf:
json.dump(to_enrich.to_dict(), outf, indent=4, default=str, ensure_ascii=False)
to_enrich.add_media(Media(filename=item_path), id="metadata_json")