XML Representation #75
Replies: 17 comments 51 replies
-
I have no plans to do any xml currently, but I'll take a patch sure. |
Beta Was this translation helpful? Give feedback.
-
if you need an m3u8 parser, try m3ufu |
Beta Was this translation helpful? Give feedback.
-
I took a look at defining something using the same interface as NBin and it would almost work, but the XML and binary representations are just different enough that there's a few issues where it wouldn't fit nicely (some field names don't translate directly to attribute names, some are omitted, not obvious how Elements would be added ...) In the end, for local use, I added an |
Beta Was this translation helpful? Give feedback.
-
I was spying on you the other day, looking at your repo, solid stuff. I think you have done a great job. Seriously. |
Beta Was this translation helpful? Give feedback.
-
Maybe this might be easier and clearer, it works similar to NBin def num2xml(val):
"""
num2xml makes
ints and floats
into strings for xml
"""
return str(val)
def bool2xml(val):
"""
bool2xml returns lowercase
strings of the boolean value
True becomes "true"
False becomes "false"
"""
return str(val).lower()
def hex2xml(val):
"""
hex2xml converts hex to int
and returns as a string
"""
return str(int(val,16)) Then the Element method for SpliceInsert would look like this # stuff.py is the current home for stray functions
from threefive.stuff import bool2xml, hex2xml, num2xml
...
# SpliceInsert.Element()
def element(self):
el = ET.Element("SpliceInsert", {
"spliceEventId": num2xml(self.splice_event_id),
"spliceEventCancelIndicator": bool2xml(self.splice_event_cancel_indicator),
"uniqueProgramId": num2xml(self.unique_program_id),
"availNum": num2xml(self.avail_num),
"availsExpected": num2xml(self.avail_expected)
})
if not self.splice_event_cancel_indicator:
el.set("outOfNetworkIndicator", bool2xml(self.out_of_network_indicator))
el.set("spliceImmediateFlag", bool2xml(self.splice_immediate_flag))
if self.program_splice_flag:
prg = ET.SubElement(el, "Program")
if not self.splice_immediate_flag:
spt = ET.SubElement(prg, "SpliceTime", {
"ptsTime": num2xml(self.pts_time_ticks)
})
else:
for comp in self.components:
cmp = ET.SubElement(el, "Component", {
"componentTag": str(comp)
})
if not self.splice_immediate_flag:
spt = ET.SubElement(cmp, "SpliceTime", {
"ptsTime": num2xml(self.pts_time_ticks)
})
if self.duration_flag:
ET.SubElement(el, "BreakDuration", {
"autoReturn": bool2xml(self.break_auto_return),
"duration": num2xml(self.break_duration_ticks)
})
return el You should not need to do the ticks checks for pts_time, if not self.pts_time_ticks:
self.pts_time_ticks = 0
if self.pts_time:
self.pts_time_ticks = self.as_ticks(self.pts_time) decode with handle that for you. Tell me if it doesn't and Ill fix it. |
Beta Was this translation helpful? Give feedback.
-
Are you validating against the schema, http://www.scte.org/schemas/35 ? |
Beta Was this translation helpful? Give feedback.
-
Hello @davemevans , @futzu , |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
-
@wabiloo I'm not going to have from_xml without to_xml. The name/namespace can be edited to whatever you want, actually any part of it can be changed or added or deleted, that's what's taken me the most time.I want it as flexible as possible. that being said, check this out: a@fu:~$ pypy3
Python 3.9.16 (7.3.11+dfsg-2+deb12u2, May 20 2024, 22:08:06)
[PyPy 7.3.11 with GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>> from threefive import Cue
>>>> that_xml = """<EventStream timescale="90000" schemeIdUri="urn:scte:scte35:2013:xml">
.... <Event duration="5310000">
.... <scte35:SpliceInfoSection protocolVersion="0" ptsAdjustment="183003" tier="4095">
.... <scte35:TimeSignal>
.... <scte35:SpliceTime ptsTime="3442857000"/>
.... </scte35:TimeSignal>
.... <scte35:Segmentation
Descriptor segmentationEventId="1414668" segmentationEventCancelIndicator="false" segmentationDuration="8100000">
<scte35:DeliveryRestrictions webDeliveryAllowedFlag="false" noRegionalBlackoutFlag="false" archiveAllowedFlag="false" deviceRestrictions="3"/>
<scte35:SegmentationUpid segmentationUpidType="8" segmentationUpidLength="8" segmentationTypeId="52"
segmentNum="0" segmentsExpected="0">0x2df3aad7</scte35:SegmentationUpid>
</scte35:SegmentationDescriptor>
</scte35:SpliceInfoSection>
</Event>
</EventStream>"""
>>>>
>>>> cue=Cue()
>>>> cue.load(that_xml)
>>>> cue.show()
{
"info_section": {
"table_id": "0xfc",
"section_syntax_indicator": false,
"private": false,
"sap_type": "0x03",
"sap_details": "No Sap Type",
"section_length": 54,
"protocol_version": 0,
"encrypted_packet": false,
"encryption_algorithm": 0,
"pts_adjustment": 2.033367,
"cw_index": "0x0",
"tier": "0xfff",
"splice_command_length": 5,
"splice_command_type": 6,
"descriptor_loop_length": 32,
"crc": "0x8926251d"
},
"command": {
"command_length": 5,
"command_type": 6,
"name": "Time Signal",
"time_specified_flag": true,
"pts_time": 38253.966667
},
"descriptors": [
{
"tag": 2,
"descriptor_length": 30,
"name": "Segmentation Descriptor",
"identifier": "CUEI",
"segmentation_event_id": "0x15960c",
"segmentation_event_cancel_indicator": false,
"segmentation_event_id_compliance_indicator": true,
"program_segmentation_flag": true,
"segmentation_duration_flag": true,
"delivery_not_restricted_flag": false,
"web_delivery_allowed_flag": false,
"no_regional_blackout_flag": false,
"archive_allowed_flag": false,
"device_restrictions": "No Restrictions",
"segmentation_duration": 90.0,
"segmentation_upid_type": 8,
"segmentation_upid_length": 8,
"segmentation_upid": "0x2df3aad7",
"segmentation_type_id": 52,
"segment_num": 0,
"segments_expected": 0,
"sub_segment_num": 0,
"sub_segments_expected": 0
}
]
} |
Beta Was this translation helpful? Give feedback.
-
@davemevans , you want to give me a hand? I've got the big pieces up and working, but it would be nice to have another pair of eyes on it. |
Beta Was this translation helpful? Give feedback.
-
@davemevans , I don't mean to be a dick, but.....
|
Beta Was this translation helpful? Give feedback.
-
@davemevans 0x01: ["Deprecated",text]
0x02: ["Deprecated", text]
0x03: ["AdID", text]
0x04: ["UMID",hexbinary]
0x05: ["ISAN", hexbinary]
0x06: ["ISAN", hexbinary]
0x07: ["TID", Text]
0x08: ["AiringID", hexbinary]
0x09: ["ADI", text]
0x10: ["UUID", text]
0x11: ["SCR", text]
0x0A: ["EIDR", hexbinary]
0x0B: ["ATSC", hexbinary]
0x0C: ["MPU", private]
0x0D: ["MID", hexbinary]
0x0E: ["ADS Info",text]
0x0F: ["URI", text]
key:
segmentationUpidType : ["Name", segmentationUpidFormat] |
Beta Was this translation helpful? Give feedback.
-
Sure, not questioning the need for consistency in the existing parser or looking to change that. What I meant was for the hexbinary XML representation of UPID values. It's not clear to me that the correct behaviour would be here as there are few examples available. SCTE224 has one that appears to imply no 0x, but that's just one and it's incomplete. I'm wondering if base64 might be a better way forward for non-text upids, but I'm open on it. It's also arguably not the best for consumers. The schema doesn't look to include the upid type name - the highlighted section above only includes the MPU format_identifier and the segmentationUpidFormat which describes the encoding format of the upid value. I don't see any reference elsewhere either but I don't have the 2023r1 XSD. I do agree that in DASH you are more likely to see Binary - I have only rarely seen SpliceInfoSection - so it'd be understandable and much more straightforward if you only want to include support for that in the project. However, @wabiloo has a DASH use case that appears to require parsing and serialising SpliceInfoSection, and I have a non-DASH use case. Perhaps we need to rethink supporting those. |
Beta Was this translation helpful? Give feedback.
-
With the UPIDS, return the value of Upid as it i in threefive, except for mid and mpu. |
Beta Was this translation helpful? Give feedback.
-
First off, thanks for the awesome library!
I have a use case where I need to convert a base64-formatted Cue I receive via my web service into the full XML representation as specified in the SCTE35 spec (ie using a
Signal.SpliceInfoSection
not just sticking it in aSignal.Binary
).XML representation is used in a number of places, notably MPEG-DASH.
I thought about building my own thing, but this library seems to do about 9/10 of the required functionality already.
It would be awesome if it were possible to do something like
cue.to_xml()
or similar. I suppose in the long termfrom_xml()
might also be useful though not something I would need right now.Is this a feature that you would consider allowing in threefive?
Beta Was this translation helpful? Give feedback.
All reactions