How to Configure Media Downloads for Videos in MediaCrawler
To configure video downloads in MediaCrawler, set ENABLE_GET_MEIDAS = True in main/config/base_config.py and define your DOWNLOAD_ROOT path so the crawler automatically fetches and stores video files via the async file writer pipeline.
MediaCrawler is an open-source scraping framework that supports multiple Chinese social media platforms. While it defaults to extracting only textual metadata, you can configure it to capture full video files by adjusting two critical settings in the configuration package. This guide walks through the exact steps to activate and customize video downloads using the actual source implementation.
Enable Video Downloads in MediaCrawler
The crawler treats media fetching as an opt-in feature controlled by a central toggle.
Toggle the Media Download Switch
Located in main/config/base_config.py, the ENABLE_GET_MEIDAS boolean acts as the master switch for all binary downloads. When set to False (the default), the crawler stores only JSON metadata and text content. Changing this to True signals the platform handlers to initiate file downloads.
# main/config/base_config.py
ENABLE_GET_MEIDAS = True
Set the Download Directory
By default, files write to a ./download folder relative to the working directory. Override this by setting DOWNLOAD_ROOT to an absolute or relative path. For platform-specific organization, use VIDEO_DOWNLOAD_ROOT to isolate videos from other media types.
# main/config/base_config.py
import os
DOWNLOAD_ROOT = os.path.join(os.getcwd(), "media_downloads")
VIDEO_DOWNLOAD_ROOT = os.path.join(DOWNLOAD_ROOT, "douyin_videos")
How the Video Download Pipeline Works
Understanding the internal flow helps troubleshoot issues and customize behavior. The implementation in media_platform/douyin/core.py (mirrored in other platform modules) follows a four-stage pipeline:
- Browser initialization – The launcher passes
accept_downloads=Trueto Playwright, permitting the headless browser to handle file streams. - Media detection – The
get_aweme_mediamethod inspects the post type, routing image notes tonote_download_urland videos tovideo_download_url. - Binary fetching – The URL feeds into
self.dy_client.get_aweme_media, which returns the raw bytes. - Persistent storage – The
store.update_dy_aweme_videomethod delegates toAsyncFileWriter, writing content to the configured root while respecting theDOWNLOAD_ROOTpath.
The writer creates subdirectories automatically, structuring files as <DOWNLOAD_ROOT>/douyin_videos/<aweme_id>/video.mp4.
Customizing Download Behavior
Beyond enabling the feature, you can control naming conventions and storage locations.
Filename Patterns and Storage Structure
The default implementation in store/douyin/_store_impl.py uses a static suffix "video.mp4" combined with the unique aweme_id. To modify this pattern, edit the extension_file_name variable in the storage implementation before the AsyncFileWriter call.
# Inside store/douyin/_store_impl.py
extension_file_name = f"{aweme_id}_custom.mp4"
Platform-Specific Overrides
Each platform maintains its own config file (e.g., main/config/dy_config.py for Douyin) that imports from base_config.py. You can override VIDEO_DOWNLOAD_ROOT here to keep platform data separated without modifying the base configuration.
# main/config/dy_config.py
import os
from main.config import base_config
VIDEO_DOWNLOAD_ROOT = os.path.join(base_config.DOWNLOAD_ROOT, "douyin")
Complete Configuration Example
Combine these settings to activate video capture for Douyin content:
# main/config/base_config.py
import os
ENABLE_GET_MEIDAS = True
DOWNLOAD_ROOT = "./media_downloads"
VIDEO_DOWNLOAD_ROOT = os.path.join(DOWNLOAD_ROOT, "douyin_videos")
When executing the crawler via main.py, the configuration propagates automatically:
# main.py
from config import base_config as cfg
from media_platform.douyin.core import DouYinCrawler
async def run():
crawler = DouYinCrawler()
await crawler.start() # Respects cfg.ENABLE_GET_MEIDAS
During execution, media_platform/douyin/core.py processes each item:
video_download_url = douyin_store._extract_video_download_url(aweme_item)
content = await self.dy_client.get_aweme_media(video_download_url)
extension_file_name = "video.mp4"
await douyin_store.update_dy_aweme_video(aweme_id, content, extension_file_name)
The AsyncFileWriter in main/tools/async_file_writer.py commits the bytes to disk at:
media_downloads/douyin_videos/<aweme_id>/video.mp4
Summary
- Enable downloads by setting
ENABLE_GET_MEIDAS = Trueinmain/config/base_config.py. - Define storage paths using
DOWNLOAD_ROOTand optionalVIDEO_DOWNLOAD_ROOTvariables. - Understand the pipeline spanning from Playwright's
accept_downloadsthroughget_aweme_mediatoAsyncFileWriter. - Customize filenames by modifying
extension_file_nameinstore/douyin/_store_impl.py. - Apply platform overrides in dedicated config files like
main/config/dy_config.pyto keep data organized.
Frequently Asked Questions
Where is the video download setting located in MediaCrawler?
The primary toggle resides in main/config/base_config.py as the boolean constant ENABLE_GET_MEIDAS. Setting this to True activates the download pipeline across all supported platforms, while False restricts the crawler to metadata only.
What file format are videos saved as in MediaCrawler?
By default, the crawler saves videos with the .mp4 extension. The specific filename is constructed in store/douyin/_store_impl.py using the aweme_id and a static "video.mp4" suffix, though you can customize this pattern by editing the extension_file_name parameter.
Can I change the download location for specific platforms only?
Yes. While DOWNLOAD_ROOT in main/config/base_config.py sets the global default, each platform config (such as main/config/dy_config.py for Douyin) can redefine VIDEO_DOWNLOAD_ROOT to isolate that platform's media in a dedicated subdirectory without affecting other crawlers.
Why are my videos not downloading even after enabling the setting?
Verify that ENABLE_GET_MEIDAS is spelled correctly and set to True in the config file actually being imported by your entry script. Additionally, ensure the DOWNLOAD_ROOT directory has write permissions, and check that Playwright's accept_downloads=True parameter is present in the browser launch configuration within media_platform/douyin/core.py.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →