display error message if unable to run youtube-dl

This would have made the typo of the command name that was just fixed
obvious earlier, when --no-raw was used to force using it.
This commit is contained in:
Joey Hess 2021-11-13 09:07:43 -04:00
parent aa6e54ac6e
commit 889e771357
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 13 additions and 9 deletions

View file

@ -271,7 +271,8 @@ performWeb addunlockedmatcher o url file urlinfo = ifAnnexed file addurl geturl
addurl = addUrlChecked o url file webUUID $ \k -> addurl = addUrlChecked o url file webUUID $ \k ->
ifM (pure (not (rawOption (downloadOptions o))) <&&> youtubeDlSupported url) ifM (pure (not (rawOption (downloadOptions o))) <&&> youtubeDlSupported url)
( return (True, True, setDownloader url YoutubeDownloader) ( return (True, True, setDownloader url YoutubeDownloader)
, checkRaw (downloadOptions o) $ return (Url.urlExists urlinfo, Url.urlSize urlinfo == fromKey keySize k, url) , checkRaw Nothing (downloadOptions o) $
return (Url.urlExists urlinfo, Url.urlSize urlinfo == fromKey keySize k, url)
) )
{- Check that the url exists, and has the same size as the key, {- Check that the url exists, and has the same size as the key,
@ -332,7 +333,7 @@ downloadWeb addunlockedmatcher o url urlinfo file =
in ifAnnexed f in ifAnnexed f
(alreadyannexed (fromRawFilePath f)) (alreadyannexed (fromRawFilePath f))
(dl f) (dl f)
Left _ -> checkRaw o (normalfinish tmp) Left err -> checkRaw (Just err) o (normalfinish tmp)
where where
dl dest = withTmpWorkDir mediakey $ \workdir -> do dl dest = withTmpWorkDir mediakey $ \workdir -> do
let cleanuptmp = pruneTmpWorkDirBefore tmp (liftIO . removeWhenExistsWith R.removeLink) let cleanuptmp = pruneTmpWorkDirBefore tmp (liftIO . removeWhenExistsWith R.removeLink)
@ -346,7 +347,7 @@ downloadWeb addunlockedmatcher o url urlinfo file =
showDestinationFile (fromRawFilePath dest) showDestinationFile (fromRawFilePath dest)
addWorkTree canadd addunlockedmatcher webUUID mediaurl dest mediakey (Just (toRawFilePath mediafile)) addWorkTree canadd addunlockedmatcher webUUID mediaurl dest mediakey (Just (toRawFilePath mediafile))
return $ Just mediakey return $ Just mediakey
Right Nothing -> checkRaw o (normalfinish tmp) Right Nothing -> checkRaw Nothing o (normalfinish tmp)
Left msg -> do Left msg -> do
cleanuptmp cleanuptmp
warning msg warning msg
@ -363,9 +364,12 @@ downloadWeb addunlockedmatcher o url urlinfo file =
warning $ dest ++ " already exists; not overwriting" warning $ dest ++ " already exists; not overwriting"
return Nothing return Nothing
checkRaw :: DownloadOptions -> Annex a -> Annex a checkRaw :: (Maybe String) -> DownloadOptions -> Annex a -> Annex a
checkRaw o a checkRaw failreason o a
| noRawOption o = giveup "Unable to use youtube-dl or a special remote and --no-raw was specified." | noRawOption o = giveup $ "Unable to use youtube-dl or a special remote and --no-raw was specified" ++
case failreason of
Just msg -> ": " ++ msg
Nothing -> ""
| otherwise = a | otherwise = a
{- The destination file is not known at start time unless the user provided {- The destination file is not known at start time unless the user provided
@ -487,7 +491,7 @@ nodownloadWeb addunlockedmatcher o url urlinfo file
then nomedia then nomedia
else youtubeDlFileName url >>= \case else youtubeDlFileName url >>= \case
Right mediafile -> usemedia (toRawFilePath mediafile) Right mediafile -> usemedia (toRawFilePath mediafile)
Left _ -> checkRaw o nomedia Left err -> checkRaw (Just err) o nomedia
| otherwise = do | otherwise = do
warning $ "unable to access url: " ++ url warning $ "unable to access url: " ++ url
return Nothing return Nothing

View file

@ -185,7 +185,7 @@ performDownload addunlockedmatcher opts cache todownload = case location todownl
let f' = fromRawFilePath f let f' = fromRawFilePath f
r <- Remote.claimingUrl url r <- Remote.claimingUrl url
if Remote.uuid r == webUUID || rawOption (downloadOptions opts) if Remote.uuid r == webUUID || rawOption (downloadOptions opts)
then checkRaw (downloadOptions opts) $ do then checkRaw Nothing (downloadOptions opts) $ do
let dlopts = (downloadOptions opts) let dlopts = (downloadOptions opts)
-- force using the filename -- force using the filename
-- chosen here -- chosen here
@ -326,7 +326,7 @@ performDownload addunlockedmatcher opts cache todownload = case location todownl
, downloadlink , downloadlink
) )
where where
downloadlink = checkRaw (downloadOptions opts) $ downloadlink = checkRaw Nothing (downloadOptions opts) $
performDownload addunlockedmatcher opts cache todownload performDownload addunlockedmatcher opts cache todownload
{ location = Enclosure linkurl } { location = Enclosure linkurl }