2021-01-24 15:26:07 +01:00
|
|
|
{-|
|
|
|
|
Module : Command.All
|
|
|
|
Description : Generate podcast for all audiobooks
|
|
|
|
Copyright : (c) Raffaele Mignone 2021
|
|
|
|
License : GPL-3
|
|
|
|
Maintainer : git@norangeb.it
|
|
|
|
|
|
|
|
This module exposes the command that generates podcast feeds for all the
|
|
|
|
audiobooks in Ad Alta Voce library.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.All(generateAll) where
|
|
|
|
|
|
|
|
import Control.Monad ( join )
|
|
|
|
import Data.Maybe ( catMaybes )
|
|
|
|
import Text.HTML.Scalpel ( scrapeURL, URL )
|
2021-01-24 19:11:10 +01:00
|
|
|
import Command.Single ( singleWithAuthor )
|
2021-01-24 15:26:07 +01:00
|
|
|
import Scraper.Playlist
|
2021-01-24 19:11:10 +01:00
|
|
|
( playlistPageNumbersScraper, playlistInfosScraper )
|
2021-01-24 15:26:07 +01:00
|
|
|
|
|
|
|
baseUrl = "https://www.raiplayradio.it"
|
|
|
|
playlistBaseUrl = "https://www.raiplayradio.it/programmi/adaltavoce/archivio/audiolibri/tutte/"
|
|
|
|
|
2021-01-24 19:11:10 +01:00
|
|
|
scrapeAudiobooksUrl :: IO (Maybe [(URL, String)])
|
2021-01-24 15:26:07 +01:00
|
|
|
scrapeAudiobooksUrl = do
|
|
|
|
pageNumbers <- scrapeURL playlistBaseUrl playlistPageNumbersScraper
|
|
|
|
case scrapePlaylistPages pageNumbers of
|
|
|
|
Nothing -> return Nothing
|
|
|
|
Just urls -> Just <$> urls
|
|
|
|
|
2021-01-24 19:11:10 +01:00
|
|
|
scrapePlaylistPages :: Maybe [String] -> Maybe (IO [(URL, String)])
|
2021-01-24 15:26:07 +01:00
|
|
|
scrapePlaylistPages pageNumbers = do
|
|
|
|
pageNumbers' <- pageNumbers
|
|
|
|
let playlistUrls = map (playlistBaseUrl ++) pageNumbers'
|
2021-01-24 19:11:10 +01:00
|
|
|
audiobookInfos = mapM (`scrapeURL` playlistInfosScraper) playlistUrls
|
|
|
|
flatAudiobookInfos = join . catMaybes <$> audiobookInfos
|
|
|
|
return $ map (\(u, a) -> (concatBaseUrl u, a)) <$> flatAudiobookInfos
|
|
|
|
where
|
|
|
|
concatBaseUrl :: URL -> URL
|
|
|
|
concatBaseUrl = (++) baseUrl
|
2021-01-24 15:26:07 +01:00
|
|
|
|
|
|
|
generateAll :: String -> IO ()
|
|
|
|
generateAll outdir = do
|
2021-01-24 19:11:10 +01:00
|
|
|
infos <- scrapeAudiobooksUrl
|
|
|
|
case infos of
|
2021-01-24 15:26:07 +01:00
|
|
|
Nothing -> putStrLn "Error"
|
2021-01-24 19:11:10 +01:00
|
|
|
Just infos' -> do
|
|
|
|
mapM_ (\(url, author) -> singleWithAuthor url outdir author) infos'
|
2021-01-24 15:26:07 +01:00
|
|
|
putStrLn "All done.\nEnjoy your books!"
|