add aria2 progress parsing
This commit is contained in:
parent
1c88b59bd0
commit
af05ac3ec2
1 changed files with 35 additions and 8 deletions
|
@ -18,6 +18,7 @@ import Logs.Trust.Basic
|
||||||
import Types.TrustLevel
|
import Types.TrustLevel
|
||||||
import Types.UrlContents
|
import Types.UrlContents
|
||||||
import Types.CleanupActions
|
import Types.CleanupActions
|
||||||
|
import Types.Key
|
||||||
import Utility.Metered
|
import Utility.Metered
|
||||||
import Utility.Tmp
|
import Utility.Tmp
|
||||||
import Backend.URL
|
import Backend.URL
|
||||||
|
@ -88,7 +89,7 @@ downloadKey key _file dest p = do
|
||||||
checkDependencies
|
checkDependencies
|
||||||
unlessM (downloadTorrentFile u) $
|
unlessM (downloadTorrentFile u) $
|
||||||
error "could not download torrent file"
|
error "could not download torrent file"
|
||||||
downloadTorrentContent u dest filenum p
|
downloadTorrentContent key u dest filenum p
|
||||||
|
|
||||||
downloadKeyCheap :: Key -> FilePath -> Annex Bool
|
downloadKeyCheap :: Key -> FilePath -> Annex Bool
|
||||||
downloadKeyCheap _ _ = return False
|
downloadKeyCheap _ _ = return False
|
||||||
|
@ -228,12 +229,13 @@ downloadMagnetLink u metadir dest = ifM download
|
||||||
, Param "--bt-save-metadata"
|
, Param "--bt-save-metadata"
|
||||||
, Param u
|
, Param u
|
||||||
, Param "--seed-time=0"
|
, Param "--seed-time=0"
|
||||||
|
, Param "--summary-interval=0"
|
||||||
, Param "-d"
|
, Param "-d"
|
||||||
, File metadir
|
, File metadir
|
||||||
]
|
]
|
||||||
|
|
||||||
downloadTorrentContent :: URLString -> FilePath -> Int -> MeterUpdate -> Annex Bool
|
downloadTorrentContent :: Key -> URLString -> FilePath -> Int -> MeterUpdate -> Annex Bool
|
||||||
downloadTorrentContent u dest filenum p = do
|
downloadTorrentContent k u dest filenum p = do
|
||||||
torrent <- tmpTorrentFile u
|
torrent <- tmpTorrentFile u
|
||||||
tmpdir <- tmpTorrentDir u
|
tmpdir <- tmpTorrentDir u
|
||||||
createAnnexDirectory tmpdir
|
createAnnexDirectory tmpdir
|
||||||
|
@ -246,13 +248,14 @@ downloadTorrentContent u dest filenum p = do
|
||||||
, return False
|
, return False
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
-- TODO parse aria's output and update progress meter
|
download torrent tmpdir = ariaProgress (keySize k) p
|
||||||
download torrent tmpdir = runAria
|
|
||||||
[ Param $ "--select-file=" ++ show filenum
|
[ Param $ "--select-file=" ++ show filenum
|
||||||
, File torrent
|
, File torrent
|
||||||
, Param "-d"
|
, Param "-d"
|
||||||
, File tmpdir
|
, File tmpdir
|
||||||
, Param "--seed-time=0"
|
, Param "--seed-time=0"
|
||||||
|
, Param "--summary-interval=0"
|
||||||
|
, Param "--file-allocation=none"
|
||||||
]
|
]
|
||||||
|
|
||||||
{- aria2c will create part of the directory structure
|
{- aria2c will create part of the directory structure
|
||||||
|
@ -272,10 +275,34 @@ checkDependencies = do
|
||||||
unless (null missing) $
|
unless (null missing) $
|
||||||
error $ "need to install additional software in order to download from bittorrent: " ++ unwords missing
|
error $ "need to install additional software in order to download from bittorrent: " ++ unwords missing
|
||||||
|
|
||||||
runAria :: [CommandParam] -> Annex Bool
|
ariaParams :: [CommandParam] -> Annex [CommandParam]
|
||||||
runAria ps = do
|
ariaParams ps = do
|
||||||
opts <- map Param . annexAriaTorrentOptions <$> Annex.getGitConfig
|
opts <- map Param . annexAriaTorrentOptions <$> Annex.getGitConfig
|
||||||
liftIO $ boolSystem "aria2c" (ps ++ opts)
|
return (ps ++ opts)
|
||||||
|
|
||||||
|
runAria :: [CommandParam] -> Annex Bool
|
||||||
|
runAria ps = liftIO . boolSystem "aria2c" =<< ariaParams ps
|
||||||
|
|
||||||
|
-- Parse aria output to find "(n%)" and update the progress meter
|
||||||
|
-- with it. The output is also output to stdout.
|
||||||
|
ariaProgress :: Maybe Integer -> MeterUpdate -> [CommandParam] -> Annex Bool
|
||||||
|
ariaProgress Nothing _ ps = runAria ps
|
||||||
|
ariaProgress (Just sz) meter ps =
|
||||||
|
liftIO . commandMeter (parseAriaProgress sz) meter "aria2c"
|
||||||
|
=<< ariaParams ps
|
||||||
|
|
||||||
|
parseAriaProgress :: Integer -> ProgressParser
|
||||||
|
parseAriaProgress totalsize = go [] . reverse . split ['\r']
|
||||||
|
where
|
||||||
|
go remainder [] = (Nothing, remainder)
|
||||||
|
go remainder (x:xs) = case readish (findpercent x) of
|
||||||
|
Nothing -> go (x++remainder) xs
|
||||||
|
Just p -> (Just (frompercent p), remainder)
|
||||||
|
|
||||||
|
-- "(N%)"
|
||||||
|
findpercent = takeWhile (/= '%') . drop 1 . dropWhile (/= '(')
|
||||||
|
|
||||||
|
frompercent p = toBytesProcessed $ totalsize * p `div` 100
|
||||||
|
|
||||||
btshowmetainfo :: FilePath -> String -> IO [String]
|
btshowmetainfo :: FilePath -> String -> IO [String]
|
||||||
btshowmetainfo torrent field =
|
btshowmetainfo torrent field =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue