mpd:
- manifest_edit.plugins.mpd.segment_url_modify:
    # This config file makes use of the "segment_url_modify" plugin to modify
    # the "baseURL" and "segmentTemplate" elements of a DASH manifest.
    #
    # With regards to "baseURL", it is possible to separately modify the URL
    # itself as well as its "serviceLocation" attribute.
    #
    # "segment_url_modify" allows to selectively edit the manifest, only
    # modifying specific periods, adaptation sets or representations where
    # "baseURL" or "segmentTemplate" elements appear, using a selection
    # syntax strictly reflecting the general structure of a DASH manifest,
    # which is briefly recapped here to better clarify how to configure the
    # plugin.
    #
    # Tracks in mpd manifests are specified as list of Representations
    # inside a given Adaptation Set, inside a given Period. The general
    # scheme can roughly be illustrated as
    #
    # Manifest:
    #  |- Period id:
    #     id = "id"
    #     |- AdaptationSet :
    #        contentType = "audio"
    #        |- Representation
    #        |-   ...
    #        |- Representation
    #     |- AdaptationSet :
    #        contentType = "video"
    #        |- Representation
    #        |-   ...
    #        |- Representation
    #
    # In an mpd there could be multiple periods, each with multiple
    # adaptation sets, each with multiple representations, to form an
    # arbitrarily nested structure.
    #
    # The segment_url_modify plugin allows to edit "baseURL" in any Adaptation
    # Set or Representation or Periods as well as in the manifest MPD root.
    # The same applies to the "segmentTemplate" element, which can appear in
    # any Period, Adaptation Set or Representation.
    # This is done by selecting the desired element by means if its properties,
    # as illustrated by the following examples:
    #
    # 1) add a "baseURL" element to the MPD root if not present
    #
    #    plugin_config:
    #      baseURL:
    #        match: '^$'
    #        replace: 'http://my.base.url'
    #
    # 2) edit an existing "baseURL" in a Period to use "https" instead of
    #    "http"
    #
    #    periods:
    #      - id : '.*'
    #        plugin_config:
    #          baseURL:
    #          match: '^http(.*)'
    #          # uses python group reference regular expression syntax
    #          replace: 'https\\g<1>'
    #
    # 3) prefix "media" and "initialization" attributes of a SegmentTemplate
    #    element, only in video Adaptation Sets, with a custom string
    #
    #    periods:
    #      - '*' : '.*'
    #        adaptationSets:
    #          - contentType :  "video"
    #            segmentTemplate:
    #              initialization:
    #                match: '^(.*)$'
    #                # uses python group reference regular expression syntax
    #                replace: 'myprefix/\\g<1>'
    #              media:
    #                match: '^(.*)$'
    #                # uses python group reference regular expression syntax
    #                replace: 'myprefix/\\g<1>'
    #
    # Since baseURL and SegmentTemplate can only be added to specific elements
    # (i.e. baseURL can be present in the manifest root, but SegmentTemplate
    # can not), the plugin will check for "impossible"
    # configurations and will only perform edits leading to a
    # DASH-compliant manifest.
    #
    # In addition to providing a specific "static" strings in the "replace"
    # configuration field, a template syntax is available to use a "dynamic"
    # string that can include values read at runtime from attributes of the
    # Period, Adaptation Set or Representation where the segmentTemplate or
    # baseURL is present.
    # In other words, it is possible to build the replace string based on,
    # i.e. an Adaptation Set's id,
    # contentType or codec using a syntax similar to "{contentType}/\\g<1>".
    # The template values within curly braces "{contentType}" will be replaced
    # at runtime by the actual values present in the manifest for that
    # Adaptation Set, generating baseURL prefixes such as "video/..." or
    # "audio/..."
    #
    # More details are available in manifest edit documentation.
    plugin_config:
    # Replace empty baseURL at MPD level (i.e. create one)
        baseURL:
          URL:
            match: '^.*$'
            replace: 'http://serving.segments.here'

- manifest_edit.plugins.mpd.segment_url_modify:
    periods:
    - id: ".*"
      adaptationSets:
      - id: ".*"
        # Will edit segmentTemplate 'media' and 'initialization' attributes
        # in any adaptationSets that belong to any period
        plugin_config:
          segmentTemplate:
            initialization:
              match: '^(.*)$'
              replace: '{contentType}.ism/\\g<1>'
            media:
              match: '^(.*)$'
              replace: '{contentType}.ism/\\g<1>'
    - id: ".*"
      # Will edit baseURL.URL in all periods
      plugin_config:
        baseURL:
          URL:
            match: '^.*$'
            replace: '/at/this/additional/path'
    - id: ".*"
      # Will edit baseURL.serviceLocation in all periods
      plugin_config:
        baseURL:
          serviceLocation:
            match: '^.*$'
            replace: 'my_location'
