importfeed: Avoid using youtube-dl when a feed does not contain an enclosure, but...
authorJoey Hess <joeyh@joeyh.name>
Tue, 15 Dec 2020 05:13:21 +0000 (01:13 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 15 Dec 2020 05:13:21 +0000 (01:13 -0400)
This is common in some feeds, which might mix some items with enclosures,
with others that link to posts or whatever. Before this, it would try to
use youtube-dl and fail, or if youtube-dl was not allowed, it would
incorrectly complain that an url was supported by youtube-dl.

CHANGELOG
Command/ImportFeed.hs

index 087c1f762aa7d6e261288d24f01c584f296e3d32..c8aa120ea70e9148867824a57243a21a0378f270 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -20,6 +20,8 @@ git-annex (8.20201128) UNRELEASED; urgency=medium
   * Fix reversion in 8.20201116 that made include= and exclude= in
     preferred/required content expressions match a path relative to the
     current directory, rather than the path from the top of the repository.
+  * importfeed: Avoid using youtube-dl when a feed does not contain an
+    enclosure, but only a link to an url which youtube-dl does not support.
 
  -- Joey Hess <id@joeyh.name>  Mon, 30 Nov 2020 12:55:49 -0400
 
index 43882b1fd49eb77c6e91b61200861f1f9652ab0e..dc21885ecba361e9d30af390e9f9621d4715ec8a 100644 (file)
@@ -308,27 +308,30 @@ performDownload addunlockedmatcher opts cache todownload = case location todownl
        
        downloadmedia linkurl mediaurl mediakey
                | rawOption (downloadOptions opts) = downloadlink
-               | otherwise = do
-                       r <- withTmpWorkDir mediakey $ \workdir -> do
-                               dl <- youtubeDl linkurl (fromRawFilePath workdir) nullMeterUpdate
-                               case dl of
-                                       Right (Just mediafile) -> do
-                                               let ext = case takeExtension mediafile of
-                                                       [] -> ".m"
-                                                       s -> s
-                                               ok <- rundownload linkurl ext $ \f ->
-                                                       checkCanAdd (downloadOptions opts) f $ \canadd -> do
-                                                               addWorkTree canadd addunlockedmatcher webUUID mediaurl f mediakey (Just (toRawFilePath mediafile))
-                                                               return (Just [mediakey])
-                                               return (Just ok)
-                                       -- youtude-dl didn't support it, so
-                                       -- download it as if the link were
-                                       -- an enclosure.
-                                       Right Nothing -> Just <$> downloadlink
-                                       Left msg -> do
-                                               warning msg
-                                               return Nothing
-                       return (fromMaybe False r)
+               | otherwise = ifM (youtubeDlSupported linkurl)
+                       ( do
+                               r <- withTmpWorkDir mediakey $ \workdir -> do
+                                       dl <- youtubeDl linkurl (fromRawFilePath workdir) nullMeterUpdate
+                                       case dl of
+                                               Right (Just mediafile) -> do
+                                                       let ext = case takeExtension mediafile of
+                                                               [] -> ".m"
+                                                               s -> s
+                                                       ok <- rundownload linkurl ext $ \f ->
+                                                               checkCanAdd (downloadOptions opts) f $ \canadd -> do
+                                                                       addWorkTree canadd addunlockedmatcher webUUID mediaurl f mediakey (Just (toRawFilePath mediafile))
+                                                                       return (Just [mediakey])
+                                                       return (Just ok)
+                                               -- youtube-dl didn't support it, so
+                                               -- download it as if the link were
+                                               -- an enclosure.
+                                               Right Nothing -> Just <$> downloadlink
+                                               Left msg -> do
+                                                       warning $ linkurl ++ ": " ++ msg
+                                                       return Nothing
+                               return (fromMaybe False r)
+                       , downloadlink
+                       )
          where
                downloadlink = performDownload addunlockedmatcher opts cache todownload
                        { location = Enclosure linkurl }