DocumentsXHS-Downloader
Video Quality Selection
Video Quality Selection
Type
Topic
Status
Published
Created
Jul 8, 2026
Updated
Jul 8, 2026
Created by
Dosu Bot
Updated by
Dosu Bot

Video Quality Selection#

XHS-Downloader selects the highest-quality video file available from XiaoHongShu's API by sorting all available stream variants according to a user-defined preference metric. A cookie is required to unlock higher-quality tiers from the API; without one, only low-resolution files are accessible.


video_preference Setting#

The video_preference key in settings.json controls the sort dimension used to rank quality tiers. Three values are accepted :

ValueSort by
resolution (default)Height (vertical pixel count)
bitratevideoBitrate field
sizeFile size

Invalid values fall back to "resolution" .


How Selection Works#

The entry point is Video.deal_video_link(data, preference). It tries a fast path first:

  1. generate_video_link — if the API response contains a direct video.consumer.originVideoKey, it constructs a CDN URL at https://sns-video-bd.xhscdn.com/{key} and returns it immediately, bypassing quality selection.
  2. get_video_link — if no direct key exists, it fetches all H.264 and H.265 stream objects from video.media.stream.h264 and video.media.stream.h265 , sorts them by the requested metric, and returns either the first backupUrls entry or the masterUrl of the highest-ranked variant.

The call site in app.py passes self.manager.video_preference directly :

container["下载地址"] = self.video.deal_video_link(data, self.manager.video_preference)

The README explicitly warns: without a cookie, video downloads are limited to low-resolution files; configuring a cookie unlocks higher quality — no login required .

Cookies are integrated at the HTTP client level. Manager.__init__ converts the cookie string to a dict via cookie_str_to_dict and injects it into the AsyncClient used for all API requests . The cookie parameter is optional in settings.json and also overridable per-request via the API mode's cookie field .

To obtain a valid cookie, the README instructs filtering the browser DevTools Network tab for cookie-name:web_session while visiting xiaohongshu.com/explore, then copying the full Cookie header .

The Manager.clean_cookie utility strips webId and web_session tokens from a cookie string — used when displaying or logging cookies without sensitive values.


Configuration Reference#

SettingDefaultConfig path
video_preference"resolution"settings.py line 30 / manager.py line 127
cookie""settings.py line 20 / manager.py line 105
video_downloadtruesettings.py line 28

Key source files: