Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions src/spi/binary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Ensemble:
:type version: integer
"""

def __init__(self, ecc, eid, version=1):
def __init__(self, ecc, eid, version=1, names=[]):
self.ecc = ecc
self.eid = eid
self.names = []
self.names = names
self.descriptions = []
self.media = []
self.keywords = []
Expand Down Expand Up @@ -765,7 +765,8 @@ def build_schedule(schedule):
child = build_location(location)
programme_element.children.append(child)
# media
if programme.media: programme_element.children.append(build_mediagroup(programme.media))
for media in programme.media:
programme_element.children.append(build_mediagroup(media))
# genre
for genre in programme.genres:
child = build_genre(genre)
Expand Down Expand Up @@ -851,30 +852,29 @@ def build_description(description):
mediagroup_element.children.append(description_element)
return mediagroup_element

def build_mediagroup(all_media):
def build_mediagroup(media):

mediagroup_element = Element(0x13)

for media in all_media :

if not isinstance(media, Multimedia):
raise ValueError('object must be of type %s (is %s)' % (Multimedia.__name__, type(media)))

media_element = Element(0x2b)

if not isinstance(media, Multimedia):
raise ValueError('object must be of type %s (is %s)' % (Multimedia.__name__, type(media)))

media_element = Element(0x2b)

if media.content is not None:
media_element.attributes.append(Attribute(0x80, media.content, encode_string))
if media.url is not None:
media_element.attributes.append(Attribute(0x82, media.url, encode_string))
if media.type == Multimedia.LOGO_UNRESTRICTED:
media_element.attributes.append(Attribute(0x83, 0x02, encode_number, 8))
if media.width: media_element.attributes.append(Attribute(0x84, media.width, encode_number, 16))
if media.height: media_element.attributes.append(Attribute(0x85, media.height, encode_number, 16))
if media.type == Multimedia.LOGO_COLOUR_SQUARE:
media_element.attributes.append(Attribute(0x83, 0x04, encode_number, 8))
if media.type == Multimedia.LOGO_COLOUR_RECTANGLE:
media_element.attributes.append(Attribute(0x83, 0x06, encode_number, 8))
if media.content is not None:
media_element.attributes.append(Attribute(0x80, media.content, encode_string))
if media.url is not None:
media_element.attributes.append(Attribute(0x82, media.url, encode_string))
if media.type == Multimedia.LOGO_UNRESTRICTED:
media_element.attributes.append(Attribute(0x83, 0x02, encode_number, 8))
if media.width: media_element.attributes.append(Attribute(0x84, media.width, encode_number, 16))
if media.height: media_element.attributes.append(Attribute(0x85, media.height, encode_number, 16))
if media.type == Multimedia.LOGO_COLOUR_SQUARE:
media_element.attributes.append(Attribute(0x83, 0x04, encode_number, 8))
if media.type == Multimedia.LOGO_COLOUR_RECTANGLE:
media_element.attributes.append(Attribute(0x83, 0x06, encode_number, 8))

mediagroup_element.children.append(media_element)
mediagroup_element.children.append(media_element)

return mediagroup_element

Expand Down Expand Up @@ -922,7 +922,8 @@ def build_programme_event(event):
for location in event.locations:
event_element.children.append(build_location(location))
# media
if event.media: event_element.children.append(build_mediagroup(event.media))
for media in event.media:
event_element.children.append(build_mediagroup(media))
# genre
for genre in event.genres:
event_element.children.append(build_genre(genre))
Expand Down Expand Up @@ -960,8 +961,9 @@ def build_service(service):
service_element.children.append(build_description(description))

# media
if service.media: service_element.children.append(build_mediagroup(service.media))

for media in service.media:
service_element.children.append(build_mediagroup(media))

# genre
for genre in service.genres:
service_element.children.append(build_genre(genre))
Expand Down Expand Up @@ -1005,7 +1007,8 @@ def build_ensemble(ensemble, services):
event_element.children.append(build_description(description))

# media
if ensemble.media: ensemble_element.children.append(build_mediagroup(ensemble.media))
for media in ensemble.media:
ensemble_element.children.append(build_mediagroup(media))

# keywords

Expand Down
10 changes: 7 additions & 3 deletions src/spi/xml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,12 @@ def parse_bearer(bearer_element):
bearer = FmBearer.fromstring(uri)
elif uri.startswith('http') or uri.startswith('https'):
if "mimeValue" not in bearer_element.attrib:
raise ValueError("missing mimeValue attribute for URL: %s" % uri)
bearer = IpBearer(uri, content=bearer_element.attrib.get('mimeValue'))
bearer = IpBearer(uri)
else:
bearer = IpBearer(uri, content=bearer_element.attrib.get('mimeValue'))
elif uri.startswith('hd'):
bearer = IpBearer("http://null/")
logger.debug('bearer %s is not useful for DAB SPI', uri)
else:
raise ValueError('bearer %s not recognised' % uri)
if 'cost' in bearer_element.attrib:
Expand Down Expand Up @@ -743,7 +747,7 @@ def parse_service(service_element, listener):

# bearers
for child in service_element.findall("spi:bearer", namespaces):
if "id" in child: ervice.bearers.append(parse_bearer(child, listener))
if "id" in child.attrib: service.bearers.append(parse_bearer(child))

# media
for media_element in service_element.findall("spi:mediaDescription", namespaces):
Expand Down