Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Add subtitlesTracks event (#20)
Browse files Browse the repository at this point in the history
* Improve error messages

* Add `subtitlesTracks` event
  • Loading branch information
tfausak authored May 18, 2023
1 parent 7503c6f commit 159f6c0
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 10 deletions.
2 changes: 2 additions & 0 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Jawa.Event.Seek",
"Jawa.Event.Seeked",
"Jawa.Event.SetupError",
"Jawa.Event.SubtitlesTracks",
"Jawa.Event.Time",
"Jawa.Event.UserActive",
"Jawa.Event.UserInactive",
Expand All @@ -59,6 +60,7 @@
"Jawa.SeekRange",
"Jawa.Source",
"Jawa.State",
"Jawa.SubtitleTrack",
"Jawa.Track",
"Jawa.TrackKind",
"Jawa.Viewable"
Expand Down
6 changes: 6 additions & 0 deletions src/Jawa/Event.elm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Jawa.Event.Resize
import Jawa.Event.Seek
import Jawa.Event.Seeked
import Jawa.Event.SetupError
import Jawa.Event.SubtitlesTracks
import Jawa.Event.Time
import Jawa.Event.UserActive
import Jawa.Event.UserInactive
Expand Down Expand Up @@ -86,6 +87,7 @@ type Event
| Seek Jawa.Event.Seek.Seek
| Seeked Jawa.Event.Seeked.Seeked
| SetupError Jawa.Event.SetupError.SetupError
| SubtitlesTracks Jawa.Event.SubtitlesTracks.SubtitlesTracks
| Time Jawa.Event.Time.Time
| UserActive Jawa.Event.UserActive.UserActive
| UserInactive Jawa.Event.UserInactive.UserInactive
Expand Down Expand Up @@ -148,6 +150,7 @@ decoders =
, ( Jawa.Event.Seek.tag, Json.Decode.map Seek Jawa.Event.Seek.decoder )
, ( Jawa.Event.Seeked.tag, Json.Decode.map Seeked Jawa.Event.Seeked.decoder )
, ( Jawa.Event.SetupError.tag, Json.Decode.map SetupError Jawa.Event.SetupError.decoder )
, ( Jawa.Event.SubtitlesTracks.tag, Json.Decode.map SubtitlesTracks Jawa.Event.SubtitlesTracks.decoder )
, ( Jawa.Event.Time.tag, Json.Decode.map Time Jawa.Event.Time.decoder )
, ( Jawa.Event.UserActive.tag, Json.Decode.map UserActive Jawa.Event.UserActive.decoder )
, ( Jawa.Event.UserInactive.tag, Json.Decode.map UserInactive Jawa.Event.UserInactive.decoder )
Expand Down Expand Up @@ -261,6 +264,9 @@ encode event =
SetupError x ->
encodeWith Jawa.Event.SetupError.tag Jawa.Event.SetupError.encode x

SubtitlesTracks x ->
encodeWith Jawa.Event.SubtitlesTracks.tag Jawa.Event.SubtitlesTracks.encode x

Time x ->
encodeWith Jawa.Event.Time.tag Jawa.Event.Time.encode x

Expand Down
42 changes: 42 additions & 0 deletions src/Jawa/Event/SubtitlesTracks.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Jawa.Event.SubtitlesTracks exposing (SubtitlesTracks, decoder, encode, tag)

{-|
@docs SubtitlesTracks, decoder, encode, tag
-}

import Jawa.SubtitleTrack
import Json.Decode
import Json.Encode


{-| This event is not documented.
-}
type alias SubtitlesTracks =
{ tracks : List Jawa.SubtitleTrack.SubtitleTrack
}


{-| A JSON decoder.
-}
decoder : Json.Decode.Decoder SubtitlesTracks
decoder =
Json.Decode.map SubtitlesTracks
(Json.Decode.field "tracks" (Json.Decode.list Jawa.SubtitleTrack.decoder))


{-| A JSON encoder.
-}
encode : SubtitlesTracks -> Json.Encode.Value
encode x =
Json.Encode.object
[ ( "tracks", Json.Encode.list Jawa.SubtitleTrack.encode x.tracks )
]


{-| The tag that describes this type.
-}
tag : String
tag =
"subtitlesTracks"
2 changes: 1 addition & 1 deletion src/Jawa/MediaType.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fromString string =
Ok Video

_ ->
Err <| "invalid MediaType: " ++ string
Err <| "unknown MediaType: " ++ string


{-| A JSON encoder.
Expand Down
2 changes: 1 addition & 1 deletion src/Jawa/PauseReason.elm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fromString string =
Ok Viewable

_ ->
Err <| "invalid PauseReason: " ++ string
Err <| "unknown PauseReason: " ++ string


{-| A JSON encoder.
Expand Down
2 changes: 1 addition & 1 deletion src/Jawa/PlayReason.elm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fromString string =
Ok RelatedInteraction

_ ->
Err <| "invalid PlayReason: " ++ string
Err <| "unknown PlayReason: " ++ string


{-| A JSON encoder.
Expand Down
2 changes: 1 addition & 1 deletion src/Jawa/Preload.elm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fromString string =
Ok None

_ ->
Err <| "invalid Preload: " ++ string
Err <| "unknown Preload: " ++ string


{-| A JSON encoder.
Expand Down
2 changes: 1 addition & 1 deletion src/Jawa/QualityMode.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fromString string =
Ok Manual

_ ->
Err <| "invalid QualityMode: " ++ string
Err <| "unknown QualityMode: " ++ string


{-| A JSON encoder.
Expand Down
2 changes: 1 addition & 1 deletion src/Jawa/QualityReason.elm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fromString string =
Ok InitialChoice

_ ->
Err <| "invalid QualityReason: " ++ string
Err <| "unknown QualityReason: " ++ string


{-| A JSON encoder.
Expand Down
2 changes: 1 addition & 1 deletion src/Jawa/State.elm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fromString string =
Ok Stalled

_ ->
Err <| "invalid State: " ++ string
Err <| "unknown State: " ++ string


{-| A JSON encoder.
Expand Down
53 changes: 53 additions & 0 deletions src/Jawa/SubtitleTrack.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module Jawa.SubtitleTrack exposing (SubtitleTrack, decoder, encode)

{-|
@docs SubtitleTrack, decoder, encode
-}

import Jawa.Metadata
import Json.Decode
import Json.Encode


{-| This type is not documented.
-}
type alias SubtitleTrack =
{ data : List Jawa.Metadata.Metadata
, default : Bool
, id : String
, kind : String
, label : String
, name : String
, subtitleTrack : Jawa.Metadata.Metadata
}


{-| A JSON decoder.
-}
decoder : Json.Decode.Decoder SubtitleTrack
decoder =
Json.Decode.map7 SubtitleTrack
(Json.Decode.field "data" (Json.Decode.list Jawa.Metadata.decoder))
(Json.Decode.field "default" Json.Decode.bool)
(Json.Decode.field "_id" Json.Decode.string)
(Json.Decode.field "kind" Json.Decode.string)
(Json.Decode.field "label" Json.Decode.string)
(Json.Decode.field "name" Json.Decode.string)
(Json.Decode.field "subtitleTrack" Jawa.Metadata.decoder)


{-| A JSON encoder.
-}
encode : SubtitleTrack -> Json.Encode.Value
encode x =
Json.Encode.object
[ ( "data", Json.Encode.list Jawa.Metadata.encode x.data )
, ( "default", Json.Encode.bool x.default )
, ( "_id", Json.Encode.string x.id )
, ( "kind", Json.Encode.string x.kind )
, ( "label", Json.Encode.string x.label )
, ( "name", Json.Encode.string x.name )
, ( "subtitleTrack", Jawa.Metadata.encode x.subtitleTrack )
]
2 changes: 1 addition & 1 deletion src/Jawa/TrackKind.elm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fromString string =
Ok Thumbnails

_ ->
Err <| "invalid TrackKind: " ++ string
Err <| "unknown TrackKind: " ++ string


{-| A JSON encoder.
Expand Down
2 changes: 1 addition & 1 deletion src/Jawa/Viewable.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fromInt int =
Ok Visible

_ ->
Err <| "invalid Viewable: " ++ String.fromInt int
Err <| "unknown Viewable: " ++ String.fromInt int


{-| A JSON encoder.
Expand Down
31 changes: 31 additions & 0 deletions tests/Jawa/Event/SubtitlesTracksTest.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Jawa.Event.SubtitlesTracksTest exposing
( fuzzer
, test
)

import Fuzz
import Jawa.Event.SubtitlesTracks
import Jawa.Extra.Test
import Jawa.SubtitleTrackTest
import Test


test : Test.Test
test =
Test.describe "Jawa.Event.SubtitlesTracks"
[ Jawa.Extra.Test.fuzzCodec "round trips" Jawa.Event.SubtitlesTracks.decoder Jawa.Event.SubtitlesTracks.encode fuzzer
, Jawa.Extra.Test.testCodec "works"
Jawa.Event.SubtitlesTracks.decoder
Jawa.Event.SubtitlesTracks.encode
""" {
"tracks": []
} """
{ tracks = []
}
]


fuzzer : Fuzz.Fuzzer Jawa.Event.SubtitlesTracks.SubtitlesTracks
fuzzer =
Fuzz.map Jawa.Event.SubtitlesTracks.SubtitlesTracks
(Fuzz.listOfLengthBetween 0 2 Jawa.SubtitleTrackTest.fuzzer)
13 changes: 13 additions & 0 deletions tests/Jawa/EventTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Jawa.Event.ResizeTest
import Jawa.Event.SeekTest
import Jawa.Event.SeekedTest
import Jawa.Event.SetupErrorTest
import Jawa.Event.SubtitlesTracksTest
import Jawa.Event.TimeTest
import Jawa.Event.UserActiveTest
import Jawa.Event.UserInactiveTest
Expand Down Expand Up @@ -468,6 +469,17 @@ test =
, message = ""
}
)
, Jawa.Extra.Test.testCodec "works with subtitlesTracks"
Jawa.Event.decoder
Jawa.Event.encode
""" {
"tracks": [],
"type": "subtitlesTracks"
} """
(Jawa.Event.SubtitlesTracks
{ tracks = []
}
)
, Jawa.Extra.Test.testCodec "works with time"
Jawa.Event.decoder
Jawa.Event.encode
Expand Down Expand Up @@ -597,6 +609,7 @@ fuzzer =
, Fuzz.map Jawa.Event.Seek Jawa.Event.SeekTest.fuzzer
, Fuzz.map Jawa.Event.Seeked Jawa.Event.SeekedTest.fuzzer
, Fuzz.map Jawa.Event.SetupError Jawa.Event.SetupErrorTest.fuzzer
, Fuzz.map Jawa.Event.SubtitlesTracks Jawa.Event.SubtitlesTracksTest.fuzzer
, Fuzz.map Jawa.Event.Time Jawa.Event.TimeTest.fuzzer
, Fuzz.map Jawa.Event.UserActive Jawa.Event.UserActiveTest.fuzzer
, Fuzz.map Jawa.Event.UserInactive Jawa.Event.UserInactiveTest.fuzzer
Expand Down
2 changes: 1 addition & 1 deletion tests/Jawa/MetadataTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test =

fuzzer : Fuzz.Fuzzer Jawa.Metadata.Metadata
fuzzer =
Fuzz.map Jawa.Metadata.Metadata (fuzzerWith 32)
Fuzz.map Jawa.Metadata.Metadata (fuzzerWith 16)


fuzzerWith : Int -> Fuzz.Fuzzer Json.Encode.Value
Expand Down
51 changes: 51 additions & 0 deletions tests/Jawa/SubtitleTrackTest.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module Jawa.SubtitleTrackTest exposing
( fuzzer
, test
)

import Fuzz
import Jawa.Extra.Test
import Jawa.Metadata
import Jawa.MetadataTest
import Jawa.SubtitleTrack
import Json.Encode
import Test


test : Test.Test
test =
Test.describe "Jawa.SubtitleTrack"
[ Jawa.Extra.Test.fuzzCodec "round trips" Jawa.SubtitleTrack.decoder Jawa.SubtitleTrack.encode fuzzer
, Jawa.Extra.Test.testCodec "works"
Jawa.SubtitleTrack.decoder
Jawa.SubtitleTrack.encode
""" {
"data": [],
"default": false,
"_id": "a",
"kind": "b",
"label": "c",
"name": "d",
"subtitleTrack": {}
} """
{ data = []
, default = False
, id = "a"
, kind = "b"
, label = "c"
, name = "d"
, subtitleTrack = Jawa.Metadata.Metadata (Json.Encode.object [])
}
]


fuzzer : Fuzz.Fuzzer Jawa.SubtitleTrack.SubtitleTrack
fuzzer =
Fuzz.map7 Jawa.SubtitleTrack.SubtitleTrack
(Fuzz.list Jawa.MetadataTest.fuzzer)
Fuzz.bool
Fuzz.string
Fuzz.string
Fuzz.string
Fuzz.string
Jawa.MetadataTest.fuzzer

0 comments on commit 159f6c0

Please sign in to comment.