forked from DRMTalks/devine
Move download time elapsed code to utilities
This commit is contained in:
parent
7b7be47f7d
commit
7ee5e71075
|
@ -48,7 +48,7 @@ from devine.core.services import Services
|
|||
from devine.core.titles import Movie, Song, Title_T
|
||||
from devine.core.titles.episode import Episode
|
||||
from devine.core.tracks import Audio, Subtitle, Video
|
||||
from devine.core.utilities import get_binary_path, is_close_match
|
||||
from devine.core.utilities import get_binary_path, is_close_match, time_elapsed_since
|
||||
from devine.core.utils.click_types import LANGUAGE_RANGE, QUALITY, SEASON_RANGE, ContextData
|
||||
from devine.core.utils.collections import merge_dict
|
||||
from devine.core.utils.subprocess import ffprobe
|
||||
|
@ -578,12 +578,10 @@ class dl:
|
|||
cookie_jar.set_cookie(cookie)
|
||||
cookie_jar.save(ignore_discard=True)
|
||||
|
||||
minutes, seconds = divmod(int(time.time() - start_time), 60)
|
||||
hours, minutes = divmod(minutes, 60)
|
||||
time_string = (f"{hours:d}h" if hours else "") + f"{minutes:d}m{seconds:d}s"
|
||||
dl_time = time_elapsed_since(start_time)
|
||||
|
||||
console.print(Padding(
|
||||
f"Processed all titles in [progress.elapsed]{time_string}",
|
||||
f"Processed all titles in [progress.elapsed]{dl_time}",
|
||||
(0, 5, 1, 5)
|
||||
))
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import importlib.util
|
|||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
|
||||
import unicodedata
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
|
@ -189,6 +191,23 @@ def get_ip_info(session: Optional[requests.Session] = None) -> dict:
|
|||
return (session or requests.Session()).get("https://ipinfo.io/json").json()
|
||||
|
||||
|
||||
def time_elapsed_since(start: float) -> str:
|
||||
"""
|
||||
Get time elapsed since a timestamp as a string.
|
||||
E.g., `1h56m2s`, `15m12s`, `0m55s`, e.t.c.
|
||||
"""
|
||||
elapsed = int(time.time() - start)
|
||||
|
||||
minutes, seconds = divmod(elapsed, 60)
|
||||
hours, minutes = divmod(minutes, 60)
|
||||
|
||||
time_string = f"{minutes:d}m{seconds:d}s"
|
||||
if hours:
|
||||
time_string = f"{hours:d}h{time_string}"
|
||||
|
||||
return time_string
|
||||
|
||||
|
||||
@contextlib.asynccontextmanager
|
||||
async def start_pproxy(proxy: str) -> AsyncIterator[str]:
|
||||
proxy = urlparse(proxy)
|
||||
|
|
Loading…
Reference in New Issue