Skip to content

Commit

Permalink
Setup pylint (#171)
Browse files Browse the repository at this point in the history
* Setup pylint

* Fix more warnings

* Standardize spacing
  • Loading branch information
AlexAplin authored May 25, 2024
1 parent c964dca commit 0dbc911
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 123 deletions.
6 changes: 5 additions & 1 deletion nndownload/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""Module entry for nndownload."""

from . import nndownload


def execute(*args):
"""Pass arguments to be executed by nndownload."""

args_list = [e.strip() for e in args]
nndownload._cmdl_opts = nndownload.cmdl_parser.parse_args(args_list)
nndownload._CMDL_OPTS = nndownload.cmdl_parser.parse_args(args_list)
nndownload.main()
3 changes: 3 additions & 0 deletions nndownload/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""CLI entry for nndownload."""

from .nndownload import cli


cli()
20 changes: 15 additions & 5 deletions nndownload/ffmpeg_dl.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""ffmpeg subprocess for merging DMS streams to output."""

import re
import subprocess
import warnings
Expand All @@ -13,18 +15,17 @@

class FfmpegDLException(Exception):
"""Raised when a download fails."""
pass


class FfmpegDL:
"""Send input streams for download to an `ffmpeg` subprocess."""

FF_GLOBAL_ARGS = [
FF_GLOBAL_ARGS = (
"-progress",
"-",
"-nostats",
"-y"
]
)

REGEX_TIME_GROUP = "([0-9]{2}:[0-9]{2}:[0-9]{2}[.[0-9]*]?)"
REGEX_OUT_TIME = re.compile(
Expand All @@ -33,20 +34,26 @@ class FfmpegDL:

@classmethod
def get_timedelta(cls, time_str: AnyStr, str_format: AnyStr = "%H:%M:%S.%f"):
"""Return a timedelta for a given time string"""

t = datetime.strptime(time_str, str_format)
return timedelta(hours=t.hour, minutes=t.minute, seconds=t.second, microseconds=t.microsecond)

def __init__(self, streams: List, input_kwargs: List, output_path: AnyStr, output_kwargs: List, global_args: List = FF_GLOBAL_ARGS):
"""Initialize a downloader to perform an ffmpeg conversion task."""

inputs = []
for stream in streams:
input = ffmpeg.input(stream, **input_kwargs)
inputs.append(input)
stream_input = ffmpeg.input(stream, **input_kwargs)
inputs.append(stream_input)
stream_spec = ffmpeg.output(*inputs, output_path, **output_kwargs).global_args(*global_args)

self.proc_args = ffmpeg._run.compile(stream_spec=stream_spec)
self.proc: subprocess.Popen = None

def load_subprocess(self):
"""Open an ffmpeg subprocess."""

self.proc = subprocess.Popen(
args=self.proc_args,
stdin=subprocess.PIPE,
Expand All @@ -56,11 +63,14 @@ def load_subprocess(self):
)

def convert(self, name: AnyStr, duration: float):
"""Perform an ffmpeg conversion while printing progress using tqdm."""

progress = tqdm_rich(desc=name, unit="sec", colour="green", total=duration)

self.load_subprocess()

stdout_line = None
prev_line = None
while True:
if self.proc.stdout is None:
continue
Expand Down
3 changes: 2 additions & 1 deletion nndownload/hls_dl.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Native HLS downloader for DMS streams."""

import re
from concurrent.futures import ThreadPoolExecutor

Expand All @@ -11,7 +13,6 @@

def download_hls(m3u8_url, filename, name, session, progress, threads):
"""Perform a native HLS download of a provided M3U8 manifest."""
# TODO: Support proxies (#150)

from .nndownload import FormatNotAvailableException

Expand Down
Loading

0 comments on commit 0dbc911

Please sign in to comment.