stream parsing
This commit is contained in:
29
app/Main.hs
29
app/Main.hs
@@ -13,6 +13,7 @@ import Data.Text (pack, splitOn, unpack)
|
||||
import Data.Time
|
||||
import GHC.Generics
|
||||
import Text.Read (readMaybe)
|
||||
import Control.Applicative (asum)
|
||||
|
||||
data ContentType
|
||||
= Movie
|
||||
@@ -107,7 +108,7 @@ data StreamDetails = StreamDetails
|
||||
data StreamSource
|
||||
= UrlSource Url
|
||||
| YoutubeSource String
|
||||
| TorrentSource
|
||||
| TorrentSource String Int
|
||||
| ExternalSource MetaLink
|
||||
deriving (Show, Generic, FromJSON, ToJSON)
|
||||
|
||||
@@ -115,7 +116,31 @@ data Stream = Stream
|
||||
{ details :: StreamDetails,
|
||||
source :: StreamSource
|
||||
}
|
||||
deriving (Show, Generic, FromJSON, ToJSON)
|
||||
deriving (Show, Generic, ToJSON)
|
||||
|
||||
instance FromJSON Stream where
|
||||
parseJSON (Object v) =
|
||||
Stream
|
||||
<$> streamDetails
|
||||
<*> streamSource
|
||||
where
|
||||
behaviorHints = v .: "behaviorHints"
|
||||
behaviorHints :: Parser Object
|
||||
streamDetails = StreamDetails
|
||||
<$> v .: "name"
|
||||
<*> v .: "title"
|
||||
<*> v .: "description"
|
||||
<*> v .: "subtitles"
|
||||
<*> (behaviorHints >>= (.: "bingeGroup"))
|
||||
<*> (behaviorHints >>= (.: "videoHash"))
|
||||
<*> (behaviorHints >>= (.: "videoSize"))
|
||||
<*> (behaviorHints >>= (.: "filename"))
|
||||
streamSource = asum [
|
||||
UrlSource <$> v .: "url",
|
||||
YoutubeSource <$> v.: "ytId",
|
||||
ExternalSource <$> v .: "externalUrl",
|
||||
TorrentSource <$> v .: "infoHash" <*> v .: "fileIdx"]
|
||||
parseJSON _ = fail "expected an object"
|
||||
|
||||
data Video = Video
|
||||
{ id :: ContentID,
|
||||
|
||||
Reference in New Issue
Block a user