async def mirroring(self, index_list: list[int]) -> None: for index in index_list: logger.debug(f"id: {index}") # Check galleryinfo first # galleryinfo 먼저 확인 if not await self.galleryinfo_database.get_galleryinfo(index): logger.debug( f"{index} couldn't find that galleryinfo locally.") if galleryinfo := await self.request.get_galleryinfo(index): logger.debug( f"{index} can get galleryinfo from hitomi.la.") await self.galleryinfo_database.add_galleryinfo(galleryinfo ) if not await self.info_database.get_info(index): logger.debug( f"{index} couldn't find that info locally.") await self.info_database.add_info( Info.from_galleryinfo(galleryinfo)) logger.debug(f"Added info {index}.") else: logger.debug(f"{index} already has info locally.") logger.debug(f"Added galleryinfo {index}.") else: logger.warning( f"{index} can't get galleryinfo from hitomi.la.") continue else: logger.debug(f"{index} already has galleryinfo locally.")
async def get_info(self, id: int) -> Optional[Info]: info_json = cast( Optional[HitomiInfoJSON], await self.collection.find_one({"id": id}, {"_id": 0}), ) if info_json: return Info.from_dict(info_json) return None
async def get_info_list(self, offset: int = 0, limit: int = 15) -> list[Info]: offset = offset * limit info_jsons = cast( list[HitomiInfoJSON], await self.collection.find({}, { "_id": 0 }).sort("id", -1).skip(offset).limit(limit).to_list(15), ) return [Info.from_dict(json_info) for json_info in info_jsons]
async def get_random_info(self) -> Info: info_json = cast( HitomiInfoJSON, await self.collection.aggregate([ { "$sample": { "size": 1 } }, { "$project": { "_id": 0 } }, ]).next(), ) return Info.from_dict(info_json)
async def search(self, querys: list[str], offset: int = 0, limit: int = 15) -> tuple[list[Info], int]: offset = offset * limit title, query = self.parse_query(querys) pipeline = self.make_pipeline(title, query, offset, limit) try: results: dict[str, Any] = await self.collection.aggregate(pipeline ).next() except StopAsyncIteration: results = {"list": [], "count": 0} return [ Info.from_dict(cast(HitomiInfoJSON, result)) for result in results["list"] ], results["count"]
async def startup_test(heliotrope: Heliotrope, loop: AbstractEventLoop): await heliotrope.ctx.orm.add_galleryinfo(Galleryinfo.from_dict(galleryinfo) ) await heliotrope.ctx.odm.add_info(Info.from_dict(info))
async def convert_thumbnail(self, info: Info) -> dict[str, str]: thumnbnail_url = await self.get_thumbnail(info.id, info.thumbnail.to_dict()) info_dict = cast(dict[str, str], info.to_dict()) info_dict["thumbnail"] = thumnbnail_url return info_dict
async def add_info(self, info: Info) -> None: await self.collection.insert_one(info.to_dict())