addurl --file youtube-dl reversion fix

addurl: Fix reversion in 7.20190322 that made --file not be honored when
youtube-dl was used to download media.

8758f9c561 was on the right track, but missed that | otherwise prevented
the code it added from being used.

Also, refactored out a common function.

This commit was sponsored by Graham Spencer on Patreon.
This commit is contained in:
Joey Hess 2020-08-25 12:56:38 -04:00
parent 27329f0bb1
commit 2ca1ff62dc
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 19 additions and 20 deletions

View file

@ -7,6 +7,8 @@ git-annex (8.20200815) UNRELEASED; urgency=medium
* Display warning when external special remote does not start up * Display warning when external special remote does not start up
properly, or is not usable. properly, or is not usable.
* stack.yaml: Updated to lts-16.10. * stack.yaml: Updated to lts-16.10.
* addurl: Fix reversion in 7.20190322 that made --file not be honored
when youtube-dl was used to download media.
-- Joey Hess <id@joeyh.name> Fri, 14 Aug 2020 14:57:45 -0400 -- Joey Hess <id@joeyh.name> Fri, 14 Aug 2020 14:57:45 -0400

View file

@ -304,8 +304,6 @@ downloadWeb addunlockedmatcher o url urlinfo file =
urlkey = addSizeUrlKey urlinfo $ Backend.URL.fromUrl url Nothing urlkey = addSizeUrlKey urlinfo $ Backend.URL.fromUrl url Nothing
downloader f p = Url.withUrlOptions $ downloadUrl urlkey p [url] f downloader f p = Url.withUrlOptions $ downloadUrl urlkey p [url] f
go Nothing = return Nothing go Nothing = return Nothing
-- If we downloaded a html file, try to use youtube-dl to
-- extract embedded media.
go (Just tmp) = ifM (pure (not (rawOption o)) <&&> liftIO (isHtml <$> readFile tmp)) go (Just tmp) = ifM (pure (not (rawOption o)) <&&> liftIO (isHtml <$> readFile tmp))
( tryyoutubedl tmp ( tryyoutubedl tmp
, normalfinish tmp , normalfinish tmp
@ -314,20 +312,14 @@ downloadWeb addunlockedmatcher o url urlinfo file =
showDestinationFile file showDestinationFile file
createWorkTreeDirectory (parentDir file) createWorkTreeDirectory (parentDir file)
Just <$> finishDownloadWith addunlockedmatcher tmp webUUID url file Just <$> finishDownloadWith addunlockedmatcher tmp webUUID url file
tryyoutubedl tmp -- Ask youtube-dl what filename it will download first,
-- Ask youtube-dl what filename it will download -- so it's only used when the file contains embedded media.
-- first, and check if that is already an annexed file, tryyoutubedl tmp = youtubeDlFileNameHtmlOnly url >>= \case
-- to avoid unnecessary work in that case. Right mediafile ->
| otherwise = youtubeDlFileNameHtmlOnly url >>= \case let f = youtubeDlDestFile o file mediafile
Right dest -> ifAnnexed (toRawFilePath dest) in ifAnnexed (toRawFilePath f)
(alreadyannexed dest) (alreadyannexed f)
(dl dest) (dl f)
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 Left _ -> normalfinish tmp
where where
dl dest = withTmpWorkDir mediakey $ \workdir -> do dl dest = withTmpWorkDir mediakey $ \workdir -> do
@ -467,13 +459,16 @@ nodownloadWeb addunlockedmatcher o url urlinfo file
let key = Backend.URL.fromUrl url (Url.urlSize urlinfo) let key = Backend.URL.fromUrl url (Url.urlSize urlinfo)
nodownloadWeb' addunlockedmatcher url key file nodownloadWeb' addunlockedmatcher url key file
usemedia mediafile = do usemedia mediafile = do
let dest = if isJust (fileOption o) let dest = youtubeDlDestFile o file mediafile
then file
else takeFileName mediafile
let mediaurl = setDownloader url YoutubeDownloader let mediaurl = setDownloader url YoutubeDownloader
let mediakey = Backend.URL.fromUrl mediaurl Nothing let mediakey = Backend.URL.fromUrl mediaurl Nothing
nodownloadWeb' addunlockedmatcher mediaurl mediakey dest nodownloadWeb' addunlockedmatcher mediaurl mediakey dest
youtubeDlDestFile :: DownloadOptions -> FilePath -> FilePath -> FilePath
youtubeDlDestFile o destfile mediafile
| isJust (fileOption o) = destfile
| otherwise = takeFileName mediafile
nodownloadWeb' :: AddUnlockedMatcher -> URLString -> Key -> FilePath -> Annex (Maybe Key) nodownloadWeb' :: AddUnlockedMatcher -> URLString -> Key -> FilePath -> Annex (Maybe Key)
nodownloadWeb' addunlockedmatcher url key file = checkCanAdd file $ do nodownloadWeb' addunlockedmatcher url key file = checkCanAdd file $ do
showDestinationFile file showDestinationFile file

View file

@ -50,3 +50,5 @@ I only recently started using the web special remote stuff, and really like it;
### Have you had any luck using git-annex before? ### Have you had any luck using git-annex before?
Yes, I've used it for several years for all sorts of things, and it just gets better and better. Yes, I've used it for several years for all sorts of things, and it just gets better and better.
> [[fixed|done]] --[[Joey]]