LivePhoto Processing in XHS-Downloader#
LivePhoto refers to XiaoHongShu's (ε°ηΊ’δΉ¦) feature where image posts can carry an accompanying short video clip per image β analogous to Apple Live Photos. In XHS-Downloader, each image entry in the API's imageList array may include an H.264 video stream URL alongside the static image URL. The downloader extracts, tracks, and optionally saves those video clips independently of the static image files.
Extraction from imageList#
The entry point for LivePhoto URL extraction is Image.get_image_link() in source/application/image.py. It:
- Reads the
imageListarray from the API response viadata.safe_extract("imageList", []). - Immediately calls
__get_live_link(images), which iterates every image item and pulls the H.264 master URL at the JSON pathstream.h264[0].masterUrl. If no such URL exists for an item,Noneis stored at that position. - Returns a parallel pair of lists β
(image_urls, live_links)β preserving index correspondence between static images and their video counterparts .
LivePhoto video URLs are served as plain HTTP URLs and are formatted through Html.format_url() before being returned .
Download Behavior#
The (urls, lives) pair from Image.get_image_link() is passed to Download.run(), which routes image/album posts to __ready_download_image().
Inside __ready_download_image(), each image and its paired live video are handled together via zip(urls, lives) . The LivePhoto video download task is added only when all three conditions are met :
self.live_downloadisTrue- The live URL for this image is not
None - The corresponding
.mp4file does not already exist on disk
The live video file is saved using the same base filename as its paired image (e.g. {filename}_1.mp4, {filename}_2.mp4, β¦), distinguished by the live_format which is always "mp4" .
Configuration#
The live_download flag controls whether LivePhoto video components are downloaded. It is wired through several layers:
| Layer | Location | Key |
|---|---|---|
| Default config | settings.py line 29 | "live_download": False |
| Manager init | manager.py line 129 | self.live_download = self.check_bool(live_download, True) |
| Downloader init | download.py line 67 | self.live_download = manager.live_download |
Note: The default in
settings.jsonisFalse, meaning LivePhoto video files are not downloaded unless explicitly enabled. TheManagerfallback default when the value is not a boolean isTrue, but sincesettings.pyalways writes a proper boolean, the effective out-of-box default isFalse.
To enable LivePhoto downloads, set "live_download": true in settings.json.
Data Flow Summary#
API imageList[]
ββ Image.get_image_link()
ββ static image URLs βββββββββββββββββββββββββββ
ββ live_link[] (stream.h264[0].masterUrl | None) β
βΌ
Download.__ready_download_image()
ββ always queues static image
ββ queues live .mp4 if live_download=True AND URL present
Key Files#
| File | Role |
|---|---|
source/application/image.py | Extracts live video URLs from imageList |
source/application/download.py | Schedules live .mp4 download tasks |
source/module/manager.py | Holds live_download flag; passes it to Download |
source/module/settings.py | Defines "live_download": False as the default config |