Files
CollectMangaInfo/pupildata.py
Lee Young Hoon e9f8a7323c Update DataClass.py, GetArc_Ehentai.py, and 7 more files...
데이터 클래스 정의, 퍼필 다운로더 json 파서...
2024-05-13 21:48:40 +09:00

94 lines
2.6 KiB
Python

import json
import UtilPack as util
import DataClass as info
GALBLOCK = "galleryBlock"
GALURL = "galleryUrl"
GALINFO = "galleryInfo"
GALTAGS = "relatedTags"
JTITLE = "japanese_title"
# Example
#with open('test.db', 'r') as file:
# data = json.load(file)
#print_json_tree(data)
#print(data['galleryInfo']['tags'])
# pupil : Json
# Caribre : text
# My : CSV
class PupuilInfoFile:
m_data = None
def __init__(self, path):
self.path = path
def __enter__(self):
self.DBXLSOpen(self.path)
def __exit__(self, ex_type, ex_value, traceback):
self.DBXLSClose()
def PupilJSONOpen(self, path):
with open(path, 'r') as file:
self.m_data = json.load(file)
# pupil 의 JSON 을 파싱해서 DataClass 로 반환한다.
def GetInfo(self):
if None == self.m_data:
return None
title = self.m_data[GALINFO]["title"]
url = self.m_data[GALBLOCK]["galleryUrl"]
retInfo = info(title, url)
retInfo.type = self.m_data[GALINFO]["type"]
retInfo.language = self.m_data[GALINFO]["language"]
retInfo.gallery_id = self.m_data[GALINFO]["id"]
listArtists = self.m_data[GALINFO]["artists"]
for item in listArtists:
strArtist = item["artist"]
strUrl = item["url"]
strTag = f"artist:{strArtist}"
tempInfo = util.TagInfo(strTag, strUrl)
retInfo.AddArtist(tempInfo)
listTags = self.m_data[GALINFO]["tags"]
for item in listTags:
strGend = ""
if 1 == item["female"]:
strGend = "female:"
elif 1 == item["male"]:
strGend = "male:"
strTag = item["tag"]
strRelatedTag = f"{strGend}:{strTag}"
tagUrl = item[url]
tempInfo = util.TagInfo(strRelatedTag, tagUrl)
retInfo.AddTag(tempInfo)
return retInfo
# pupil 의 JSON 을 파싱해서 ImageFileList 를 반환한다.
def GetImageFilesInfo(self):
if None == self.m_data:
return None
listRet = set()
listFiles = self.m_data[GALINFO]["files"]
for item in listFiles:
tempInfo = info.ImageFileInfo(item["name"],
item["height"],
item["width"],
item["hash"],
item["haswebp"])
listRet.append(tempInfo)
return listRet