Python downloader for saving m3u8 video to local MP4 file.
Project description
M3u8-To-MP4
Python downloader for saving m3u8 videos to local MP4 files.
QuickStart
Install m3u8_To_MP4 via pip
Preparation: configure ffmpeg. (e.g., Win10)
Download “release full” build. It will have the largest set of libraries with greater functionality.
Extract the contents in the ZIP file to a folder of your choice.
To add FFmpeg to Win10 path. (User variables -> Path -> New and add)
Verify. Open the Command Prompt or PowerShell window, type ffmpeg, and press Enter.
Installation: m3u8_To_MP4
pip install m3u8_To_MP4
Download a mp4 video
There are two options to download a m3u8 video into a mp4 file: async and multi-threads.
Multi-thread downloader (recommend)
import m3u8_To_MP4
if __name__ == '__main__':
# 1. Download videos from uri.
m3u8_To_MP4.multithread_download('http://videoserver.com/playlist.m3u8')
# 2. Download videos from existing m3u8 files.
m3u8_To_MP4.multithread_file_download('http://videoserver.com/playlist.m3u8',m3u8_file_path)
# For compatibility, i reserve this api, but i do not recommend to you again.
# m3u8_To_MP4.download('http://videoserver.com/playlist.m3u8')
Asynchronous downloader
import m3u8_To_MP4
if __name__ == '__main__':
# 1. Download mp4 from uri.
m3u8_To_MP4.async_download('http://videoserver.com/playlist.m3u8')
# 2. Download mp4 from existing m3u8 files.
m3u8_To_MP4.async_file_download('http://videoserver.com/playlist.m3u8',m3u8_file_path)
Resuming
If you use default tmp dir, resuming the transfer from the point of interruption will be executed automatically (based on crc32 hashing).
Custom http request header
In some cases, customized http request headers help to match some website requirements. For the available APIs, you can pass in a dictionary type header, which overrides the settings in the program. A simple example is:
import m3u8_To_MP4
if __name__ == '__main__':
customized_http_header=dict()
customized_http_header['Referer']='https://videoserver.com/'
m3u8_To_MP4.multithread_download('http://videoserver.com/playlist.m3u8',customized_http_header=customized_http_header)
Features
Treat ffmpeg as a system service to achieve cross-platform.
If ffmpeg is not found, archiving is also supported. (v0.1.3 new features)
Resume from interruption. (based on crc32 temp directory path)
Use system tmp folder.
Concurrent requests based on the thread pool.
Concurrent requests based on efficient coroutines (v0.1.3 new features).
The retry strategy is carried out collectively after the whole cycle is repeated, avoiding the problem of short retry interval.
Download videos from existing m3u8 files.
Anti-crawler parameters based on customized request headers.
Clean codes based on inheritance.
TODO
Errors: application data after close notify (related to the Python interpreter).
Extract independent asynchronous http package.
Support IPv6.
Compare ffmpeg/avconv/mencoder/moviepy.
Support bilibili etc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for m3u8_To_MP4-0.1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d50290172ae45bfc7c8882819109398d6f9c424d050730886d5e30c28ee747a9 |
|
MD5 | d2799f6665289eb137e00c3a85ea386e |
|
BLAKE2b-256 | b5cca6a95ba31737ebe5c1ea6c27e1a08e290c1c5ec9f9f7a09b34a9269e3565 |