Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Add threads flag #46

Merged
merged 3 commits into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions m3u8dl/core/download_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

def download_process(links, total_links, session, http2, max_retries,
convert, file_link_maps, path_prefix, debug, progress_bar_queue,
processes) -> None:
processes, threads) -> None:
print(f"Starting Download process {current_process().name}")
start_time = time()
try:
download_manager = DownloadProcess(links, total_links, session, http2,
max_retries, convert, debug, processes)
max_retries, convert, debug, processes, threads)

start_processes(download_manager, file_link_maps, path_prefix, progress_bar_queue)
try:
Expand All @@ -47,7 +47,7 @@ class DownloadProcess:
def __init__(self, links: List[str], total_links: int, session: requests.Session,
http2: bool = False, max_retries: int = 5,
convert: bool = True, debug: bool = False,
processes: int = 0):
processes: int = 0, threads: int = 0):
"""Initialize Object of DownloadProcess.

Parameters
Expand All @@ -68,6 +68,8 @@ def __init__(self, links: List[str], total_links: int, session: requests.Session
A flag to print messages to the console
processes: int
The number of processes to be used
threads: int
The number of threads to be used by each process
"""
self.__session: requests.Session = session
self.__total_links: int = total_links
Expand All @@ -76,8 +78,8 @@ def __init__(self, links: List[str], total_links: int, session: requests.Session
self.http2: bool = http2
self.convert = convert
self.__sent = 0
self.__process_num = processes or len(os.sched_getaffinity(os.getpid())) if platform.system() == "Linux" else 4
self.__thread_num = int(ceil((total_links - self.__sent) / (self.__process_num * 4)))
self.__process_num = processes or (len(os.sched_getaffinity(os.getpid())) if platform.system() == "Linux" else 4)
self.__thread_num = threads or int(ceil((total_links - self.__sent) / (self.__process_num * 4)))
self.debug = debug
self.done_retries = 0
self.error_links = []
Expand Down
4 changes: 3 additions & 1 deletion m3u8dl/core/m3u8dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def main():
"help understanding the process flow", action="store_true")
parser.add_argument("-m", "--processes", type=int, help="Specify number of processese by default 4 will be "
"initiated, or number of CPUs if on Linux")
parser.add_argument("-t", "--threads", type=int, help="Specify number of threads by default 4 will be "
"initiated for each process")

cli_args = parser.parse_args()

Expand Down Expand Up @@ -108,7 +110,7 @@ def main():
progress_bar_process.start()

download_process(links, len(links), sess, http2, MAX_RETRIES, cli_args.convert,
file_link_maps, path_prefix, debug, queue, cli_args.processes)
file_link_maps, path_prefix, debug, queue, cli_args.processes, cli_args.threads)

server.join()
video.join()
Expand Down