Skip to main content

A multithreading m3u8 download module for python, and the number of threads can decide by yourself; Convert .m3u8 file to .mp4 file; Supporting redownload.

Project description

M3u8 Downloader

A multithread m3u8 download module and the number of threads can decide by yourself. using how many threads is decide by your network and your device.

Github : https://github.com/walkureHHH/M3u8-Downloader/

1. Install

pip install mder

2. Import

import mder

3. Instance object and start download

downloader = mder.m3u8_downloader(m3u8_file_path='./test.m3u8',temp_file_path='./',mp4_path='./test.mp4',num_of_threads=10)
# parameters
# 1.m3u8_file_path
# default : no default   (type : str)
# 2.temp_file_path
# default : '.'          (type : str)
# 3.mp4_path
# default : './test.mp4' (type : str)
# 4.num_of_threads
# default : 10           (type : int)

downloader.start()
# parameters
# 1.mod
# default : 0            (type : int)
# mod 0 means delete TS folder and m3u8 file if download completely
# mod 1 means delete m3u8 file only if download completely
# mod 2 means delete TS folder only if download completely
# mod 3 means reserve TS folder and m3u8 file if download completely
# 2.time_out
# default : 60           (type : int)(units : seconds)
# The time_out is the timeout in request.get(timeout=)

before download

the structure of ./ is:

.
├── test.m3u8
└── test.py

when it is downloading

the structure of ./ is:

.
├── TS
│   ├── qzCFnDUZE9_720_5308_0000.ts
│   ├── qzCFnDUZE9_720_5308_0001.ts
│   ├── qzCFnDUZE9_720_5308_0002.ts
│   ├── qzCFnDUZE9_720_5308_0003.ts
│   ├── qzCFnDUZE9_720_5308_0004.ts
│   ├── qzCFnDUZE9_720_5308_0005.ts
│   ├── qzCFnDUZE9_720_5308_0006.ts
│   ├── qzCFnDUZE9_720_5308_0007.ts
│   ├── qzCFnDUZE9_720_5308_0008.ts
│   ├── qzCFnDUZE9_720_5308_0009.ts
│   └── qzCFnDUZE9_720_5308_0010.ts  
├── test.m3u8
└── test.py

process bar: <<*>> 29% 500/1752 [01:33<04:02] <<*>>

TS is temp folder, all .ts file are in it. The path of it is %temp_file_path%/TS, in the test case, it is in ./TS. If the mission is not complete, the m3u8 file and TS folder will be reserved, you can instance a new downloader with corresponding TS folder and m3u8 file, and use the start() function to begin, in this way, the mission will go on.

after download and download successfully

the structure of ./ is:

.
├── test.mp4
└── test.py

If some .ts download failed, the module will redownload for 4 times, and the information will print to the command line

at last, the command line is like this:

<<*>>  99% 1737/1752 [05:35<00:22] <<*>>
thread0 Time out ERROR qzCFnDUZE9_720_5308_1710.ts
thread2 Time out ERROR qzCFnDUZE9_720_5308_1722.ts
thread0 redownload successfully qzCFnDUZE9_720_5308_1710.ts
<<*>>  99% 1738/1752 [06:20<03:19] <<*>>
thread2 redownload successfully qzCFnDUZE9_720_5308_1722.ts
<<*>> 100% 1752/1752 [06:26<00:00] <<*>>
downloading finished 100.00%

if complete

The attribute if_complete of class M3u8_Download can used to find if the download is conplete. In this example, we can use

a = downloader.if_complete # a == False means the downloading is incomplete.

5. restart

If you want to restart a incomplete mission, you only should use the corresponding TS folder and .m3u8 file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mder-1.0.2.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

mder-1.0.2-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page