Skip to content

Commit

Permalink
fix: zero length for delete tags
Browse files Browse the repository at this point in the history
  • Loading branch information
hairmare committed Jan 16, 2022
1 parent c780cf8 commit 848d303
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@

DAB+ now playing PAD (DLS+ and MOT SLS) generator

## Usage

### DL+

You can use this to generate some DLPlus Tags.

```python
>>> from nowplaypadgen.dlplus import *
>>> message = DLPlusMessage()
>>> message.add_dlp_object(DLPlusObject("STATIONNAME.LONG", "Radio Bern RaBe"))
>>> message.add_dlp_object(DLPlusObject("STATIONNAME.SHORT", "RaBe"))
>>> message.add_dlp_object(DLPlusObject("ITEM.TITLE", "Radio Bern"))
>>> message.build("{o[STATIONNAME.LONG]}")
>>> message.message
'Radio Bern RaBe'
>>> tags = message.get_dlp_tags()
>>> long = tags['STATIONNAME.LONG']
>>> f"{long}: {long.code} {long.start} {long.length}"
'STATIONNAME.LONG: 32 0 15'
>>> short = tags['STATIONNAME.SHORT']
>>> f"{short}: {short.code} {short.start} {short.length}"
'STATIONNAME.SHORT: 31 11 4'
>>> title = tags['ITEM.TITLE']
>>> f"{title}: {title.code} {title.start} {title.length}"
'ITEM.TITLE: 1 0 10'

```

Later on you might want to generate DL+ that deletes an item tag.

```python
>>> message = DLPlusMessage()
>>> message.add_dlp_object(DLPlusObject("STATIONNAME.LONG", "Radio Bern RaBe"))
>>> message.add_dlp_object(DLPlusObject("ITEM.TITLE", delete=True))
>>> message.build("{o[STATIONNAME.LONG]}")
>>> message.message
'Radio Bern RaBe'
>>> tags = message.get_dlp_tags()
>>> title = tags['ITEM.TITLE']
>>> f"{title}: {title.code} {title.start} {title.length}"
'ITEM.TITLE: 1 5 0'

```

## Release Management

The CI/CD setup uses semantic commit messages following the [conventional commits standard](https://www.conventionalcommits.org/en/v1.0.0/).
Expand Down
14 changes: 14 additions & 0 deletions nowplaypadgen/dlplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,9 @@ def __init__(self, content_type: str, text: str = "", delete: bool = False):
# DL Plus dummy objects always have their text set to an empty string
if self.is_dummy():
text = ""
# DL Plus delete objects always have their text set to a whitespace string
if delete:
text = " "

#: The text string of the DL Plus object
self.text = text
Expand Down Expand Up @@ -922,6 +925,15 @@ def from_message(cls, dlp_message: DLPlusMessage, content_type: str) -> DLPlusTa
>>> f"{tag.content_type} {tag.start} {tag.length}"
'STATIONNAME.SHORT 6 4'
It also handles delete tags in messages
>>> message = DLPlusMessage()
>>> message.add_dlp_object(DLPlusObject("ITEM.TITLE", delete=True))
>>> message.build("I am string")
>>> tag = DLPlusTag.from_message(message, "ITEM.TITLE")
>>> f"{tag.content_type} {tag.start} {tag.length}"
'ITEM.TITLE 1 0'
:param DLPlusMessage dlp_message: The populated DL Plus message
:return: DL Plus Tag
"""
Expand Down Expand Up @@ -950,6 +962,8 @@ def from_message(cls, dlp_message: DLPlusMessage, content_type: str) -> DLPlusTa

# Get the string length of the DL Plus object's text
length = len(dlp_object.text)
if dlp_object.is_delete:
length = 0

return cls(content_type, start, length)

Expand Down
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
description-file = README.md

[tool:pytest]
addopts = --doctest-glob='*.rst' --doctest-modules nowplaypadgen --cov=nowplaypadgen
testpaths =
tests
addopts = --doctest-glob='*.md' --doctest-modules --cov=nowplaypadgen

0 comments on commit 848d303

Please sign in to comment.