From 43f681d4c15221096975250c0809ded40bf8a5fd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 21 Nov 2022 15:04:36 -0400 Subject: [PATCH] Support parsing yt-dpl output to display download progress Before this fix, no progress was displayed when yt-dpl was used. Sponsored-by: Graham Spencer on Patreon --- Annex/YoutubeDl.hs | 11 ++++++++--- CHANGELOG | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Annex/YoutubeDl.hs b/Annex/YoutubeDl.hs index ba050d4024..c6d0f2253e 100644 --- a/Annex/YoutubeDl.hs +++ b/Annex/YoutubeDl.hs @@ -265,8 +265,10 @@ supportedScheme uo url = case parseURIRelaxed url of _ -> allowedScheme uo u {- Strategy: Look for chunks prefixed with \r, which look approximately - - like this: + - like this for youtube-dl: - "ESC[K[download] 26.6% of 60.22MiB at 254.69MiB/s ETA 00:00" + - or for yt-dlp, like this: + - "\r[download] 1.8% of 1.14GiB at 1.04MiB/s ETA 18:23" - Look at the number before "% of " and the number and unit after, - to determine the number of bytes. -} @@ -292,8 +294,11 @@ parseYoutubeDlProgress = go [] . reverse . progresschunks calc percent total = round (percent * fromIntegral total / 100) parsepercent :: String -> Maybe Double - parsepercent = readMaybe . reverse . takeWhile (not . isSpace) . reverse + parsepercent = readMaybe + . reverse . takeWhile (not . isSpace) . reverse + . dropWhile isSpace - parsebytes = readSize units . takeWhile (not . isSpace) + parsebytes = readSize units . takeWhile (not . isSpace) + . dropWhile isSpace units = committeeUnits ++ storageUnits diff --git a/CHANGELOG b/CHANGELOG index 78fa628e4f..78c8abc552 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ git-annex (10.20221105) UNRELEASED; urgency=medium * init: Avoid scanning for annexed files, which can be lengthy in a large repository. Instead that scan is done on demand. * When youtube-dl is not available in PATH, use yt-dlp instead. + * Support parsing yt-dpl output to display download progress. -- Joey Hess Fri, 18 Nov 2022 12:58:06 -0400