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