diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c349571 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM jrottenberg/ffmpeg:4.1-ubuntu + +WORKDIR /app + +RUN apt-get update && apt-get install -y \ + software-properties-common +RUN add-apt-repository universe +RUN apt-get update && apt-get install -y \ + python3.6 \ + python3-pip +COPY . /app + +RUN pip install -r requirements.txt + diff --git a/README.md b/README.md index 138bade..7f7753d 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ a CLI program to download videos in a m3u8 playlist, write it to a single video - Visit https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment for instructions on how to use virtualenv. ## Usage + +### Setup without docker - clone the repository using `git clone "ssh/https url"`. - create a virtual environment using `virtualenv -p python3.6 venv` in linux terminal, see 'Dependencies' for platform specific instructions. - activate virtual environment using `source venv/bin/activate` in linux terminal, see 'Dependencies' for platform specific instructions. @@ -26,6 +28,11 @@ a CLI program to download videos in a m3u8 playlist, write it to a single video - insert the url request headers in headers.txt. - start the script using `python -m m3u8dl `. +### Setup with docker +- build docker image using `docker build -t m3u8dl:0.11 .` +- start container `docker run -d -it --entrypoint='bash' --name m3u8dl-app m3u8dl:0.11` +- go into container terminal `docker exec -it m3u8dl-app bash` + ## Installing/Uninstalling for installation and usage using pip:- - ensure ffmpeg is installed see dependecies section diff --git a/m3u8dl/core/utils/write_file_no_gil.pyx b/m3u8dl/core/utils/write_file_no_gil.pyx deleted file mode 100644 index 96aa202..0000000 --- a/m3u8dl/core/utils/write_file_no_gil.pyx +++ /dev/null @@ -1,23 +0,0 @@ -from libc.stdio cimport FILE, fopen, fclose, fwrite - -cdef extern from "stdio.h" nogil: - FILE *fopen(const char *, const char *); - int fclose(FILE *); - size_t fwrite(const void *, size_t size, size_t nmemb, FILE *); - -cdef void write_no_gil(char* f_name, char* data, int size) nogil: - cdef FILE* c_file - c_file = fopen(f_name, "ab") - - fwrite(data, sizeof(data[0]), size, c_file) - fclose(c_file) - -cpdef write_file(file_path, data): - file_temp = file_path.encode("utf-8") - - cdef int size = len(data) - cdef char* f_name = file_temp - cdef char* d = data - - with nogil: - write_no_gil(f_name, d, size) \ No newline at end of file diff --git a/m3u8dl/core/weblib/fetch.py b/m3u8dl/core/weblib/fetch.py index fd3fb2d..2f5e2d2 100644 --- a/m3u8dl/core/weblib/fetch.py +++ b/m3u8dl/core/weblib/fetch.py @@ -1,7 +1,6 @@ from urllib.parse import urlparse from typing import Optional -import write_file_no_gil import requests @@ -43,10 +42,15 @@ def fetch_data(download_url: str, session: requests.Session, if request_data.status_code == 302: request_data = redirect_handler(session, request_data) + file = open(file_path, "ab") + for chunk in request_data.iter_content(10485760): if not chunk: break - write_file_no_gil.write_file(file_path, chunk) + + file.write(chunk) + + file.close() except (ConnectionResetError, ConnectionRefusedError, ConnectionError, TimeoutError, ConnectionAbortedError, OSError): diff --git a/requirements.txt b/requirements.txt index bbd1267..ad25dbc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ hyper==0.7.0 PyInstaller==3.6 requests==2.24.0 -Cython~=0.29.21 progress~=1.5 \ No newline at end of file diff --git a/setup.py b/setup.py index aabf05e..322fbeb 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,4 @@ from setuptools import setup, find_packages, Extension -import os - -USE_CYTHON = False - -ext = '.pyx' if USE_CYTHON else '.c' - -path = os.path.join("m3u8dl", "core", "utils", "write_file_no_gil") -extensions = [Extension("write_file_no_gil", [path + ext])] - -if USE_CYTHON: - from Cython.Build import cythonize - extensions = cythonize(extensions) - DESCRIPTION = 'm3u8 playlist downloader' VERSION = "0.1.1" @@ -23,7 +10,6 @@ setup( name="m3u8dl", version=VERSION, - ext_modules=extensions, zip_safe=False, author="Kevin Rohan Vaz", author_email="excalibur.krv@gmail.com", @@ -38,7 +24,6 @@ "hyper==0.7.0", "PyInstaller==3.6", "requests==2.24.0", - "Cython~=0.29.21", "progress~=1.5" ], classifiers=[