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
This commit is contained in:
Joey Hess 2022-11-21 15:04:36 -04:00
parent 5256be61c1
commit 43f681d4c1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 9 additions and 3 deletions

View file

@ -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

View file

@ -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 <id@joeyh.name> Fri, 18 Nov 2022 12:58:06 -0400