diff --git a/feed b/feed index 2aa0d32..d09b46e 100755 --- a/feed +++ b/feed @@ -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))