diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-11-30 13:24:52 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-11-30 13:24:52 -0400 |
commit | c70952118b9a453d998752a5fe6e5ace3d91ec99 (patch) | |
tree | 07b90cf738768951a03f67bfc8f48bca5b1d3de3 | |
parent | 5ff33723613ce9f53b63df50274c6bd469c1e052 (diff) |
honor --file when downloading with youtube-dl
This used to be done with quvi, and got broken in the transition.
-rw-r--r-- | Command/AddUrl.hs | 23 | ||||
-rw-r--r-- | Command/ImportFeed.hs | 2 |
2 files changed, 14 insertions, 11 deletions
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 06a960b0e..6db619e70 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -209,7 +209,7 @@ startWeb o urlstring = go $ fromMaybe bad $ parseURI urlstring performWeb :: AddUrlOptions -> URLString -> FilePath -> Url.UrlInfo -> CommandPerform performWeb o url file urlinfo = ifAnnexed file addurl geturl where - geturl = next $ isJust <$> addUrlFile (relaxedOption o) url urlinfo file + geturl = next $ isJust <$> addUrlFile (Just o) (relaxedOption o) url urlinfo file -- TODO youtube-dl addurl = addUrlChecked (relaxedOption o) url webUUID $ \k -> return $ (Url.urlExists urlinfo, Url.urlSize urlinfo == keySize k) @@ -234,12 +234,13 @@ addUrlChecked relaxed url u checkexistssize key stop ) -{- Adds an url, normally to the specified FilePath. But, if youtube-dl - - supports the url, it will be written to a different file, based on the - - title of the media. +{- Downloads an url and adds it to the repository, normally at the specified + - FilePath. But, if youtube-dl supports the url, it will be written to a + - different file, based on the title of the media. Unless the user + - specified fileOption, which then forces using the FilePath. -} -addUrlFile :: Bool -> URLString -> Url.UrlInfo -> FilePath -> Annex (Maybe Key) -addUrlFile relaxed url urlinfo file +addUrlFile :: Maybe AddUrlOptions -> Bool -> URLString -> Url.UrlInfo -> FilePath -> Annex (Maybe Key) +addUrlFile mo relaxed url urlinfo file | relaxed = checkCanAdd file $ do liftIO $ createDirectoryIfMissing True (parentDir file) nodownload url urlinfo file @@ -247,11 +248,11 @@ addUrlFile relaxed url urlinfo file ( checkCanAdd file $ do liftIO $ createDirectoryIfMissing True (parentDir file) nodownload url urlinfo file - , downloadWeb url urlinfo file + , downloadWeb mo url urlinfo file ) -downloadWeb :: URLString -> Url.UrlInfo -> FilePath -> Annex (Maybe Key) -downloadWeb url urlinfo file = +downloadWeb :: Maybe AddUrlOptions -> URLString -> Url.UrlInfo -> FilePath -> Annex (Maybe Key) +downloadWeb mo url urlinfo file = go =<< downloadWith' downloader urlkey webUUID url (AssociatedFile (Just file)) where urlkey = addSizeUrlKey urlinfo $ Backend.URL.fromUrl url Nothing @@ -279,7 +280,9 @@ downloadWeb url urlinfo file = case dl of Right (Just mediafile) -> do pruneTmpWorkDirBefore tmp (liftIO . nukeFile) - let dest = takeFileName mediafile + let dest = if isJust (fileOption <$> mo) + then file + else takeFileName mediafile showDestinationFile dest addWorkTree webUUID mediaurl dest mediakey (Just mediafile) return $ Right $ Just mediakey diff --git a/Command/ImportFeed.hs b/Command/ImportFeed.hs index 57daa22f8..c860f637f 100644 --- a/Command/ImportFeed.hs +++ b/Command/ImportFeed.hs @@ -170,7 +170,7 @@ performDownload opts cache todownload = case location todownload of urlinfo <- if relaxedOption opts then pure Url.assumeUrlExists else Url.withUrlOptions (Url.getUrlInfo url) - maybeToList <$> addUrlFile (relaxedOption opts) url urlinfo f + maybeToList <$> addUrlFile Nothing (relaxedOption opts) url urlinfo f else do res <- tryNonAsync $ maybe (error $ "unable to checkUrl of " ++ Remote.name r) |