stream parsing

This commit is contained in:
senstella
2026-02-12 02:19:01 +09:00
parent a2ca530a14
commit 0e53fe3ff3

View File

@@ -13,6 +13,7 @@ import Data.Text (pack, splitOn, unpack)
import Data.Time import Data.Time
import GHC.Generics import GHC.Generics
import Text.Read (readMaybe) import Text.Read (readMaybe)
import Control.Applicative (asum)
data ContentType data ContentType
= Movie = Movie
@@ -107,7 +108,7 @@ data StreamDetails = StreamDetails
data StreamSource data StreamSource
= UrlSource Url = UrlSource Url
| YoutubeSource String | YoutubeSource String
| TorrentSource | TorrentSource String Int
| ExternalSource MetaLink | ExternalSource MetaLink
deriving (Show, Generic, FromJSON, ToJSON) deriving (Show, Generic, FromJSON, ToJSON)
@@ -115,7 +116,31 @@ data Stream = Stream
{ details :: StreamDetails, { details :: StreamDetails,
source :: StreamSource 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 data Video = Video
{ id :: ContentID, { id :: ContentID,