Packages

Library to parse SCTE-35 data.

Current section

Files

Jump to
scte35 test scte35_test.exs
Raw

test/scte35_test.exs

defmodule Scte35Test do
use ExUnit.Case
doctest Scte35
@scte_string "/DBCAAAAAyiYAP/wBQb+lhn8CwAsAipDVUVJAAAAAX//AACkuwkOFm5ld3Nub3dfRVAwMzc5MTk0MTAyNTIiAwBa0YMA"
@scte_string2 "/DBCAAAAAyiYAP/wBQb+F2L2YAAsAipDVUVJAAAAAX//AAD3KiYOFm5ld3Nub3dfRVAwNDA2MjE2MDAwMDIiAQBmICS/"
@scte_string3 "/DBCAAAAAyiYAP/wBQb+HP0O2wAsAipDVUVJAAAAAX//AAD3KiYOFm5ld3Nub3dfRVAwNDA2MjE2MDAwMDIiAgD+QQuM"
@scte_string4 "/DBCAAAAAyiYAP/wBQb+mAlVvQAsAipDVUVJAAAAAX//AAD3TVcOFm5ld3Nub3dfRVAwMzc5MTk0MTAyNDAjAgAAAa7I"
@scte_string5 "/DBCAAAAAyiYAP/wBQb+lxIUIQAsAipDVUVJAAAAAX//AAD3TVcOFm5ld3Nub3dfRVAwMzc5MTk0MTAyNDAiAgBaKqT3"
test "#base2" do
assert Scte35.base2(113) == "01110001"
assert Scte35.base2(43) == "00101011"
assert Scte35.base2(255) == "11111111"
end
test "#binary_to_hex" do
assert Scte35.binary_to_hex("01110001") == "71"
assert Scte35.binary_to_hex("00101011") == "2B"
assert Scte35.binary_to_hex("11111111") == "FF"
end
test "#run" do
assert Scte35.run("data/nbc_ad_break.m3u8").segmentation_upid == "newsnow_EP037919410252"
assert Scte35.run("data/nbc_ad_break.m3u8").segment_num == 3
end
test "#get_scte_string_from" do
assert Scte35.get_scte_string_from("data/nbc_ad_break.m3u8") == @scte_string
end
test "#analyze_segmentation_descriptor" do
IO.puts("SCTE35 string: #{@scte_string}\n")
assert Scte35.analyze_segmentation_descriptor(@scte_string) == %{
byte1: 127,
byte1_reserved: "7F",
byte2: 255,
byte2_reserved: "1F",
delivery_not_restricted_flag: 1,
program_segmentation_flag: 1,
scte_string: @scte_string,
segment_num: 3,
segmentation_duration: "0000A4BB09",
segmentation_duration_flag: 1,
segmentation_event_cancel_indicator: 0,
segmentation_upid: "newsnow_EP037919410252",
remaining_bytes:
<<110, 101, 119, 115, 110, 111, 119, 95, 69, 80, 48, 51, 55, 57, 49, 57, 52, 49,
48, 50, 53, 50, 34, 3, 0, 90, 209, 131, 0>>
}
IO.puts("SCTE35 string: #{@scte_string2}\n")
assert Scte35.analyze_segmentation_descriptor(@scte_string2) == %{
byte1: 127,
byte1_reserved: "7F",
byte2: 255,
byte2_reserved: "1F",
delivery_not_restricted_flag: 1,
program_segmentation_flag: 1,
scte_string: @scte_string2,
segment_num: 1,
segmentation_duration: "0000F72A26",
segmentation_duration_flag: 1,
segmentation_event_cancel_indicator: 0,
segmentation_upid: "newsnow_EP040621600002",
remaining_bytes:
<<110, 101, 119, 115, 110, 111, 119, 95, 69, 80, 48, 52, 48, 54, 50, 49, 54, 48,
48, 48, 48, 50, 34, 1, 0, 102, 32, 36, 191>>
}
IO.puts("SCTE35 string: #{@scte_string3}\n")
assert Scte35.analyze_segmentation_descriptor(@scte_string3) == %{
byte1: 127,
byte1_reserved: "7F",
byte2: 255,
byte2_reserved: "1F",
delivery_not_restricted_flag: 1,
program_segmentation_flag: 1,
scte_string: @scte_string3,
segment_num: 2,
segmentation_duration: "0000F72A26",
segmentation_duration_flag: 1,
segmentation_event_cancel_indicator: 0,
segmentation_upid: "newsnow_EP040621600002",
remaining_bytes:
<<110, 101, 119, 115, 110, 111, 119, 95, 69, 80, 48, 52, 48, 54, 50, 49, 54, 48,
48, 48, 48, 50, 34, 2, 0, 254, 65, 11, 140>>
}
IO.puts("SCTE35 string: #{@scte_string4}\n")
assert Scte35.analyze_segmentation_descriptor(@scte_string4) == %{
byte1: 127,
byte1_reserved: "7F",
byte2: 255,
byte2_reserved: "1F",
delivery_not_restricted_flag: 1,
program_segmentation_flag: 1,
scte_string: @scte_string4,
segment_num: 2,
segmentation_duration: "0000F74D57",
segmentation_duration_flag: 1,
segmentation_event_cancel_indicator: 0,
segmentation_upid: "newsnow_EP037919410240",
remaining_bytes:
<<110, 101, 119, 115, 110, 111, 119, 95, 69, 80, 48, 51, 55, 57, 49, 57, 52, 49,
48, 50, 52, 48, 35, 2, 0, 0, 1, 174, 200>>
}
IO.puts("SCTE35 string: #{@scte_string5}\n")
assert Scte35.analyze_segmentation_descriptor(@scte_string5) == %{
byte1: 127,
byte1_reserved: "7F",
byte2: 255,
byte2_reserved: "1F",
delivery_not_restricted_flag: 1,
program_segmentation_flag: 1,
scte_string: @scte_string5,
segment_num: 2,
segmentation_duration: "0000F74D57",
segmentation_duration_flag: 1,
segmentation_event_cancel_indicator: 0,
segmentation_upid: "newsnow_EP037919410240",
remaining_bytes:
<<110, 101, 119, 115, 110, 111, 119, 95, 69, 80, 48, 51, 55, 57, 49, 57, 52, 49,
48, 50, 52, 48, 34, 2, 0, 90, 42, 164, 247>>
}
end
test "#till_segmentation_event_id" do
assert_raise ArgumentError, "Invalid SCTE35 string (function 2)", fn ->
%{scte_string: "blah"} |> Scte35.till_segmentation_event_id()
end
bytes =
<<127, 255, 0, 0, 164, 187, 9, 14, 22, 110, 101, 119, 115, 110, 111, 119, 95, 69, 80, 48,
51, 55, 57, 49, 57, 52, 49, 48, 50, 53, 50, 34, 3, 0, 90, 209, 131, 0>>
assert Scte35.till_segmentation_event_id(%{scte_string: @scte_string}).remaining_bytes == bytes
end
end
# 2 output examples:
# SCTE35 string: /DBCAAAAAyiYAP/wBQb+lhn8CwAsAipDVUVJAAAAAX//AACkuwkOFm5ld3Nub3dfRVAwMzc5MTk0MTAyNTIiAwBa0YMA
# segmentation_event_id (decimals): <<0, 0, 0, 1>>
# Start of segmentation_event_cancel_indicator:
# Remaining Bytes (decimals): <<127, 255, 0, 0, 164, 187, 9, 14, 22, 110, 101, 119, 115, 110, 111, 119, 95,
# 69, 80, 48, 51, 55, 57, 49, 57, 52, 49, 48, 50, 53, 50, 34, 3, 0, 90, 209,
# 131, 0>>
# Byte 1: Decimal = 127. Binary = 01111111
# segmentation_event_cancel_indicator (binary): 0
# reserved (hex): 7F
# Byte 2: Decimal = 255. Binary = 11111111
# program_segmentation_flag (binary): 1
# segmentation_duration_flag (binary): 1
# delivery_not_restricted_flag (binary): 1
# reserved (hex): 1F
# segmentation_duration (hex): 0000A4BB09
# segmentation_upid_type (hex): 0E
# segmentation_upid_length (decimal): 22
# Start of segmentation_upid:
# Remaining Bytes (decimals): <<110, 101, 119, 115, 110, 111, 119, 95, 69, 80, 48, 51, 55, 57, 49, 57, 52, 49,
# 48, 50, 53, 50, 34, 3, 0, 90, 209, 131, 0>>
# --> segmentation_upid: newsnow_EP037919410252
# --> segment_num (decimal): 3
# _____________________________
# SCTE35 string: /DBCAAAAAyiYAP/wBQb+F2L2YAAsAipDVUVJAAAAAX//AAD3KiYOFm5ld3Nub3dfRVAwNDA2MjE2MDAwMDIiAQBmICS/
# segmentation_event_id (decimals): <<0, 0, 0, 1>>
# Start of segmentation_event_cancel_indicator:
# Remaining Bytes (decimals): <<127, 255, 0, 0, 247, 42, 38, 14, 22, 110, 101, 119, 115, 110, 111, 119, 95,
# 69, 80, 48, 52, 48, 54, 50, 49, 54, 48, 48, 48, 48, 50, 34, 1, 0, 102, 32, 36,
# 191>>
# Byte 1: Decimal = 127. Binary = 01111111
# segmentation_event_cancel_indicator (binary): 0
# reserved (hex): 7F
# Byte 2: Decimal = 255. Binary = 11111111
# program_segmentation_flag (binary): 1
# segmentation_duration_flag (binary): 1
# delivery_not_restricted_flag (binary): 1
# reserved (hex): 1F
# segmentation_duration (hex): 0000F72A26
# segmentation_upid_type (hex): 0E
# segmentation_upid_length (decimal): 22
# Start of segmentation_upid:
# Remaining Bytes (decimals): <<110, 101, 119, 115, 110, 111, 119, 95, 69, 80, 48, 52, 48, 54, 50, 49, 54, 48,
# 48, 48, 48, 50, 34, 1, 0, 102, 32, 36, 191>>
# --> segmentation_upid: newsnow_EP040621600002
# --> segment_num (decimal): 1