From 848d303b73a72ce5684f31564c56c0461b53048e Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Sun, 16 Jan 2022 21:44:55 +0100 Subject: [PATCH] fix: zero length for delete tags --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++ nowplaypadgen/dlplus.py | 14 +++++++++++++ setup.cfg | 4 +--- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6cd999a..34fdbe7 100644 --- a/README.md +++ b/README.md @@ -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/). diff --git a/nowplaypadgen/dlplus.py b/nowplaypadgen/dlplus.py index 1e4d228..83cfac1 100644 --- a/nowplaypadgen/dlplus.py +++ b/nowplaypadgen/dlplus.py @@ -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 @@ -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 """ @@ -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) diff --git a/setup.cfg b/setup.cfg index d0562a1..eefe12d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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