diff options
author | Yuchen Pei <hi@ypei.me> | 2022-09-13 13:10:32 +1000 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-09-13 13:10:32 +1000 |
commit | e1e795e8152c435ca408de3c373c6687f4bf415e (patch) | |
tree | 682102787d89e105a48aa61f7db1920e2fc2e434 /app/Main.hs | |
parent | e61c4e2ad09772108efa4407ecaa371f3f26beae (diff) |
separating out video type
Diffstat (limited to 'app/Main.hs')
-rw-r--r-- | app/Main.hs | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/app/Main.hs b/app/Main.hs index 82acb3c..005b63a 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -12,11 +12,13 @@ import Control.Lens ( (^.) ) import Control.Monad.IO.Class ( liftIO ) import Data.Aeson ( (.:) + , (.=) , FromJSON(..) - , ToJSON + , ToJSON(..) , Value(..) , decode , encode + , object ) import qualified Data.Aeson.KeyMap as KM ( KeyMap @@ -180,33 +182,11 @@ getInfobox name = do searchYt :: Text -> Handler [Video] searchYt query = do (_, Just hout, _, _) <- liftIO $ createProcess - (proc "yt-dlp" ["-j", "ytsearch3:" <> T.unpack query]) + (proc "yt-dlp" ["-j", "ytsearch10:" <> T.unpack query]) { std_out = CreatePipe } liftIO $ (catMaybes . map decode . BSL.lines) <$> BSL.hGetContents hout -data Video = Video - { vid :: Text - , vtitle :: Text - , vdesc :: Text - , vduration :: Int - } - deriving (Eq, Show, Generic) - -instance FromJSON Video where - parseJSON (Object o) = - Video - <$> o - .: "id" - <*> o - .: "title" - <*> o - .: "description" - <*> o - .: "duration" - -instance ToJSON Video - app :: Application app = serve api server |