From 889e77135709227b2f99fdd261c2aef8c6cca836 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 13 Nov 2021 09:07:43 -0400 Subject: [PATCH] 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. --- Command/AddUrl.hs | 18 +++++++++++------- Command/ImportFeed.hs | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index a24d4c8c9b..cf240d0069 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -271,7 +271,8 @@ performWeb addunlockedmatcher o url file urlinfo = ifAnnexed file addurl geturl addurl = addUrlChecked o url file webUUID $ \k -> ifM (pure (not (rawOption (downloadOptions o))) <&&> youtubeDlSupported url) ( 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, @@ -332,7 +333,7 @@ downloadWeb addunlockedmatcher o url urlinfo file = in ifAnnexed f (alreadyannexed (fromRawFilePath f)) (dl f) - Left _ -> checkRaw o (normalfinish tmp) + Left err -> checkRaw (Just err) o (normalfinish tmp) where dl dest = withTmpWorkDir mediakey $ \workdir -> do let cleanuptmp = pruneTmpWorkDirBefore tmp (liftIO . removeWhenExistsWith R.removeLink) @@ -346,7 +347,7 @@ downloadWeb addunlockedmatcher o url urlinfo file = showDestinationFile (fromRawFilePath dest) addWorkTree canadd addunlockedmatcher webUUID mediaurl dest mediakey (Just (toRawFilePath mediafile)) return $ Just mediakey - Right Nothing -> checkRaw o (normalfinish tmp) + Right Nothing -> checkRaw Nothing o (normalfinish tmp) Left msg -> do cleanuptmp warning msg @@ -363,9 +364,12 @@ downloadWeb addunlockedmatcher o url urlinfo file = warning $ dest ++ " already exists; not overwriting" return Nothing -checkRaw :: DownloadOptions -> Annex a -> Annex a -checkRaw o a - | noRawOption o = giveup "Unable to use youtube-dl or a special remote and --no-raw was specified." +checkRaw :: (Maybe String) -> DownloadOptions -> Annex a -> Annex a +checkRaw failreason o a + | 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 {- 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 else youtubeDlFileName url >>= \case Right mediafile -> usemedia (toRawFilePath mediafile) - Left _ -> checkRaw o nomedia + Left err -> checkRaw (Just err) o nomedia | otherwise = do warning $ "unable to access url: " ++ url return Nothing diff --git a/Command/ImportFeed.hs b/Command/ImportFeed.hs index 9fbaf34ffd..a8d21365e3 100644 --- a/Command/ImportFeed.hs +++ b/Command/ImportFeed.hs @@ -185,7 +185,7 @@ performDownload addunlockedmatcher opts cache todownload = case location todownl let f' = fromRawFilePath f r <- Remote.claimingUrl url if Remote.uuid r == webUUID || rawOption (downloadOptions opts) - then checkRaw (downloadOptions opts) $ do + then checkRaw Nothing (downloadOptions opts) $ do let dlopts = (downloadOptions opts) -- force using the filename -- chosen here @@ -326,7 +326,7 @@ performDownload addunlockedmatcher opts cache todownload = case location todownl , downloadlink ) where - downloadlink = checkRaw (downloadOptions opts) $ + downloadlink = checkRaw Nothing (downloadOptions opts) $ performDownload addunlockedmatcher opts cache todownload { location = Enclosure linkurl }