##############################################################################
#                         Resolution/Edition Overlay                         #
#                 Created by Yozora, Bullmoose20, & Sohjiro                  #
#                     Credit to Magic815 for base images                     #
#          EDITING THIS FILE MAY CAUSE PULLING NEW UPDATES TO FAIL           #
#    https://metamanager.wiki/en/latest/defaults/overlays/resolution.html    #
##############################################################################

external_templates:
  pmm: templates
  template_variables:
    conditionals:
      suppress_overlays:
        default: <<overlay_name>>-Dovetail
        conditions:
          - type: edition_dovetail
            value:
              - 4K-DV-HDR
              - 4K-Plus
              - 4K-DV
              - 4K-HDR
              - 4K
              - 1080P-DV-HDR
              - 1080P-Plus
              - 1080P-DV
              - 1080P-HDR
              - 1080P
              - 720P-DV-HDR
              - 720P-Plus
              - 720P-DV
              - 720P-HDR
              - 720P
              - 576P-DV-HDR
              - 576P-Plus
              - 576P-DV
              - 576P-HDR
              - 576P
              - 480P-DV-HDR
              - 480P-Plus
              - 480P-DV
              - 480P-HDR
              - 480P
              - DV-HDR
              - Plus
              - DV
              - HDR
          - type: resolution_dovetail
            value:
              - Extended-Edition
              - Uncut-Edition
              - Unrated-Edition
              - Special-Edition
              - Anniversary-Edition
              - Collectors-Edition
              - Diamond-Edition
              - Platinum-Edition
              - Directors-Cut
              - Final-Cut
              - International-Cut
              - Theatrical-Cut
              - Ultimate-Cut
              - Alternate-Cut
              - Coda-Cut
              - IMAX-Enhanced
              - IMAX
              - Remastered
              - Criterion
              - Richard-Donner
              - Black-And-Chrome
              - Definitive
              - Ulysses
      final_horizontal_offset:
        default: <<horizontal_offset>>
        conditions:
          - type: resolution_dovetail
            value: <<horizontal_offset+30>>
      final_vertical_offset:
        default: <<vertical_offset>>
        conditions:
          - type: edition_dovetail
            vertical_align: bottom
            key: [remastered, coda]
            value: <<vertical_offset-10>>
          - type: edition_dovetail
            vertical_align: bottom
            value: <<vertical_offset>>
          - type: edition_dovetail
            value: <<vertical_offset+64>>
          - type: resolution_dovetail
            value: <<vertical_offset+30>>
      back_width:
        conditions:
          - type: [edition, resolution, edition_dovetail]
            value: 305
          - type: resolution_dovetail
            value: 245
      back_height:
        conditions:
          - type: [edition, resolution]
            value: 105
          - type: [resolution_dovetail, edition_dovetail]
            value: 129
      back_color:
        conditions:
          - type: [edition, resolution, resolution_dovetail]
            value: "#00000099"
          - type: edition_dovetail
            value: "#00000000"
      back_padding:
        conditions:
          - type: resolution_dovetail
            value: 30
      back_align:
        conditions:
          - type: resolution_dovetail
            value: top
      pmm:
        conditions:
          - type: [edition, edition_dovetail]
            file.exists: false
            file_<<key>>.exists: false
            url.exists: false
            url_<<key>>.exists: false
            git.exists: false
            git_<<key>>.exists: false
            repo.exists: false
            repo_<<key>>.exists: false
            value: edition/<<key>>
          - type: [resolution, resolution_dovetail]
            file.exists: false
            file_<<key>>.exists: false
            url.exists: false
            url_<<key>>.exists: false
            git.exists: false
            git_<<key>>.exists: false
            repo.exists: false
            repo_<<key>>.exists: false
            value: resolution/<<key>><<alt>>
      group:
        conditions:
          - type: [edition, edition_dovetail]
            value: edition
          - type: [resolution, resolution_dovetail]
            value: resolution
    horizontal_offset: 15
    vertical_offset: 15
    horizontal_align: left
    vertical_align: top

templates:
  edition:
    conditionals:
      regex1:
        conditions:
          - key: enhanced
            value: '(?i)\bIMAX Enhanced\b|^(?=.*(DSNP|Disney\+|CORE(?=[ ._-]web[ ._-]?(dl|rip)\b)|\bBC(?=[ ._-]web[ ._-]?(dl|rip)\b)|IMAX[- .]Enhanced)\b)(?=.*\b(IMAX|IMAX[- .]Enhanced)\b).*'
          - key: imax
            value: '(?i)\bIMAX\b'
          - key: criterion
            value: '(?i)Criterion'
      regex2:
        conditions:
          - key: criterion
            value: '(?i)\[CC\]'
    optional:
      - search
      - use_<<key>>
      - use_edition
      - allowed_libraries
    run_definition:
      - <<use_<<key>>>>
      - <<use_edition>>
      - <<allowed_libraries>>
    ignore_blank_results: true
    plex_all: true
    filters:
      - edition: <<search>>
      - filepath.regex:
        - <<regex1>>
        - <<regex2>>
        - '(?i)edition-\b(4k )?<<search>>(s|ed)?\b'           # New TRaSH naming
        - '(?<=[0-9]{4}[)}>\]]\s)\b(4k )?<<search>>(s|ed)?\b' # Original TRaSH naming

  resolution:
    conditionals:
      res:
        conditions:
          - key: 4k
            value: "(?i)2160|4k"
          - key: 1080p
            value: "(?i)1080|2k"
          - key: 720p
            value: "(?i)720|hd"
          - key: 576p
            value: "(?i)576"
          - key: 480p
            value: "(?i)480|sd"
      dolby_vision:
        conditions:
          - alt: dv
            value: true
      hdr:
        conditions:
          - alt: hdr
            value: true
      regex:
        conditions:
          - alt: plus
            value: '(?i)\bhdr10(\+|p(lus)?\b)'
          - alt: dvhdr
            value: '(?i)\bdv(.hdr10?\b)'
    optional:
      - all
      - use_<<key>>
      - use_<<key>>_<<alt>>
      - use_<<alt>>
      - use_resolution
      - allowed_libraries
    run_definition:
      - <<use_<<key>>>>
      - <<use_<<alt>>>>
      - <<use_<<key>>_<<alt>>>>
      - <<allowed_libraries>>
      - <<use_resolution>>
    ignore_blank_results: true
    plex_all: <<all>>
    plex_search:
      all:
        any:
          resolution.regex: <<res>>
        hdr: <<hdr>>
    filters:
      has_dolby_vision: <<dolby_vision>>
      filepath.regex:
        - <<regex>>

overlays:

  4K-DV-HDR-Dovetail:
    variables: {key: 4k, alt: dvhdr, weight: 158, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  4K-Plus-Dovetail:
    variables: {key: 4k, alt: plus, weight: 155, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  4K-DV-Dovetail:
    variables: {key: 4k, alt: dv, weight: 150, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  4K-HDR-Dovetail:
    variables: {key: 4k, alt: hdr, weight: 140, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  4K-Dovetail:
    variables: {key: 4k, alt: "", weight: 130, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  1080P-DV-HDR-Dovetail:
    variables: {key: 1080p, alt: dvhdr, weight: 128, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  1080P-Plus-Dovetail:
    variables: {key: 1080p, alt: plus, weight: 125, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  1080P-DV-Dovetail:
    variables: {key: 1080p, alt: dv, weight: 120, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  1080P-HDR-Dovetail:
    variables: {key: 1080p, alt: hdr, weight: 110, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  1080P-Dovetail:
    variables: {key: 1080p, alt: "", weight: 100, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  720P-DV-HDR-Dovetail:
    variables: {key: 720p, alt: dvhdr, weight: 98, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  720P-Plus-Dovetail:
    variables: {key: 720p, alt: plus, weight: 95, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  720P-DV-Dovetail:
    variables: {key: 720p, alt: dv, weight: 90, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  720P-HDR-Dovetail:
    variables: {key: 720p, alt: hdr, weight: 80, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  720P-Dovetail:
    variables: {key: 720p, alt: "", weight: 70, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  576P-DV-HDR-Dovetail:
    variables: {key: 576p, alt: dvhdr, weight: 68, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  576P-Plus-Dovetail:
    variables: {key: 576p, alt: plus, weight: 65, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  576P-DV-Dovetail:
    variables: {key: 576p, alt: dv, weight: 60, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  576P-HDR-Dovetail:
    variables: {key: 576p, alt: hdr, weight: 50, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  576P-Dovetail:
    variables: {key: 576p, alt: "", weight: 40, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  480P-DV-HDR-Dovetail:
    variables: {key: 480p, alt: dvhdr, weight: 38, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  480P-Plus-Dovetail:
    variables: {key: 480p, alt: plus, weight: 35, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  480P-DV-Dovetail:
    variables: {key: 480p, alt: dv, weight: 30, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  480P-HDR-Dovetail:
    variables: {key: 480p, alt: hdr, weight: 20, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  480P-Dovetail:
    variables: {key: 480p, alt: "", weight: 10, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  DV-HDR-Dovetail:
    variables: {key: "", alt: dvhdr, weight: 8, type: resolution_dovetail, all: true, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  Plus-Dovetail:
    variables: {key: "", alt: plus, weight: 7, type: resolution_dovetail, all: true, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  DV-Dovetail:
    variables: {key: "", alt: dv, weight: 5, type: resolution_dovetail, all: true, allowed_libraries: movie}
    template: [name: resolution, name: standard]
  HDR-Dovetail:
    variables: {key: "", alt: hdr, weight: 1, type: resolution_dovetail, allowed_libraries: movie}
    template: [name: resolution, name: standard]

  Extended-Edition-Dovetail:
    variables: {key: extended, weight: 190, search: Extend, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Uncut-Edition-Dovetail:
    variables: {key: uncut, weight: 180, search: Uncut, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Unrated-Edition-Dovetail:
    variables: {key: unrated, weight: 170, search: Unrat, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Special-Edition-Dovetail:
    variables: {key: special, weight: 160, search: Special, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Anniversary-Edition-Dovetail:
    variables: {key: anniversary, weight: 150, search: Anniversary, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Collectors-Edition-Dovetail:
    variables: {key: collector, weight: 140, search: Collector, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Diamond-Edition-Dovetail:
    variables: {key: diamond, weight: 130, search: Diamond, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Platinum-Edition-Dovetail:
    variables: {key: platinum, weight: 120, search: Platinum, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Directors-Cut-Dovetail:
    variables: {key: directors, weight: 110, search: Director, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Final-Cut-Dovetail:
    variables: {key: final, weight: 100, search: Final, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  International-Cut-Dovetail:
    variables: {key: international, weight: 90, search: International, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Theatrical-Cut-Dovetail:
    variables: {key: theatrical, weight: 80, search: Theatrical, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Ultimate-Cut-Dovetail:
    variables: {key: ultimate, weight: 70, search: Ultimate, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Alternate-Cut-Dovetail:
    variables: {key: alternate, weight: 60, search: Alternate, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Coda-Cut-Dovetail:
    variables: {key: coda, weight: 50, search: Coda, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  IMAX-Enhanced-Dovetail:
    variables: {key: enhanced, weight: 40, search: IMAX Enhanced, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  IMAX-Dovetail:
    variables: {key: imax, weight: 30, search: IMAX, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Remastered-Dovetail:
    variables: {key: remastered, weight: 20, search: Remaster, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Criterion-Dovetail:
    variables: {key: criterion, weight: 10, search: Criterion, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Richard-Donner-Dovetail:
    variables: {key: richarddonner, weight: 9, search: Rich, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Black-And-Chrome-Dovetail:
    variables: {key: blackchrome, weight: 8, search: Black, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Definitive-Dovetail:
    variables: {key: definitive, weight: 7, search: Definitive, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Ulysses-Dovetail:
    variables: {key: ulysses, weight: 6, search: Ulysses, type: edition_dovetail, allowed_libraries: movie}
    template: [name: edition, name: standard]

  4K-DV-HDR:
    variables: {key: 4k, alt: dvhdr, weight: 158, type: resolution}
    template: [name: resolution, name: standard]
  4K-Plus:
    variables: {key: 4k, alt: plus, weight: 155, type: resolution}
    template: [name: resolution, name: standard]
  4K-DV:
    variables: {key: 4k, alt: dv, weight: 150, type: resolution}
    template: [name: resolution, name: standard]
  4K-HDR:
    variables: {key: 4k, alt: hdr, weight: 140, type: resolution}
    template: [name: resolution, name: standard]
  4K:
    variables: {key: 4k, alt: "", weight: 130, type: resolution}
    template: [name: resolution, name: standard]
  1080P-DV-HDR:
    variables: {key: 1080p, alt: dvhdr, weight: 128, type: resolution}
    template: [name: resolution, name: standard]
  1080P-Plus:
    variables: {key: 1080p, alt: plus, weight: 125, type: resolution}
    template: [name: resolution, name: standard]
  1080P-DV:
    variables: {key: 1080p, alt: dv, weight: 120, type: resolution}
    template: [name: resolution, name: standard]
  1080P-HDR:
    variables: {key: 1080p, alt: hdr, weight: 110, type: resolution}
    template: [name: resolution, name: standard]
  1080P:
    variables: {key: 1080p, alt: "", weight: 100, type: resolution}
    template: [name: resolution, name: standard]
  720P-DV-HDR:
    variables: {key: 720p, alt: dvhdr, weight: 98, type: resolution}
    template: [name: resolution, name: standard]
  720P-Plus:
    variables: {key: 720p, alt: plus, weight: 95, type: resolution}
    template: [name: resolution, name: standard]
  720P-DV:
    variables: {key: 720p, alt: dv, weight: 90, type: resolution}
    template: [name: resolution, name: standard]
  720P-HDR:
    variables: {key: 720p, alt: hdr, weight: 80, type: resolution}
    template: [name: resolution, name: standard]
  720P:
    variables: {key: 720p, alt: "", weight: 70, type: resolution}
    template: [name: resolution, name: standard]
  576P-DV-HDR:
    variables: {key: 576p, alt: dvhdr, weight: 68, type: resolution}
    template: [name: resolution, name: standard]
  576P-Plus:
    variables: {key: 576p, alt: plus, weight: 65, type: resolution}
    template: [name: resolution, name: standard]
  576P-DV:
    variables: {key: 576p, alt: dv, weight: 60, type: resolution}
    template: [name: resolution, name: standard]
  576P-HDR:
    variables: {key: 576p, alt: hdr, weight: 50, type: resolution}
    template: [name: resolution, name: standard]
  576P:
    variables: {key: 576p, alt: "", weight: 40, type: resolution}
    template: [name: resolution, name: standard]
  480P-DV-HDR:
    variables: {key: 480p, alt: dvhdr, weight: 38, type: resolution}
    template: [name: resolution, name: standard]
  480P-Plus:
    variables: {key: 480p, alt: plus, weight: 35, type: resolution}
    template: [name: resolution, name: standard]
  480P-DV:
    variables: {key: 480p, alt: dv, weight: 30, type: resolution}
    template: [name: resolution, name: standard]
  480P-HDR:
    variables: {key: 480p, alt: hdr, weight: 20, type: resolution}
    template: [name: resolution, name: standard]
  480P:
    variables: {key: 480p, alt: "", weight: 10, type: resolution}
    template: [name: resolution, name: standard]
  DV-HDR:
    variables: {key: "", alt: dvhdr, weight: 8, type: resolution, all: true}
    template: [name: resolution, name: standard]
  Plus:
    variables: {key: "", alt: plus, weight: 7, type: resolution, all: true}
    template: [name: resolution, name: standard]
  DV:
    variables: {key: "", alt: dv, weight: 5, type: resolution, all: true}
    template: [name: resolution, name: standard]
  HDR:
    variables: {key: "", alt: hdr, weight: 1, type: resolution}
    template: [name: resolution, name: standard]

  Extended-Edition:
    variables: {key: extended, weight: 190, search: Extend, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Uncut-Edition:
    variables: {key: uncut, weight: 180, search: Uncut, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Unrated-Edition:
    variables: {key: unrated, weight: 170, search: Unrat, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Special-Edition:
    variables: {key: special, weight: 160, search: Special, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Anniversary-Edition:
    variables: {key: anniversary, weight: 150, search: Anniversary, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Collectors-Edition:
    variables: {key: collector, weight: 140, search: Collector, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Diamond-Edition:
    variables: {key: diamond, weight: 130, search: Diamond, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Platinum-Edition:
    variables: {key: platinum, weight: 120, search: Platinum, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Directors-Cut:
    variables: {key: directors, weight: 110, search: Director, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Final-Cut:
    variables: {key: final, weight: 100, search: Final, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  International-Cut:
    variables: {key: international, weight: 90, search: International, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Theatrical-Cut:
    variables: {key: theatrical, weight: 80, search: Theatrical, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Ultimate-Cut:
    variables: {key: ultimate, weight: 70, search: Ultimate, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Alternate-Cut:
    variables: {key: alternate, weight: 60, search: Alternate, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Coda-Cut:
    variables: {key: coda, weight: 50, search: Coda, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  IMAX-Enhanced:
    variables: {key: enhanced, weight: 40, search: IMAX Enhanced, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  IMAX:
    variables: {key: imax, weight: 30, search: IMAX, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Remastered:
    variables: {key: remastered, weight: 20, search: Remaster, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Criterion:
    variables: {key: criterion, weight: 10, search: Criterion, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Richard-Donner:
    variables: {key: richarddonner, weight: 9, search: Rich, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Black-And-Chrome:
    variables: {key: blackchrome, weight: 8, search: Black, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Definitive:
    variables: {key: definitive, weight: 7, search: Definitive, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]
  Ulysses:
    variables: {key: ulysses, weight: 6, search: Ulysses, type: edition, allowed_libraries: movie}
    template: [name: edition, name: standard]