Skip to content

Commit

Permalink
feat: 新增实况图集下载 (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnserf-Seed committed Oct 14, 2024
1 parent 5d8d896 commit 5df0fc3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
21 changes: 21 additions & 0 deletions f2/apps/douyin/dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,27 @@ async def download_video(self):
)

async def download_images(self):
# 处理实况视频下载
images_video_list = self.aweme_data_dict.get("images_video", [])
if images_video_list:
for i, images_video_url in enumerate(images_video_list):
image_video_name = f"{format_file_name(self.kwargs.get('naming'), self.aweme_data_dict)}_live_{i + 1}"
if images_video_url:
await self.initiate_download(
_("实况"),
images_video_url,
self.base_path,
image_video_name,
".mp4",
)
else:
logger.warning(
_("[{0}] 该图集没有实况链接,无法下载").format(self.aweme_id)
)
else:
logger.info(_("[{0}] 非实况图集,跳过实况下载").format(self.aweme_id))

# 处理图片下载
for i, image_url in enumerate(self.aweme_data_dict.get("images", [])):
image_name = f"{format_file_name(self.kwargs.get('naming'), self.aweme_data_dict)}_image_{i + 1}"
if image_url:
Expand Down
39 changes: 39 additions & 0 deletions f2/apps/douyin/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,23 @@ def images(self):
for images in images_list
]

@property
def images_video(self):
images_video_list = self._get_list_attr_value("$.aweme_list[*].images")

return [
(
[
live["video"]["play_addr"]["url_list"][0]
for live in images_video
if isinstance(live, dict) and "video" in live
]
if images_video
else None
)
for images_video in images_video_list
]

@property
def animated_cover(self):
# 临时办法
Expand Down Expand Up @@ -1415,6 +1432,12 @@ def video_play_addr(self):
def images(self):
return self._get_list_attr_value("$.aweme_detail.images[*].url_list[0]")

@property
def images_video(self):
return self._get_list_attr_value(
"$.aweme_detail.images[*].video.play_addr.url_list[0]"
)

def _to_raw(self) -> Dict:
return self._data

Expand Down Expand Up @@ -1858,6 +1881,22 @@ def images(self):
for images in images_list
]

@property
def images_video(self):
images_list = self._get_list_attr_value("$.data[*].aweme.images")
return [
(
[
img["video"]["play_addr"]["url_list"][0]
for img in images
if isinstance(img, dict) and "video" in img
]
if images
else None
)
for images in images_list
]

@property
def video_play_addr(self):
return self._get_list_attr_value("$.data[*].aweme.video.play_addr.url_list")
Expand Down
8 changes: 7 additions & 1 deletion f2/apps/douyin/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@
class DouyinHandler:

# 需要忽略的字段(需过滤掉有时效性的字段)
ignore_fields = ["video_play_addr", "images", "video_bit_rate", "cover"]
ignore_fields = [
"video_play_addr",
"images",
"video_bit_rate",
"cover",
"images_video",
]

def __init__(self, kwargs: Dict = ...) -> None:
self.kwargs = kwargs
Expand Down
1 change: 1 addition & 0 deletions f2/apps/douyin/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BaseRequestModel(BaseModel):
aid: str = "6383"
channel: str = "channel_pc_web"
pc_client_type: int = 1
publish_video_strategy_type: int = 2
version_code: str = ClientConfManager.brm_version().get("code", "290100")
version_name: str = ClientConfManager.brm_version().get("name", "29.1.0")
cookie_enabled: str = "true"
Expand Down

0 comments on commit 5df0fc3

Please sign in to comment.