@@ -162,7 +162,7 @@ def __init__(self, parameter: "Parameter", database: "Database", ):
162162 ("批量下载账号作品(抖音)" , self .account_acquisition_interactive ,),
163163 ("批量下载链接作品(抖音)" , self .detail_interactive ,),
164164 ("获取直播推流地址(抖音)" , self .live_interactive ,),
165- ("采集作品评论数据(抖音)" , self .comment_interactive ,),
165+ # ("采集作品评论数据(抖音)", self.comment_interactive,),
166166 ("批量下载合集作品(抖音)" , self .mix_interactive ,),
167167 # ("采集账号详细数据(抖音)", self.disable_function,),
168168 # ("采集搜索结果数据(抖音)", self.disable_function,),
@@ -486,17 +486,20 @@ async def _batch_process_detail(self,
486486 addition : str = None ,
487487 tiktok = False ,
488488 title : str = None ,
489+ collect_id : str = None ,
489490 ):
490491 self .logger .info ("开始提取作品数据" )
491492 id_ , name , mid , title , mark , data = self .extractor .preprocessing_data (
492- data , id_ , mark , post , mix , tiktok , title , )
493+ data , id_ , mark , post , mix , tiktok , title , collect_id = collect_id , )
493494 self .__display_extracted_information (
494495 mix , id_ , name , mid , title , mark , )
495496 addition = addition or ("合集作品" if mix else "发布作品" if post else "喜欢作品" )
496497 old_mark = f"{ m ["MARK" ]} _{ addition } " if (
497498 m := await self .cache .has_cache (
498499 mid if mix else id_ )) else None
499- async with logger (root , name = f"{ 'MID' if mix else 'UID' } { mid if mix else id_ } _{ mark } _{ addition } " , old = old_mark ,
500+ async with logger (root ,
501+ name = f"{ self ._generate_prefix (mix = mix , collect = bool (collect_id ))} { self ._generate_id (id_ , mid , mix = mix , collect = bool (collect_id ))} _{ mark } _{ addition } " ,
502+ old = old_mark ,
500503 console = self .console , ** params ) as recorder :
501504 data = await self .extractor .run (
502505 data ,
@@ -512,16 +515,35 @@ async def _batch_process_detail(self,
512515 return data
513516 await self .cache .update_cache (
514517 self .parameter .folder_mode ,
515- "MID" if mix else "UID" ,
516- mid if mix else id_ ,
518+ self . _generate_prefix ( mix = mix , collect = bool ( collect_id )) ,
519+ self . _generate_id ( id_ , mid , mix = mix , collect = bool ( collect_id )) ,
517520 mark ,
518521 title if mix else name ,
519522 addition ,
520523 )
521524 await self .download_account_detail (
522- data , id_ , name , mark , mid , title , addition , tiktok , )
525+ data , id_ , name , mark , self ._generate_id (id_ , mid , mix = mix , collect = bool (collect_id )), title , addition ,
526+ tiktok , collect = bool (collect_id ), )
523527 return True
524528
529+ @staticmethod
530+ def _generate_prefix (user = True , mix = False , collect = False ):
531+ if collect :
532+ return "CID"
533+ if mix :
534+ return "MID"
535+ if user :
536+ return "UID"
537+
538+ @staticmethod
539+ def _generate_id (id_ , mid , user = True , mix = False , collect = False ):
540+ if collect :
541+ return mid
542+ if mix :
543+ return mid
544+ if user :
545+ return id_
546+
525547 def __display_extracted_information (
526548 self ,
527549 mix : bool ,
@@ -544,6 +566,7 @@ async def download_account_detail(
544566 title : str = None ,
545567 addition : str = None ,
546568 tiktok : bool = False ,
569+ collect = False ,
547570 ):
548571 await self .downloader .run (
549572 data ,
@@ -555,6 +578,7 @@ async def download_account_detail(
555578 addition = addition ,
556579 mid = mid ,
557580 title = title ,
581+ collect = collect ,
558582 )
559583
560584 async def detail_interactive (self , select = "" , * args , ** kwargs ):
@@ -906,7 +930,8 @@ async def mix_inquire_collection(self) -> list[str]:
906930 return self .input_download_index (data )
907931
908932 def input_download_index (self , data : list [dict ]) -> list [str ]:
909- return self .__input_download_index (data )[- 1 ]
933+ _ , id_ = self .__input_download_index (data )
934+ return id_
910935
911936 def __input_download_index (self ,
912937 data : list [dict ],
@@ -917,15 +942,14 @@ def __input_download_index(self,
917942 self .console .print (f"{ text } 列表:" )
918943 for i , j in enumerate (data , start = 1 ):
919944 self .console .print (f"{ i } . { j [key ]} " )
920- index = self .console .input (f"请输入需要下载的{ text } 序号(输入 ALL 下载全部{ text } ):" )
945+ index = self .console .input (f"请输入需要下载的{ text } 序号(多个序号使用空格分隔, 输入 ALL 下载全部{ text } ):" )
921946 try :
922947 if index .upper () == "ALL" :
923948 return zip (* [(d [key ], d ["id" ]) for d in data ])
924- if 0 <= (i := int (index ) - 1 ) <= len (data ):
925- return [data [i ][key ]], [data [i ]["id" ]]
926- self .console .print (f"{ text } 序号输入错误!" , style = WARNING )
927- raise ValueError
949+ index = {int (i ) for i in index .split ()}
950+ return zip (* [(d [key ], d ["id" ]) for i , d in enumerate (data , start = 1 ) if i in index ])
928951 except ValueError :
952+ self .console .print (f"{ text } 序号输入错误!" , style = WARNING )
929953 return []
930954
931955 async def mix_txt (self , root , params , logger ):
@@ -1331,7 +1355,10 @@ async def collection_interactive(self, *args, **kwargs):
13311355 @check_cookie_state (tiktok = False )
13321356 async def collects_interactive (self , * args , ** kwargs ):
13331357 if sec_user_id := await self .__check_owner_url ():
1334- names , ids = await self .__get_collects_list ()
1358+ try :
1359+ names , ids = await self .__get_collects_list ()
1360+ except ValueError :
1361+ names , ids = [], []
13351362 root , params , logger = self .record .run (self .parameter )
13361363 start = time ()
13371364 for i , j in zip (names , ids ):
@@ -1465,6 +1492,7 @@ async def _deal_collects_data(
14651492 addition = "收藏夹作品" ,
14661493 tiktok = tiktok ,
14671494 title = name ,
1495+ collect_id = id_ ,
14681496 )
14691497
14701498 async def hashtag_interactive (
0 commit comments