addurl --file: Fix a bug that made youtube-dl be used unneccessarily when adding an html url that does not contain any media.

This commit is contained in:
Joey Hess 2019-03-18 13:34:29 -04:00
parent a87da159c1
commit 8758f9c561
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 11 additions and 2 deletions

View file

@ -218,7 +218,7 @@ performWeb :: AddUrlOptions -> URLString -> FilePath -> Url.UrlInfo -> CommandPe
performWeb o url file urlinfo = ifAnnexed file addurl geturl
where
geturl = next $ isJust <$> addUrlFile (downloadOptions o) url urlinfo file
addurl = addUrlChecked o url file webUUID $ \k ->
addurl = addUrlChecked o url file webUUID $ \k ->
ifM (pure (not (rawOption (downloadOptions o))) <&&> youtubeDlSupported url)
( return (True, True, setDownloader url YoutubeDownloader)
, return (Url.urlExists urlinfo, Url.urlSize urlinfo == keySize k, url)
@ -277,7 +277,6 @@ downloadWeb o url urlinfo file =
liftIO $ createDirectoryIfMissing True (parentDir file)
finishDownloadWith tmp webUUID url file
tryyoutubedl tmp
| isJust (fileOption o) = dl file
-- Ask youtube-dl what filename it will download
-- first, and check if that is already an annexed file,
-- to avoid unnecessary work in that case.
@ -286,6 +285,12 @@ downloadWeb o url urlinfo file =
(alreadyannexed dest)
(dl dest)
Left _ -> normalfinish tmp
-- Ask youtube-dl what filename it will download
-- fist, so it's only used when the file contains embedded
-- media.
| isJust (fileOption o) = youtubeDlFileNameHtmlOnly url >>= \case
Right _ -> dl file
Left _ -> normalfinish tmp
where
dl dest = withTmpWorkDir mediakey $ \workdir -> do
let cleanuptmp = pruneTmpWorkDirBefore tmp (liftIO . nukeFile)