add --intro and --outro

This commit is contained in:
boyska 2024-05-10 13:34:26 +02:00
parent f4e04a41ee
commit 4c9f73f705

22
feed
View file

@ -122,6 +122,12 @@ class Audio(object):
self.date = date
self.end_date = datetime.datetime(9999, 12, 31, tzinfo=datetime.timezone.utc)
@classmethod
def from_trusted(cls, url_or_path) -> 'Audio':
if url_or_path.startswith('/'):
return cls('file://' + url_or_path)
return cls(url_or_path)
def __str__(self):
return self.url
@ -465,6 +471,12 @@ def get_parser():
help="Between each item, put a random file from DIR",
)
intro = p.add_argument_group(
"intro", "Add intro/outro to output, but only if at least one audio will be output"
)
intro.add_argument("--intro", default=None, type=str, metavar="PATH")
intro.add_argument("--outro", default=None, type=str, metavar="PATH")
p.add_argument(
"--start",
default=0,
@ -640,6 +652,15 @@ def get_audio_by_source(args, parser):
sources = [weighted_choice(sources, weights)]
return audio_by_source, sources
def add_intro_outro(audios: list, args) -> list:
if not audios:
return audios
audios = audios.copy()
if args.intro:
audios.insert(0, Audio.from_trusted(args.intro))
if args.outro:
audios.append(Audio.from_trusted(args.outro))
return audios
def main():
parser = get_parser()
@ -701,6 +722,7 @@ def main():
# this is to support the --slotsize option
if not audios:
return
audios = add_intro_outro(audios, args)
for audio in audios[:-1]:
if args.debug:
debug(repr(audio))