|
1 | 1 | from datetime import datetime |
2 | 2 | from pathlib import Path |
3 | | -from typing import Union, overload, Set, Optional |
| 3 | +from typing import Union, overload, Tuple |
4 | 4 |
|
5 | 5 | import aiofiles |
6 | 6 | from loguru import logger |
@@ -194,34 +194,35 @@ async def download_post( |
194 | 194 | ) |
195 | 195 | if ret: |
196 | 196 | post_path = path / generate_post_path_name(ret.data.post) |
197 | | - |
| 197 | + |
198 | 198 | # For revision posts, create a revision subfolder |
199 | 199 | if revision_id: |
200 | 200 | post_path = post_path / "revision" / revision_id |
201 | | - |
| 201 | + |
202 | 202 | # Download the main post |
203 | 203 | job_list = await create_job_from_post( |
204 | 204 | post=ret.data.post, |
205 | 205 | post_path=post_path, |
206 | 206 | dump_post_data=dump_post_data |
207 | 207 | ) |
208 | | - |
| 208 | + |
209 | 209 | # If include_revisions is enabled and we have revisions data |
210 | 210 | if (config.job.include_revisions and |
211 | | - ret.data.props and |
212 | | - ret.data.props.revisions and |
213 | | - not revision_id): # Don't process revisions if we're already downloading a specific revision |
214 | | - |
| 211 | + ret.data.props and |
| 212 | + ret.data.props.revisions and |
| 213 | + not revision_id): # Don't process revisions if we're already downloading a specific revision |
| 214 | + |
215 | 215 | for revision_order, revision_data in ret.data.props.revisions: |
216 | 216 | if revision_data.revision_id: # Only process actual revisions, not the main post |
217 | | - revision_path = post_path / config.job.post_structure.revisions / generate_post_path_name(revision_data) |
| 217 | + revision_path = post_path / config.job.post_structure.revisions / generate_post_path_name( |
| 218 | + revision_data) |
218 | 219 | revision_jobs = await create_job_from_post( |
219 | 220 | post=revision_data, |
220 | 221 | post_path=revision_path, |
221 | 222 | dump_post_data=dump_post_data |
222 | 223 | ) |
223 | 224 | job_list.extend(revision_jobs) |
224 | | - |
| 225 | + |
225 | 226 | job_runner = JobRunner(job_list=job_list) |
226 | 227 | await job_runner.start() |
227 | 228 | else: |
@@ -271,8 +272,8 @@ async def sync_creator( |
271 | 272 | end_time: str = None, |
272 | 273 | offset: int = 0, |
273 | 274 | length: int = None, |
274 | | - keywords: str = None, |
275 | | - keywords_exclude: str = None |
| 275 | + keywords: Tuple[str] = None, |
| 276 | + keywords_exclude: Tuple[str] = None |
276 | 277 | ): |
277 | 278 | """ |
278 | 279 | Sync posts from a creator |
@@ -338,23 +339,18 @@ async def sync_creator( |
338 | 339 | return creator_ret.message |
339 | 340 |
|
340 | 341 | creator_path = path / sanitize_filename(creator_name) |
341 | | - |
342 | 342 | creator_path.mkdir(exist_ok=True) |
343 | | - |
344 | | - # Parse keywords |
345 | | - keyword_set: Optional[Set[str]] = None |
| 343 | + |
| 344 | + keywords = [keywords] if isinstance(keywords, str) else keywords |
| 345 | + keyword_set = set(keywords) if keywords else config.job.keywords |
346 | 346 | if keywords: |
347 | | - keyword_set = set(kw.strip() for kw in keywords.split(',') if kw.strip()) |
348 | | - if keyword_set: |
349 | | - logger.info(f"Filtering posts by keywords: {', '.join(keyword_set)}") |
350 | | - |
351 | | - # Parse exclude keywords |
352 | | - keyword_exclude_set: Optional[Set[str]] = None |
| 347 | + logger.info(f"Filtering posts by keywords: {', '.join(keyword_set)}") |
| 348 | + |
| 349 | + keywords_exclude = [keywords_exclude] if isinstance(keywords_exclude, str) else keywords_exclude |
| 350 | + keyword_exclude_set = set(keywords_exclude) if keywords_exclude else config.job.keywords_exclude |
353 | 351 | if keywords_exclude: |
354 | | - keyword_exclude_set = set(kw.strip() for kw in keywords_exclude.split(',') if kw.strip()) |
355 | | - if keyword_exclude_set: |
356 | | - logger.info(f"Excluding posts by keywords: {', '.join(keyword_exclude_set)}") |
357 | | - |
| 352 | + logger.info(f"Excluding posts by keywords: {', '.join(keyword_exclude_set)}") |
| 353 | + |
358 | 354 | ret = await create_job_from_creator( |
359 | 355 | service=service, |
360 | 356 | creator_id=creator_id, |
|
0 commit comments