Nowadays, video websites tend to break their online videos into hundreds (if not thousands) of TS fragments and stream them via an M3U playlist. This makes scraping rather hard as:
- Without access to the M3U playlist, we don't know how many files are there and what their names are
- Each TS fragment can be encrypted
- TS is not that popular hence might not be correctly recognised by many video players
- Hundreds of TS files are not watchable for humans at all
M3UAssistant is designed to address this problem by:
- Parsing the content (i.e. TS fragment URLs) of the target M3U8 file, and the key file if the TS fragments are encrypted
- Download the fragments and the value of decryption key if encrypted
- Concatenate fragments into one TS file
- Decrypt the TS file
- Convert the decrypted file to MP4, which can be recognised by all most all video player
Unfortunately, all of the following dependencies are required for now. In the short (hopefully) future, I will add the options of replacing them with other ones you would like to use.
However, hey, it is always nice to have a try on the following ones on this or other occasions if you haven't : )
Hopefully, your computer already has the tool for concatenation: cat
pip3 install -r requirements.txt
The following dependencies can be installed via HomeBrew
:
aria2c
For downloading:
brew install aria2c
OpenSSL
For decryption:
brew install openssl
FFmpeg
For video conversion:
brew install ffmpeg
If you are not a macOS
user, then good luck on finding them via your own package manager :P
Here is a demo on how to use this assistant:
cd
to the parent directory ofM3UAssistant
,- Run with
Python3
:
python3 -m M3UAssistant.master_engine <target_m3u_url> -P <m3u_prefix> -O <output_name.mp4>
where:
target_m3u_url
is the URL to the M3U file to parsem3u_prefix
is the prefix that should be added to each TS fragment URI in the M3U file to complete a full URL. Usually M3U will omit this prefix, but Normally you can identify it easily by checking out the full address of TS fragments in your browser.output_name.mp4
the name of the final output, as indicated by its name, it should end with.mp4
--help, -h
, showing the help message and exit--verbose True|False
or-V True|False
, indicating whether to print out the debug messages--*_tool
, indicating whether to replace the default tools, coming soon