Skip to content

Commit

Permalink
isolate descriptor data
Browse files Browse the repository at this point in the history
  • Loading branch information
futzu authored Nov 17, 2024
1 parent 0365b8d commit 4d5f5e3
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions threefive/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class SpliceDescriptor(SCTE35Base):
"""

def __init__(self, bites=None):

self.tag = None
self.descriptor_length = 0
self.identifier = "CUEI"
self.name = None
self.identifier = None
self.bites = bites
self.parse_tag_and_len()
self.parse_id()
Expand Down Expand Up @@ -148,7 +148,6 @@ def __init__(self, bites=None):
super().__init__(bites)
self.name = "Avail Descriptor"
self.tag = 0
self.identifier = "CUEI"
self.provider_avail_id = None

def decode(self):
Expand All @@ -170,7 +169,9 @@ def xml(self, ns="scte35"):
"""
Create a Node describing the AvailDescriptor
"""
ad = Node("AvailDescriptor", attrs={"providerAvailId": self.provider_avail_id}, ns=ns)
ad = Node(
"AvailDescriptor", attrs={"providerAvailId": self.provider_avail_id}, ns=ns
)
return ad

def from_xml(self, stuff):
Expand All @@ -190,7 +191,6 @@ def __init__(self, bites=None):
super().__init__(bites)
self.name = "DTMF Descriptor"
self.tag = 1
self.identifier = "CUEI"
self.preroll = None
self.dtmf_count = 0
self.dtmf_chars = None
Expand Down Expand Up @@ -227,7 +227,8 @@ def xml(self, ns="scte35"):
attrs={
"preroll": self.preroll,
"chars": "".join(self.dtmf_chars),
},ns=ns
},
ns=ns,
)
return dd

Expand All @@ -250,7 +251,6 @@ def __init__(self, bites=None):
super().__init__(bites)
self.tag = 3
self.name = "Time Descriptor"
self.identifier = "CUEI"
self.tai_seconds = 0
self.tai_ns = 0
self.utc_offset = 0
Expand Down Expand Up @@ -284,7 +284,8 @@ def xml(self, ns="scte35"):
"tai_seconds": self.tai_seconds,
"tai_ns": self.tai_ns,
"utc_offset": self.utc_offset,
}, ns=ns
},
ns=ns,
)
return td

Expand Down Expand Up @@ -316,9 +317,8 @@ def __init__(self, bites=None):
super().__init__(bites)
self.tag = 2
self.name = "Segmentation Descriptor"
self.identifier = "CUEI"
self.segmentation_event_id = None
self.segmentation_event_cancel_indicator = None
self.segmentation_event_id = None
self.segmentation_event_id_compliance_indicator = None
self.program_segmentation_flag = None
self.segmentation_duration_flag = None
Expand All @@ -328,11 +328,11 @@ def __init__(self, bites=None):
self.archive_allowed_flag = None
self.device_restrictions = None
self.segmentation_duration = None
self.segmentation_type_id = None
self.segmentation_message = None
self.segmentation_upid_length = None
self.segmentation_type_id = None
self.segmentation_upid_type = None
self.segmentation_upid_type_name = None
self.segmentation_upid_length = None
self.segmentation_upid = None
self.segment_num = None
self.segments_expected = None
Expand Down Expand Up @@ -373,7 +373,7 @@ def _decode_segmentation(self, bitbin):
the_upid = self.mk_the_upid(bitbin)
self.segmentation_upid_type_name, self.segmentation_upid = the_upid.decode()
self.segmentation_type_id = bitbin.as_int(8)
if self.segmentation_type_id in table22: # fix for #126
if self.segmentation_type_id in table22:
self.segmentation_message = table22[self.segmentation_type_id]
self._decode_segments(bitbin)

Expand Down Expand Up @@ -477,7 +477,7 @@ def _encode_segments(self, nbin):
nbin.add_int(0, 8)
nbin.add_int(0, 8)

def _xml_sub_segs(self,sd_attrs):
def _xml_sub_segs(self, sd_attrs):
if self.segmentation_type_id in self.SUB_SEG_TYPES:
sd_attrs["sub_segment_num"] = self.sub_segment_num
sd_attrs["sub_segments_expected"] = self.sub_segments_expected
Expand Down Expand Up @@ -513,7 +513,7 @@ def xml(self, ns="scte35"):
}
dr = Node("DeliveryRestrictions", attrs=dr_attrs, ns=ns)
sd.add_child(dr)
comment=f"{upid_map[self.segmentation_upid_type][0]}"
comment = f"{upid_map[self.segmentation_upid_type][0]}"
sd.add_comment(comment)
if isinstance(upid_node, list):
for node in upid_node:
Expand All @@ -528,12 +528,12 @@ def _xml_redecode(self, seg_upid):
before encoding to another format.
"""
if isinstance(seg_upid, str):
bites = b''
bites = b""
bitbin = None
try:
bites =bytes.fromhex(seg_upid)
bites = bytes.fromhex(seg_upid)
except ValueError:
bites= seg_upid.encode()
bites = seg_upid.encode()
bitbin = BitBin(bites)
self.segmentation_upid_length = len(bites)
the_upid = self.mk_the_upid(bitbin=bitbin)
Expand All @@ -542,14 +542,18 @@ def _xml_redecode(self, seg_upid):
def _upid_from_xml(self, stuff):
if "SegmentationUpid" in stuff:
if "segmentation_upid" not in stuff["SegmentationUpid"]:
self.segmentation_upid_type=0
self.segmentation_upid_length=0
self.segmentation_upid=''
self.segmentation_upid_type = 0
self.segmentation_upid_length = 0
self.segmentation_upid = ""
else:
seg_upid=stuff["SegmentationUpid"]["segmentation_upid"]
seg_upid = stuff["SegmentationUpid"]["segmentation_upid"]
if "segmentation_upid_type" in stuff["SegmentationUpid"]:
self.segmentation_upid_type= stuff["SegmentationUpid"]["segmentation_upid_type"]
self.segmentation_upid_type_name = upid_map[self.segmentation_upid_type][0]
self.segmentation_upid_type = stuff["SegmentationUpid"][
"segmentation_upid_type"
]
self.segmentation_upid_type_name = upid_map[
self.segmentation_upid_type
][0]
self._xml_redecode(seg_upid)

def from_xml(self, stuff):
Expand Down

0 comments on commit 4d5f5e3

Please sign in to comment.