summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CmdLine/GitAnnex.hs4
-rw-r--r--Command/AddUrl.hs22
-rw-r--r--Command/ImportFeed.hs59
3 files changed, 48 insertions, 37 deletions
diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs
index cdeac1b51..21e780398 100644
--- a/CmdLine/GitAnnex.hs
+++ b/CmdLine/GitAnnex.hs
@@ -84,7 +84,7 @@ import qualified Command.Sync
import qualified Command.Mirror
import qualified Command.AddUrl
#ifdef WITH_FEED
---import qualified Command.ImportFeed
+import qualified Command.ImportFeed
#endif
import qualified Command.RmUrl
--import qualified Command.Import
@@ -133,7 +133,7 @@ cmds =
, Command.Mirror.cmd
, Command.AddUrl.cmd
#ifdef WITH_FEED
--- , Command.ImportFeed.cmd
+ , Command.ImportFeed.cmd
#endif
, Command.RmUrl.cmd
-- , Command.Import.cmd
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs
index ed76e6c35..4ae80d9d4 100644
--- a/Command/AddUrl.hs
+++ b/Command/AddUrl.hs
@@ -61,14 +61,20 @@ optParser desc = AddUrlOptions
( long "pathdepth" <> metavar paramNumber
<> help "path components to use in filename"
))
- <*> switch
- ( long "relaxed"
- <> help "skip size check"
- )
- <*> switch
- ( long "raw"
- <> help "disable special handling for torrents, quvi, etc"
- )
+ <*> parseRelaxedOption
+ <*> parseRawOption
+
+parseRelaxedOption :: Parser Bool
+parseRelaxedOption = switch
+ ( long "relaxed"
+ <> help "skip size check"
+ )
+
+parseRawOption :: Parser Bool
+parseRawOption = switch
+ ( long "raw"
+ <> help "disable special handling for torrents, quvi, etc"
+ )
seek :: AddUrlOptions -> CommandSeek
seek o = forM_ (addUrls o) $ \u -> do
diff --git a/Command/ImportFeed.hs b/Command/ImportFeed.hs
index 5e4869b30..5afbb192a 100644
--- a/Command/ImportFeed.hs
+++ b/Command/ImportFeed.hs
@@ -30,7 +30,7 @@ import Types.UrlContents
import Logs.Web
import qualified Utility.Format
import Utility.Tmp
-import Command.AddUrl (addUrlFile, downloadRemoteFile, relaxedOption, rawOption)
+import Command.AddUrl (addUrlFile, downloadRemoteFile, parseRelaxedOption, parseRawOption)
import Annex.Perms
import Annex.UUID
import Backend.URL (fromUrl)
@@ -44,33 +44,38 @@ import Logs.MetaData
import Annex.MetaData
cmd :: Command
-cmd = notBareRepo $ withOptions [templateOption, relaxedOption, rawOption] $
+cmd = notBareRepo $
command "importfeed" SectionCommon "import files from podcast feeds"
- (paramRepeating paramUrl) (withParams seek)
-
-templateOption :: Option
-templateOption = fieldOption [] "template" paramFormat "template for filenames"
-
-seek :: CmdParams -> CommandSeek
-seek ps = do
- tmpl <- getOptionField templateOption return
- relaxed <- getOptionFlag relaxedOption
- raw <- getOptionFlag rawOption
- let opts = Opts { relaxedOpt = relaxed, rawOpt = raw }
- cache <- getCache tmpl
- withStrings (start opts cache) ps
-
-data Opts = Opts
- { relaxedOpt :: Bool
- , rawOpt :: Bool
+ (paramRepeating paramUrl) (seek <$$> optParser)
+
+data ImportFeedOptions = ImportFeedOptions
+ { feedUrls :: CmdParams
+ , templateOption :: Maybe String
+ , relaxedOption :: Bool
+ , rawOption :: Bool
}
-start :: Opts -> Cache -> URLString -> CommandStart
+optParser :: CmdParamsDesc -> Parser ImportFeedOptions
+optParser desc = ImportFeedOptions
+ <$> cmdParams desc
+ <*> optional (strOption
+ ( long "template" <> metavar paramFormat
+ <> help "template for filenames"
+ ))
+ <*> parseRelaxedOption
+ <*> parseRawOption
+
+seek :: ImportFeedOptions -> CommandSeek
+seek o = do
+ cache <- getCache (templateOption o)
+ withStrings (start o cache) (feedUrls o)
+
+start :: ImportFeedOptions -> Cache -> URLString -> CommandStart
start opts cache url = do
showStart "importfeed" url
next $ perform opts cache url
-perform :: Opts -> Cache -> URLString -> CommandPerform
+perform :: ImportFeedOptions -> Cache -> URLString -> CommandPerform
perform opts cache url = do
v <- findDownloads url
case v of
@@ -160,15 +165,15 @@ downloadFeed url
, return Nothing
)
-performDownload :: Opts -> Cache -> ToDownload -> Annex Bool
+performDownload :: ImportFeedOptions -> Cache -> ToDownload -> Annex Bool
performDownload opts cache todownload = case location todownload of
Enclosure url -> checkknown url $
rundownload url (takeExtension url) $ \f -> do
r <- Remote.claimingUrl url
- if Remote.uuid r == webUUID || rawOpt opts
+ if Remote.uuid r == webUUID || rawOption opts
then do
urlinfo <- Url.withUrlOptions (Url.getUrlInfo url)
- maybeToList <$> addUrlFile (relaxedOpt opts) url urlinfo f
+ maybeToList <$> addUrlFile (relaxedOption opts) url urlinfo f
else do
res <- tryNonAsync $ maybe
(error $ "unable to checkUrl of " ++ Remote.name r)
@@ -178,10 +183,10 @@ performDownload opts cache todownload = case location todownload of
Left _ -> return []
Right (UrlContents sz _) ->
maybeToList <$>
- downloadRemoteFile r (relaxedOpt opts) url f sz
+ downloadRemoteFile r (relaxedOption opts) url f sz
Right (UrlMulti l) -> do
kl <- forM l $ \(url', sz, subf) ->
- downloadRemoteFile r (relaxedOpt opts) url' (f </> fromSafeFilePath subf) sz
+ downloadRemoteFile r (relaxedOption opts) url' (f </> fromSafeFilePath subf) sz
return $ if all isJust kl
then catMaybes kl
else []
@@ -199,7 +204,7 @@ performDownload opts cache todownload = case location todownload of
let videourl = Quvi.linkUrl link
checkknown videourl $
rundownload videourl ("." ++ fromMaybe "m" (Quvi.linkSuffix link)) $ \f ->
- maybeToList <$> addUrlFileQuvi (relaxedOpt opts) quviurl videourl f
+ maybeToList <$> addUrlFileQuvi (relaxedOption opts) quviurl videourl f
#else
return False
#endif