1111
1212from ktoolbox ._enum import PostFileTypeEnum , DataStorageNameEnum
1313from ktoolbox .action import ActionRet , fetch_creator_posts , FetchInterruptError
14- from ktoolbox .action .utils import generate_post_path_name , filter_posts_by_date , generate_filename , filter_posts_by_keywords , filter_posts_by_keywords_exclude , generate_grouped_post_path
15- from ktoolbox .api .model import Post , Attachment
16- from ktoolbox .api .posts import get_post_revisions as get_post_revisions_api
14+ from ktoolbox .action .utils import generate_post_path_name , filter_posts_by_date , generate_filename , \
15+ filter_posts_by_keywords , filter_posts_by_keywords_exclude , generate_grouped_post_path
16+ from ktoolbox .api .model import Post , Attachment , Revision
17+ from ktoolbox .api .posts import get_post_revisions as get_post_revisions_api , get_post as get_post_api
1718from ktoolbox .configuration import config , PostStructureConfiguration
1819from ktoolbox .job import Job , CreatorIndices
1920from ktoolbox .utils import extract_external_links
2223
2324
2425async def create_job_from_post (
25- post : Post ,
26+ post : Union [ Post , Revision ] ,
2627 post_path : Path ,
2728 * ,
2829 post_structure : Union [PostStructureConfiguration , bool ] = None ,
@@ -75,8 +76,8 @@ async def create_job_from_post(
7576 )
7677 ):
7778 # Check if file extension should be excluded from sequential naming
78- should_use_sequential = (config .job .sequential_filename and
79- file_path_obj .suffix .lower () not in config .job .sequential_filename_excludes )
79+ should_use_sequential = (config .job .sequential_filename and
80+ file_path_obj .suffix .lower () not in config .job .sequential_filename_excludes )
8081 if should_use_sequential :
8182 basic_filename = f"{ sequential_counter } { file_path_obj .suffix } "
8283 sequential_counter += 1
@@ -120,6 +121,17 @@ async def create_job_from_post(
120121 )
121122 )
122123
124+ # If post has no content, fetch it from get_post API
125+ if not post .content :
126+ get_post_ret = await get_post_api (
127+ service = post .service ,
128+ creator_id = post .user ,
129+ post_id = post .id ,
130+ revision_id = post .revision_id if isinstance (post , Revision ) else None
131+ )
132+ if get_post_ret :
133+ post = get_post_ret .data .post
134+
123135 # Write content file
124136 if content_path and post .content :
125137 async with aiofiles .open (content_path , "w" , encoding = config .downloader .encoding ) as f :
@@ -204,15 +216,15 @@ async def create_job_from_creator(
204216 # Filter posts by publish time
205217 if start_time or end_time :
206218 post_list = list (filter_posts_by_date (post_list , start_time , end_time ))
207-
219+
208220 # Filter posts by keywords
209221 if keywords :
210222 post_list = list (filter_posts_by_keywords (post_list , keywords ))
211-
223+
212224 # Filter out posts by exclude keywords
213225 if keywords_exclude :
214226 post_list = list (filter_posts_by_keywords_exclude (post_list , keywords_exclude ))
215-
227+
216228 logger .info (f"Get { len (post_list )} posts after filtering, start creating jobs" )
217229
218230 # Filter posts and generate ``CreatorIndices``
@@ -223,7 +235,7 @@ async def create_job_from_creator(
223235 for post in post_list :
224236 grouped_base_path = generate_grouped_post_path (post , path )
225237 posts_path [post .id ] = grouped_base_path / sanitize_filename (post .title )
226-
238+
227239 indices = CreatorIndices (
228240 creator_id = creator_id ,
229241 service = service ,
@@ -258,7 +270,7 @@ async def create_job_from_creator(
258270 post_structure = False if mix_posts else None ,
259271 dump_post_data = not mix_posts
260272 )
261-
273+
262274 # If include_revisions is enabled, fetch and download revisions for this post
263275 if config .job .include_revisions and not mix_posts :
264276 try :
@@ -270,7 +282,8 @@ async def create_job_from_creator(
270282 if revisions_ret and revisions_ret .data :
271283 for revision in revisions_ret .data :
272284 if revision .revision_id : # Only process actual revisions
273- revision_path = post_path / config .job .post_structure .revisions / generate_post_path_name (revision )
285+ revision_path = post_path / config .job .post_structure .revisions / generate_post_path_name (
286+ revision )
274287 revision_jobs = await create_job_from_post (
275288 post = revision ,
276289 post_path = revision_path ,
@@ -279,5 +292,5 @@ async def create_job_from_creator(
279292 job_list += revision_jobs
280293 except Exception as e :
281294 logger .warning (f"Failed to fetch revisions for post { post .id } : { e } " )
282-
295+
283296 return ActionRet (data = job_list )
0 commit comments