-- | Compares unprocessed and processed feeds and downloads new
--   torrents.
cmdTorrents :: Config -> IO ()
cmdTorrents cfg = do
  feeds <- mapM parseFile =<< feedXmls cfg
  newFeeds <- mapM parseFile =<< newFeedXmls cfg

  let mergedFeeds = mergeAllFeeds feeds newFeeds

  -- Only download torrents that aren't already stored.
  forM_ mergedFeeds (\feed -> do
                  forM_ (items feed)
                    (\item -> do
                        putStrLn $ "Downloading " ++ enclosureUrl item
                        file <- getTorrentUnlessExists cfg item
                        case file of
                          Left e -> error . show $ e
                          Right filename -> putStrLn $ "Downloaded " ++ filename)
                  mv (newFeedPath cfg feed) (oldFeedPath cfg feed))

-- | Runs some tests.
cmdTorrents :: Config -> IO ()
cmdTorrents cfg = do
  feeds <- mapM parseFile =<< feedXmls cfg
  newFeeds <- mapM parseFile =<< newFeedXmls cfg

  let mergedFeeds = mergeAllFeeds feeds newFeeds

  -- Only download torrents that aren't already stored.
  forM_ mergedFeeds (\feed -> do
                  forM_ (items feed)
                    (\item -> do
                        putStrLn $ "Downloading " ++ enclosureUrl item
                        file <- getTorrentUnlessExists cfg item
                        case file of
                          Left e -> error . show $ e
                          Right filename -> putStrLn $ "Downloaded " ++ filename)
                  mv (newFeedPath cfg feed) (oldFeedPath cfg feed))

-- | Runs some tests.
cmdTorrents cfg = do
  feeds <- mapM parseFile =<< feedXmls cfg
  newFeeds <- mapM parseFile =<< newFeedXmls cfg

  let mergedFeeds = mergeAllFeeds feeds newFeeds

  -- Only download torrents that aren't already stored.
  forM_ mergedFeeds (\feed -> do
                  forM_ (items feed)
                    (\item -> do
                        putStrLn $ "Downloading " ++ enclosureUrl item
                        file <- getTorrentUnlessExists cfg item
                        case file of
                          Left e -> error . show $ e
                          Right filename -> putStrLn $ "Downloaded " ++ filename)
                  mv (newFeedPath cfg feed) (oldFeedPath cfg feed))

-- | Runs some tests.