3 from .common
import InfoExtractor
10 from ..utils
.traversal
import traverse_obj
13 class XiaoHongShuIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://www\.xiaohongshu\.com/explore/(?P<id>[\da-f]+)'
17 'url': 'https://www.xiaohongshu.com/explore/6411cf99000000001300b6d9',
18 'md5': '2a87a77ddbedcaeeda8d7eae61b61228',
20 'id': '6411cf99000000001300b6d9',
22 'uploader_id': '5c31698d0000000007018a31',
23 'description': '#今日快乐今日发[话题]# #吃货薯看这里[话题]# #香妃蛋糕[话题]# #小五卷蛋糕[话题]# #新手蛋糕卷[话题]#',
24 'title': '香妃蛋糕也太香了吧🔥不需要卷❗️绝对的友好',
25 'tags': ['今日快乐今日发', '吃货薯看这里', '香妃蛋糕', '小五卷蛋糕', '新手蛋糕卷'],
27 'thumbnail': r
're:https?://sns-webpic-qc\.xhscdn\.com/\d+/[a-z0-9]+/[\w]+',
31 def _real_extract(self
, url
):
32 display_id
= self
._match
_id
(url
)
33 webpage
= self
._download
_webpage
(url
, display_id
)
34 initial_state
= self
._search
_json
(
35 r
'window\.__INITIAL_STATE__\s*=', webpage
, 'initial state', display_id
, transform_source
=js_to_json
)
37 note_info
= traverse_obj(initial_state
, ('note', 'noteDetailMap', display_id
, 'note'))
38 video_info
= traverse_obj(note_info
, ('video', 'media', 'stream', ('h264', 'av1', 'h265'), ...))
41 for info
in video_info
:
42 format_info
= traverse_obj(info
, {
43 'fps': ('fps', {int_or_none}
),
44 'width': ('width', {int_or_none}
),
45 'height': ('height', {int_or_none}
),
46 'vcodec': ('videoCodec', {str}
),
47 'acodec': ('audioCodec', {str}
),
48 'abr': ('audioBitrate', {int_or_none}
),
49 'vbr': ('videoBitrate', {int_or_none}
),
50 'audio_channels': ('audioChannels', {int_or_none}
),
51 'tbr': ('avgBitrate', {int_or_none}
),
52 'format': ('qualityType', {str}
),
53 'filesize': ('size', {int_or_none}
),
54 'duration': ('duration', {functools
.partial(float_or_none
, scale
=1000)}),
57 formats
.extend(traverse_obj(info
, (('mediaUrl', ('backupUrls', ...)), {
58 lambda u
: url_or_none(u
) and {'url': u
, **format_info
}})))
61 for image_info
in traverse_obj(note_info
, ('imageList', ...)):
62 thumbnail_info
= traverse_obj(image_info
, {
63 'height': ('height', {int_or_none}
),
64 'width': ('width', {int_or_none}
),
66 for thumb_url
in traverse_obj(image_info
, (('urlDefault', 'urlPre'), {url_or_none}
)):
75 'thumbnails': thumbnails
,
76 'title': self
._html
_search
_meta
(['og:title'], webpage
, default
=None),
77 **traverse_obj(note_info
, {
78 'title': ('title', {str}
),
79 'description': ('desc', {str}
),
80 'tags': ('tagList', ..., 'name', {str}
),
81 'uploader_id': ('user', 'userId', {str}
),