Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/jmcomic/jm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def new_postman(cls, session=False, **kwargs):
'cache': None, # see CacheRegistry
'domain': [],
'postman': {
'type': 'cffi',
'type': 'curl_cffi',
'meta_data': {
'impersonate': 'chrome110',
'headers': None,
Expand Down
26 changes: 26 additions & 0 deletions src/jmcomic/jm_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,32 @@ def get_dirname(cls, detail: 'DetailEntity', ref: str) -> str:

return getattr(detail, ref)

def get_properties_dict(self):
import inspect

prefix = self.__class__.__name__[2]
result = {}

# field
for k, v in self.__dict__.items():
result[prefix + k] = v

# property
for cls in inspect.getmro(type(self)):
for name, attr in cls.__dict__.items():
k = prefix + name
if k not in result and isinstance(attr, property):
v = attr.__get__(self, cls)
result[k] = v

# advice
advice_dict = JmModuleConfig.AFIELD_ADVICE if self.is_album() else JmModuleConfig.PFIELD_ADVICE
for name, func in advice_dict.items():
k = prefix + name
result[k] = func(self)

return result
Comment thread
coderabbitai[bot] marked this conversation as resolved.


class JmImageDetail(JmBaseEntity, Downloadable):

Expand Down
18 changes: 13 additions & 5 deletions src/jmcomic/jm_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class DirRule:
]

Detail = Union[JmAlbumDetail, JmPhotoDetail, None]
RuleFunc = Callable[[Detail], str]
RuleFunc = Callable
RuleSolver = Tuple[str, RuleFunc, str]
RuleSolverList = List[RuleSolver]

Expand Down Expand Up @@ -154,6 +154,12 @@ def split_rule_dsl(self, rule_dsl: str) -> List[str]:

@classmethod
def get_rule_solver(cls, rule: str) -> Optional[RuleSolver]:
if '{' in rule:
def format_path(album, photo):
return fix_windir_name(rule.format(**album.get_properties_dict(), **photo.get_properties_dict())).strip()

return 'F', format_path, rule

# 检查dsl
if not rule.startswith(('A', 'P')):
return None
Expand All @@ -176,15 +182,17 @@ def apply_rule_solver(cls, album, photo, rule_solver: RuleSolver) -> str:

def choose_detail(key):
if key == 'Bd':
return None
return None,
if key == 'A':
return album
return album,
if key == 'P':
return photo
return photo,
if key == 'F':
return album, photo

key, func, _ = rule_solver
detail = choose_detail(key)
return func(detail)
return func(*detail)

@classmethod
def apply_rule_directly(cls, album, photo, rule: str) -> str:
Expand Down