diff --git a/Pipfile b/Pipfile index deae92f9..a71c0a53 100644 --- a/Pipfile +++ b/Pipfile @@ -5,6 +5,7 @@ name = "pypi" [packages] fuse-python = "==1.0.7" +humanize = "==4.9.0" plexapi = "==4.15.7" requests-cache = "==1.1.1" sentry-sdk = "==2.1.1" diff --git a/Pipfile.lock b/Pipfile.lock index 29f8e063..09e3bbc1 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "43963e7d9096951208aa5866be8110ab8a97ee2ac8c3573ee057b30f4479f341" + "sha256": "a7c7ed75a5da2ed16a527cb2dfe7b2113a7424260a28271fd1d77cc577069f9b" }, "pipfile-spec": 6, "requires": { @@ -145,6 +145,15 @@ "index": "pypi", "version": "==1.0.7" }, + "humanize": { + "hashes": [ + "sha256:582a265c931c683a7e9b8ed9559089dea7edcf6cc95be39a3cbc2c5d5ac2bcfa", + "sha256:ce284a76d5b1377fd8836733b983bfb0b76f1aa1c090de2566fcf008d7f6ab16" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==4.9.0" + }, "idna": { "hashes": [ "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc", diff --git a/plexfuse/measure_speed.py b/plexfuse/measure_speed.py new file mode 100644 index 00000000..9561be6f --- /dev/null +++ b/plexfuse/measure_speed.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from contextlib import contextmanager +from time import monotonic +from typing import TYPE_CHECKING + +from humanize import naturalsize + +if TYPE_CHECKING: + from pathlib import Path + + +@contextmanager +def measure_speed(part: Path): + start = monotonic() + print(f"Downloading: {part}") + yield + now = monotonic() + file_size = part.stat().st_size + rate = file_size / (now - start) + speed = naturalsize(rate, binary=True) + + print(f"Downloaded in {speed}/s: {part}") diff --git a/plexfuse/vfs/ChunkedFile.py b/plexfuse/vfs/ChunkedFile.py index 94bc93ab..1e78fbef 100644 --- a/plexfuse/vfs/ChunkedFile.py +++ b/plexfuse/vfs/ChunkedFile.py @@ -3,6 +3,7 @@ from typing import TYPE_CHECKING from plexfuse.cache.FileCache import FileCache +from plexfuse.measure_speed import measure_speed if TYPE_CHECKING: from plexfuse.plex.PlexApi import PlexApi @@ -44,10 +45,11 @@ def cache_path(self, path: str, chunk_number: int): cache_path = file.parent / filename if not cache_path.exists(): - print(f"Downloading: {cache_path}") base_offset = self.base_offset(chunk_number) - self.plex.download_part(path, cache_path, - offset=base_offset, size=self.chunk_size) + + with measure_speed(cache_path): + self.plex.download_part(path, cache_path, + offset=base_offset, size=self.chunk_size) return cache_path diff --git a/pyproject.toml b/pyproject.toml index 925ec8d7..49f27faf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ authors = [ requires-python = ">= 3.11" dependencies = [ "fuse-python", + "humanize>=4.9.0", "plexapi>=4.15", "requests-cache>=1.1", "websocket-client>=1.7.0",