converted ImportFeed
This commit is contained in:
parent
aff4b9a3dc
commit
9c1a42873c
3 changed files with 47 additions and 36 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
(paramRepeating paramUrl) (seek <$$> optParser)
|
||||
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue