<commit_before># Flexget (http://www.flexget.com) configuration file.
#
# Created by: <NAME> <<EMAIL>>
# Available from: https://github.com/jawilson/dotfiles
#
# For more information, see the README.md
#

# Use the secrets plugin to separately store credentials, etc
variables: secretfile.yml
templates:

  global:
    # Some strings I found tripping up the parsers
    manipulate:
      - title:
          replace:
            regexp: '-?bs666$'
            format: ''
      - title:
          replace:
            regexp: 's(\d\d)(\d\d)'
            format: 's\1e\2'
    if:
      - "'torrentleech' in url":
          deluge:
            username: '{? deluge.username ?}'
            password: '{? <PASSWORD> ?}'
            main_file_only: yes # Ignore all but the file that is >90% of the torrent if it exists
            keep_subs: yes
            port: 58847
      - "'torrentleech' not in url":
          deluge:
            username: '{? deluge.username ?}'
            password: '{? <PASSWORD> ?}'
            main_file_only: yes # Ignore all but the file that is >90% of the torrent if it exists
            keep_subs: yes
            port: 58846
    # Make there's 50GB free before adding more downloads
    free_space:
      path: /media/raid
      space: 50000
    # Make sure all filenames are Windows safe (for samba)
    pathscrub: windows
    # Limit the frequency of requests to domains so they don't complain about
    # using a bot
    domain_delay:
      www.torrentleech.org: 10 seconds
      rss.torrentleech.org: 10 minutes
      bt-chat.com: 5 seconds
      thexem.de: 10 seconds
    # The Pirate Bay ssl certs always fail
    verify_ssl_certificates: no
    notify:
      entries:
        message: >
          {{task}} - Download started:
          {%- if series_name is defined %}
          {% set info_string = tvdb_series_name|d(series_name) ~ ' - ' ~ series_id ~ (' - ' ~ tvdb_ep_name if tvdb_ep_name|default(False) else '') %}
          {%- if trakt_series_url is defined and trakt_season is defined and trakt_episode is defined -%}
          <{{ trakt_series_url }}/seasons/{{ trakt_season }}/episodes/{{ trakt_episode }}|{{ info_string }}>
          {%- else %}
          {{ info_string }}
          {%- endif %}
          - {{quality}}
          {%- elif imdb_name is defined %}
          {% set info_string = imdb_name ~ (' (' ~ imdb_year ~ ')' if imdb_year|d(False) else '') %}
          {%- if imdb_url is defined %}
          <{{imdb_url}}|{{info_string}}>
          {%- else %}
          {{info_string}}
          {%- endif %}
          - {{quality}}{% if extras|d(False) %} 3d {{ extras|lower }}{% endif %}
          {%- else -%}
          {{title}}
          {%- endif %}
        via:
          - slack:
              web_hook_url: '{? slack.webhook_url ?}'

  global-filter:
    # Most of these are the results of problem torrents I kept seeing still pop up, so I wholesale blocked them
    # RegExr (http://www.gskinner.com/RegExr/) is a great tool for testing regexes
    regexp:
      reject:
        - (s|d)ub(s|bed)?\b: {from: title}                    # Block any subbed/dubbed/etc videos
        - \bspanish\b: {from: title}                          # Spanish releases kept cropping up
        - \b(duo|tri|quadri|tetra|penta)logy\b: {from: title} # Block series, only accept one at a time
        - \btrailer\b: {from: title}                          # I've gotten a few trailers that matched as movies. VERY annoying
        - \bR5\b: {from: title}                               # The following are poor quality types that somehow got through the quality
        - \bWEBSCR\b: {from: title}                           # features usually due to the title including a keyword like "720p" as well
        - \bscreener\b: {from: title}
        - \bTS\b: {from: title}
        - \bCam\b: {from: title}
        - '{C_P}': {from: title}                              # The following are groups with poor quality releases
        - TrTd TeaM: {from: title}
        - \[TNTVillage\]: {from: title}
        - \[facepalm\]: {from: title}
        - \bASAP\b: {from: title}
        - the.day.of.the.doctor                               # The following are titles that caused me issues from plugins
    # Require at least 10 seeds of any torrent
    torrent_alive:
      min_seeds: 10
      reject_for: 1 day
    # Filter by filenames. Allow multiple video types and rar packs (but note if there is just a
    # single .rar file it won't be accepted)
    content_filter:
      require:
        - '*.avi'
        - '*.mkv'
        - '*.mpg'
        - '*.mp4'
        - '*.r0*'
        - '*.part0*'
      reject:
        - 'password.txt'
        - '*.wmv'
    # Size and seed restrictions require real torrents
    magnets: no

  tv-anchors:
    _tv_discover_from: &tv-discover-from
      from:
        - torrentleech:
            rss_key: '{? torrentleech.rss_key ?}'
            username: '{? torrentleech.username ?}'
            password: '{? <PASSWORD> ?}'
            category: ['Episodes HD', 'Episodes']
        - flexget_archive: [tv]
        - rarbg:
            category: [41]
            use_tvdb: true
            min_seeders: 10
    _tv_trakt_list_tv_shows: &tv-trakt-list-tv-shows
      account: '{? trakt.account ?}'
      list: TV Shows
      strip_dates: yes
    _tv_trakt_ak_list_tv_shows: &tv-trakt-ak-list-tv-shows
      account: '{? trakt.ak_account ?}'
      list: TV Shows
      strip_dates: yes
    _tv_series: &tv-series
      include:
        - series.yml
      configure_series: &tv-series-from
        from:
          inputs:
            - trakt_list:
                <<: *tv-trakt-list-tv-shows
                type: shows
            - trakt_list:
                <<: *tv-trakt-ak-list-tv-shows
                type: shows

  tv-trakt-follow:
    disable:
      - seen
    accept_all: yes
    no_entries_ok: yes
    set_series_begin: yes
    manipulate:
      - series_name:
          from: trakt_series_name

  tv-filter:
    <<: *tv-series
    template: [global-filter]
    configure_series:
      <<: *tv-series-from
      settings:
        target: 720p+ webrip+
        timeframe: 14 days
        quality: 480p+ webrip+
        tracking: backfill
        season_packs: yes
    # Impose reasonable size constraints
    content_size:
      max: 5000
      min: 20
    # Prevent from downloading shows that were aquired manually
    # or are currently downloading
    exists_series:
      - "/media/raid/videos/TV Shows/{{ tvdb_series_name|default(series_name)|replace('/', '_')|replace(':', ' -')|replace(',', '') }}"
      - /media/raid/videos/AK Shows
      - /media/raid/videos/staging/tv_shows/
      - /media/raid/deluge/downloads/


  tv-global:
    archive: [tv]
    # Look up info on TheTVDB.com to fill in extra info
    thetvdb_lookup: yes
    trakt_lookup: yes
    require_field: [series_name, series_id]
    sequence:
      - configure_series:
          settings:
            set:
              movedone: >-
                /media/raid/videos/TV Shows/{{ tvdb_series_name|default(series_name)|replace('/', '_')|replace(':', ' -')|replace(',', '') }}/{% if series_id_type == 'ep' %}Season {{ series_season }}/{% endif %}
          from:
            trakt_list:
              <<: *tv-trakt-list-tv-shows
              type: shows
      - configure_series:
          settings:
            set:
              movedone: >-
                /media/raid/videos/AK Shows/{{ tvdb_series_name|default(series_name)|replace('/', '_')|replace(':', ' -')|replace(',', '') }}/{% if series_id_type == 'ep' %}Season {{ series_season }}/{% endif %}
          from:
            trakt_list:
              <<: *tv-trakt-ak-list-tv-shows
              type: shows
    set:
      queuetotop: yes
      # Rename the "content file" to something nice, use leading slash to force file to top level
      content_filename: >-
        /{{ tvdb_series_name|default(series_name)|replace('/', '_')|replace(':', ' -')|replace(',', '') }} - {{ series_id }}{% if tvdb_ep_name|default(False) %} - {{ tvdb_ep_name|replace('/', '_')|replace(':', ' -')|replace(',', '') }}{% endif %} - {{ quality }}
      label: tv
    # This is a custom plugin, it is part of my rar-unpacking method,
    # it changes 'movedone' based on the regexp in the key
    content_sort:
      '*.rar': '/media/raid/deluge/downloads/completed/tv_shows/'


  movie-anchors:
    _movie_trakt_list_movies: &movie-trakt-list-movies
      account: '{? trakt.account ?}'
      list: Movie Queue
      type: movies
    _movie_trakt_ak_list_movies: &movie-trakt-ak-list-movies
      account: '{? trakt.ak_account ?}'
      list: Movies
      type: movies

  movies-global:
    archive: [movies]
    imdb_lookup: yes
    trakt_lookup: yes
    # Download propers, since they will have the same content_filename,
    # lower/non-propers will be overwritten
    proper_movies: yes
    manipulate:
      - extras:
          from: title
          extract: '($|half.?(?:sbs|tab|ou))'
    set:
      # Give folders/files nice names
      movedone: "/media/raid/videos/Movies/{{ imdb_name|replace('/', '_')|replace(':', ' -')|replace(',', '') }} ({{ imdb_year }})"
      # Rename the "content file" to something nice, use leading slash to force file to top level
      content_filename: >-
        /{{ imdb_name|replace('/', '_')|replace(':', ' -')|replace(',', '') }} ({{ imdb_year }}) - {{ quality }}{% if extras|default(False) %} 3d {{ extras|lower }}{% endif %}
    # This is a custom plugin, it is part of my rar-unpacking method, it changes
    # 'movedone' based on the regexp in the key
    content_sort:
      '*.rar': '/media/raid/deluge/downloads/completed/movies/'

  # This template uses the movie queue to find movies from various sources
  movies-queued:
    template: [global-filter]
    rss:
      url: 'http://rss.torrentleech.org/{? torrentleech.rss_key ?}'
      other_fields: [category]
    # Some feeds might include TV Shows, ignore them
    if:
      - "has_field('category')":
          regexp:
            reject_excluding:
              - '^(HD|BDRip|DVDRip.DVDScreener|DVD-R|Documentaries)$': {from: category}
    discover:
      release_estimations:
        optimistic: 30 days
      what:
        - movie_list: movie queue
      from:
        - torrentleech:
            rss_key: '{? torrentleech.rss_key ?}'
            username: '{? torrentleech.username ?}'
            password: '{? <PASSWORD> ?}'
            category: ['HD', 'BDRip', 'DVDRip', 'DVDR', 'Documentaries']
        - flexget_archive: [movies]
        - rarbg:
            category: [44, 45]
            min_seeders: 10
    regexp:
      reject:
        - s\d+e\d+: {from: title}
        - '\d{4}.\d{2}.\d{2}': {from: title}
        - \d+x\d+: {from: title}
        - \baac2: {from: title} # No 2 channel audio
    # Impose reasonable size constraints
    content_size:
      max: 20000
      min: 1000
    # Check for already downloaded or currently downloading movies
    exists_movie:
      - /media/raid/videos/Movies/
      - /media/raid/videos/staging/movies
      - /media/raid/deluge/downloads/
    list_match:
      from:
        - movie_list: movie queue
    list_remove:
      - trakt_list:
          <<: *movie-trakt-list-movies
      - trakt_list:
          <<: *movie-trakt-ak-list-movies
    set:
      label: my-movies


# This is where we pull everything together
tasks:

  # Use a local folder (synced with Dropbox) as a source
  # I can drop torrents in this folder and they are synced with Dropbox, always
  # accepted, then the original file is deleted
  Local-Torrents-TV:
    priority: 1
    <<: *tv-series
    template:
      - tv-global
    disable:
      - archive
      - retry_failed
      - seen
    all_series:
      parse_only: yes
      assume_special: yes
      season_packs: yes
    configure_series:
      <<: *tv-series-from
      settings:
        parse_only: yes
    filesystem:
      path: '/home/jawilson/Dropbox/torrents/TV'
      recursive: yes
      retrieve: files
      regexp: '.*\.torrent$'
    no_entries_ok: yes
    accept_all: yes
    series_add: yes
    set:
      label: local-tv
    exec:
      on_exit:
        for_accepted: rm "{{location}}"


  # Same as above but for movies
  Local-Torrents-Movies:
    priority: 2
    template:
      - movies-global
    disable:
      - archive
      - retry_failed
      - seen
    filesystem:
      path: '/home/jawilson/Dropbox/torrents/Movies'
      recursive: yes
      retrieve: files
      regexp: '.*\.torrent$'
    no_entries_ok: yes
    accept_all: yes
    list_remove:
      - movie_list: movie queue
      - trakt_list:
          <<: *movie-trakt-list-movies
      - trakt_list:
          <<: *movie-trakt-ak-list-movies
    set:
      label: local-movies
    exec:
      on_exit:
        for_accepted: rm "{{location}}"


  Sync-TV-Shows:
    manual: yes
    template:
      - no_global # None of the global templates make sense here
    disable:
      - seen
      - seen_info_hash
      - nzb_size
      - urlrewriting
    filesystem:
      path:
        - /media/raid/videos/TV Shows/
        - /media/raid/videos/AK Shows/
      recursive: yes
      retrieve: files
      regexp: '.*\.(avi|mkv|mp4|mpg|m4v)$'
    regexp:
      reject:
        - \bsample\b: {from: title}
    <<: *tv-series
    configure_series:
      <<: *tv-series-from
      settings:
        tracking: no
        upgrade: yes
    accept_all: true


  Sync-Trakt-Shows-Deleted:
    priority: 10
    template: no_global
    seen: no
    inputs:
      - next_trakt_episodes:
          <<: *tv-trakt-list-tv-shows
          context: collected
          position: next
      - next_trakt_episodes:
          <<: *tv-trakt-ak-list-tv-shows
          context: collected
          position: next
    all_series:
      tracking: no
      parse_only: yes
    accept_all: yes
    exists_series:
      - /media/raid/videos/TV Shows
      - /media/raid/videos/AK Shows
    series_remove: yes


  Follow-Trakt-Shows:
    priority: 20
    template: [no_global,tv-trakt-follow]
    trakt_list:
      <<: *tv-trakt-list-tv-shows
      type: episodes
      strip_dates: yes
    list_remove:
      - trakt_list:
          <<: *tv-trakt-list-tv-shows
          strip_dates: yes
    list_add:
      - trakt_list:
          <<: *tv-trakt-list-tv-shows
          type: shows
          strip_dates: yes


  Follow-Trakt-Shows-AK:
    priority: 20
    template: [no_global,tv-trakt-follow]
    trakt_list:
      <<: *tv-trakt-ak-list-tv-shows
      type: episodes
      strip_dates: yes
    list_remove:
      - trakt_list:
          <<: *tv-trakt-ak-list-tv-shows
          strip_dates: yes
    list_add:
      - trakt_list:
          <<: *tv-trakt-ak-list-tv-shows
          type: shows
          strip_dates: yes


  My-TV-Shows:
    priority: 30
    template:
      - tv-global
      - tv-filter
    rss:
      url: 'http://rss.torrentleech.org/{? torrentleech.rss_key ?}'
      other_fields: [category]
    if:
      - "has_field('category')":
          regexp:
            reject_excluding:
              - '^Episodes( HD)?$': {from: category}
    archive: [tv]
    discover:
      <<: *tv-discover-from
      what:
        - next_series_seasons:
            backfill: yes
            from_start: yes
            threshold: 4
        - next_series_episodes:
            backfill: yes
            from_start: yes
    max_reruns: 2


  # Cleans movies from the movie queue (and Trakt) that we already have
  Clean-Movie-Queue:
    priority: 90
    template: no_global
    seen: no
    filesystem:
      path: /media/raid/videos/Movies/
      recursive: no
      retrieve: dirs
    imdb_lookup: yes
    tmdb_lookup: yes
    require_field: [movie_name, movie_year]
    accept_all: yes
    list_remove:
      - movie_list: movie queue
      - trakt_list:
          <<: *movie-trakt-list-movies
      - trakt_list:
          <<: *movie-trakt-ak-list-movies


  # This task queues all of the movies in my Trakt "Movie Queue" playlist
  Movie-Queue:
    priority: 100 # Always run before My-Movies task
    template: no_global # None of the global templates make sense here
    seen: local
    sequence:
      - trakt_list:
          <<: *movie-trakt-list-movies
      - trakt_list:
          <<: *movie-trakt-ak-list-movies
    no_entries_ok: yes
    accept_all: yes
    list_add:
      - movie_list: movie queue


  # The next two tasks download the queue from the previous task effectively implementing
  # a 2 day timeframe for 1080p movies, then falls back to 720p
  My-Movies-1080p:
    priority: 110
    template:
      - movies-queued
      - movies-global
    quality: 1080p+ bluray+ h264+ truehd|dtshd|dd5.1|dts


  My-Movies-720p:
    priority: 120
    template:
      - movies-queued
      - movies-global
    quality: 720p+ dvdrip+ xvid+ truehd|dtshd|dd5.1|dts|ac3
    torrent_alive:
      min_seeds: 5
    delay: 28 days # Wait 28 days for a 1080p movie before trying downloading 720p


schedules:

  #
  # Local
  #
  - tasks: [ 'Local-Torrents-*' ]
    interval:
      minutes: 15

  #
  # Series
  #
  - tasks: [ 'Follow-Trakt-Shows*', 'Sync-Trakt-Shows-Deleted' ]
    schedule:
      hour: 8
  - tasks: [ 'My-TV-Shows' ]
    schedule:
      minute: 3,18,33,48

  #
  # Movies
  #
  - tasks: [ 'Movie-Queue', 'My-Movies-*' ]
    interval:
      hours: 1

  - tasks: [ 'Clean-Movie-Queue' ]
    interval:
      weeks: 1
<commit_msg>flexget: don't ignore ssl certs<commit_after># Flexget (http://www.flexget.com) configuration file.
#
# Created by: <NAME> <<EMAIL>>
# Available from: https://github.com/jawilson/dotfiles
#
# For more information, see the README.md
#

# Use the secrets plugin to separately store credentials, etc
variables: secretfile.yml
templates:

  global:
    # Some strings I found tripping up the parsers
    manipulate:
      - title:
          replace:
            regexp: '-?bs666$'
            format: ''
      - title:
          replace:
            regexp: 's(\d\d)(\d\d)'
            format: 's\1e\2'
    if:
      - "'torrentleech' in url":
          deluge:
            username: '{? deluge.username ?}'
            password: '{? <PASSWORD> ?}'
            main_file_only: yes # Ignore all but the file that is >90% of the torrent if it exists
            keep_subs: yes
            port: 58847
      - "'torrentleech' not in url":
          deluge:
            username: '{? deluge.username ?}'
            password: '{? <PASSWORD> ?}'
            main_file_only: yes # Ignore all but the file that is >90% of the torrent if it exists
            keep_subs: yes
            port: 58846
    # Make there's 50GB free before adding more downloads
    free_space:
      path: /media/raid
      space: 50000
    # Make sure all filenames are Windows safe (for samba)
    pathscrub: windows
    # Limit the frequency of requests to domains so they don't complain about
    # using a bot
    domain_delay:
      www.torrentleech.org: 10 seconds
      rss.torrentleech.org: 10 minutes
      bt-chat.com: 5 seconds
      thexem.de: 10 seconds
    notify:
      entries:
        message: >
          {{task}} - Download started:
          {%- if series_name is defined %}
          {% set info_string = tvdb_series_name|d(series_name) ~ ' - ' ~ series_id ~ (' - ' ~ tvdb_ep_name if tvdb_ep_name|default(False) else '') %}
          {%- if trakt_series_url is defined and trakt_season is defined and trakt_episode is defined -%}
          <{{ trakt_series_url }}/seasons/{{ trakt_season }}/episodes/{{ trakt_episode }}|{{ info_string }}>
          {%- else %}
          {{ info_string }}
          {%- endif %}
          - {{quality}}
          {%- elif imdb_name is defined %}
          {% set info_string = imdb_name ~ (' (' ~ imdb_year ~ ')' if imdb_year|d(False) else '') %}
          {%- if imdb_url is defined %}
          <{{imdb_url}}|{{info_string}}>
          {%- else %}
          {{info_string}}
          {%- endif %}
          - {{quality}}{% if extras|d(False) %} 3d {{ extras|lower }}{% endif %}
          {%- else -%}
          {{title}}
          {%- endif %}
        via:
          - slack:
              web_hook_url: '{? slack.webhook_url ?}'

  global-filter:
    # Most of these are the results of problem torrents I kept seeing still pop up, so I wholesale blocked them
    # RegExr (http://www.gskinner.com/RegExr/) is a great tool for testing regexes
    regexp:
      reject:
        - (s|d)ub(s|bed)?\b: {from: title}                    # Block any subbed/dubbed/etc videos
        - \bspanish\b: {from: title}                          # Spanish releases kept cropping up
        - \b(duo|tri|quadri|tetra|penta)logy\b: {from: title} # Block series, only accept one at a time
        - \btrailer\b: {from: title}                          # I've gotten a few trailers that matched as movies. VERY annoying
        - \bR5\b: {from: title}                               # The following are poor quality types that somehow got through the quality
        - \bWEBSCR\b: {from: title}                           # features usually due to the title including a keyword like "720p" as well
        - \bscreener\b: {from: title}
        - \bTS\b: {from: title}
        - \bCam\b: {from: title}
        - '{C_P}': {from: title}                              # The following are groups with poor quality releases
        - TrTd TeaM: {from: title}
        - \[TNTVillage\]: {from: title}
        - \[facepalm\]: {from: title}
        - \bASAP\b: {from: title}
        - the.day.of.the.doctor                               # The following are titles that caused me issues from plugins
    # Require at least 10 seeds of any torrent
    torrent_alive:
      min_seeds: 10
      reject_for: 1 day
    # Filter by filenames. Allow multiple video types and rar packs (but note if there is just a
    # single .rar file it won't be accepted)
    content_filter:
      require:
        - '*.avi'
        - '*.mkv'
        - '*.mpg'
        - '*.mp4'
        - '*.r0*'
        - '*.part0*'
      reject:
        - 'password.txt'
        - '*.wmv'
    # Size and seed restrictions require real torrents
    magnets: no

  tv-anchors:
    _tv_discover_from: &tv-discover-from
      from:
        - torrentleech:
            rss_key: '{? torrentleech.rss_key ?}'
            username: '{? torrentleech.username ?}'
            password: '{? <PASSWORD> ?}'
            category: ['Episodes HD', 'Episodes']
        - flexget_archive: [tv]
        - rarbg:
            category: [41]
            use_tvdb: true
            min_seeders: 10
    _tv_trakt_list_tv_shows: &tv-trakt-list-tv-shows
      account: '{? trakt.account ?}'
      list: TV Shows
      strip_dates: yes
    _tv_trakt_ak_list_tv_shows: &tv-trakt-ak-list-tv-shows
      account: '{? trakt.ak_account ?}'
      list: TV Shows
      strip_dates: yes
    _tv_series: &tv-series
      include:
        - series.yml
      configure_series: &tv-series-from
        from:
          inputs:
            - trakt_list:
                <<: *tv-trakt-list-tv-shows
                type: shows
            - trakt_list:
                <<: *tv-trakt-ak-list-tv-shows
                type: shows

  tv-trakt-follow:
    disable:
      - seen
    accept_all: yes
    no_entries_ok: yes
    set_series_begin: yes
    manipulate:
      - series_name:
          from: trakt_series_name

  tv-filter:
    <<: *tv-series
    template: [global-filter]
    configure_series:
      <<: *tv-series-from
      settings:
        target: 720p+ webrip+
        timeframe: 14 days
        quality: 480p+ webrip+
        tracking: backfill
        season_packs: yes
    # Impose reasonable size constraints
    content_size:
      max: 5000
      min: 20
    # Prevent from downloading shows that were aquired manually
    # or are currently downloading
    exists_series:
      - "/media/raid/videos/TV Shows/{{ tvdb_series_name|default(series_name)|replace('/', '_')|replace(':', ' -')|replace(',', '') }}"
      - /media/raid/videos/AK Shows
      - /media/raid/videos/staging/tv_shows/
      - /media/raid/deluge/downloads/


  tv-global:
    archive: [tv]
    # Look up info on TheTVDB.com to fill in extra info
    thetvdb_lookup: yes
    trakt_lookup: yes
    require_field: [series_name, series_id]
    sequence:
      - configure_series:
          settings:
            set:
              movedone: >-
                /media/raid/videos/TV Shows/{{ tvdb_series_name|default(series_name)|replace('/', '_')|replace(':', ' -')|replace(',', '') }}/{% if series_id_type == 'ep' %}Season {{ series_season }}/{% endif %}
          from:
            trakt_list:
              <<: *tv-trakt-list-tv-shows
              type: shows
      - configure_series:
          settings:
            set:
              movedone: >-
                /media/raid/videos/AK Shows/{{ tvdb_series_name|default(series_name)|replace('/', '_')|replace(':', ' -')|replace(',', '') }}/{% if series_id_type == 'ep' %}Season {{ series_season }}/{% endif %}
          from:
            trakt_list:
              <<: *tv-trakt-ak-list-tv-shows
              type: shows
    set:
      queuetotop: yes
      # Rename the "content file" to something nice, use leading slash to force file to top level
      content_filename: >-
        /{{ tvdb_series_name|default(series_name)|replace('/', '_')|replace(':', ' -')|replace(',', '') }} - {{ series_id }}{% if tvdb_ep_name|default(False) %} - {{ tvdb_ep_name|replace('/', '_')|replace(':', ' -')|replace(',', '') }}{% endif %} - {{ quality }}
      label: tv
    # This is a custom plugin, it is part of my rar-unpacking method,
    # it changes 'movedone' based on the regexp in the key
    content_sort:
      '*.rar': '/media/raid/deluge/downloads/completed/tv_shows/'


  movie-anchors:
    _movie_trakt_list_movies: &movie-trakt-list-movies
      account: '{? trakt.account ?}'
      list: Movie Queue
      type: movies
    _movie_trakt_ak_list_movies: &movie-trakt-ak-list-movies
      account: '{? trakt.ak_account ?}'
      list: Movies
      type: movies

  movies-global:
    archive: [movies]
    imdb_lookup: yes
    trakt_lookup: yes
    # Download propers, since they will have the same content_filename,
    # lower/non-propers will be overwritten
    proper_movies: yes
    manipulate:
      - extras:
          from: title
          extract: '($|half.?(?:sbs|tab|ou))'
    set:
      # Give folders/files nice names
      movedone: "/media/raid/videos/Movies/{{ imdb_name|replace('/', '_')|replace(':', ' -')|replace(',', '') }} ({{ imdb_year }})"
      # Rename the "content file" to something nice, use leading slash to force file to top level
      content_filename: >-
        /{{ imdb_name|replace('/', '_')|replace(':', ' -')|replace(',', '') }} ({{ imdb_year }}) - {{ quality }}{% if extras|default(False) %} 3d {{ extras|lower }}{% endif %}
    # This is a custom plugin, it is part of my rar-unpacking method, it changes
    # 'movedone' based on the regexp in the key
    content_sort:
      '*.rar': '/media/raid/deluge/downloads/completed/movies/'

  # This template uses the movie queue to find movies from various sources
  movies-queued:
    template: [global-filter]
    rss:
      url: 'http://rss.torrentleech.org/{? torrentleech.rss_key ?}'
      other_fields: [category]
    # Some feeds might include TV Shows, ignore them
    if:
      - "has_field('category')":
          regexp:
            reject_excluding:
              - '^(HD|BDRip|DVDRip.DVDScreener|DVD-R|Documentaries)$': {from: category}
    discover:
      release_estimations:
        optimistic: 30 days
      what:
        - movie_list: movie queue
      from:
        - torrentleech:
            rss_key: '{? torrentleech.rss_key ?}'
            username: '{? torrentleech.username ?}'
            password: '{? <PASSWORD> ?}'
            category: ['HD', 'BDRip', 'DVDRip', 'DVDR', 'Documentaries']
        - flexget_archive: [movies]
        - rarbg:
            category: [44, 45]
            min_seeders: 10
    regexp:
      reject:
        - s\d+e\d+: {from: title}
        - '\d{4}.\d{2}.\d{2}': {from: title}
        - \d+x\d+: {from: title}
        - \baac2: {from: title} # No 2 channel audio
    # Impose reasonable size constraints
    content_size:
      max: 20000
      min: 1000
    # Check for already downloaded or currently downloading movies
    exists_movie:
      - /media/raid/videos/Movies/
      - /media/raid/videos/staging/movies
      - /media/raid/deluge/downloads/
    list_match:
      from:
        - movie_list: movie queue
    list_remove:
      - trakt_list:
          <<: *movie-trakt-list-movies
      - trakt_list:
          <<: *movie-trakt-ak-list-movies
    set:
      label: my-movies


# This is where we pull everything together
tasks:

  # Use a local folder (synced with Dropbox) as a source
  # I can drop torrents in this folder and they are synced with Dropbox, always
  # accepted, then the original file is deleted
  Local-Torrents-TV:
    priority: 1
    <<: *tv-series
    template:
      - tv-global
    disable:
      - archive
      - retry_failed
      - seen
    all_series:
      parse_only: yes
      assume_special: yes
      season_packs: yes
    configure_series:
      <<: *tv-series-from
      settings:
        parse_only: yes
    filesystem:
      path: '/home/jawilson/Dropbox/torrents/TV'
      recursive: yes
      retrieve: files
      regexp: '.*\.torrent$'
    no_entries_ok: yes
    accept_all: yes
    series_add: yes
    set:
      label: local-tv
    exec:
      on_exit:
        for_accepted: rm "{{location}}"


  # Same as above but for movies
  Local-Torrents-Movies:
    priority: 2
    template:
      - movies-global
    disable:
      - archive
      - retry_failed
      - seen
    filesystem:
      path: '/home/jawilson/Dropbox/torrents/Movies'
      recursive: yes
      retrieve: files
      regexp: '.*\.torrent$'
    no_entries_ok: yes
    accept_all: yes
    list_remove:
      - movie_list: movie queue
      - trakt_list:
          <<: *movie-trakt-list-movies
      - trakt_list:
          <<: *movie-trakt-ak-list-movies
    set:
      label: local-movies
    exec:
      on_exit:
        for_accepted: rm "{{location}}"


  Sync-TV-Shows:
    manual: yes
    template:
      - no_global # None of the global templates make sense here
    disable:
      - seen
      - seen_info_hash
      - nzb_size
      - urlrewriting
    filesystem:
      path:
        - /media/raid/videos/TV Shows/
        - /media/raid/videos/AK Shows/
      recursive: yes
      retrieve: files
      regexp: '.*\.(avi|mkv|mp4|mpg|m4v)$'
    regexp:
      reject:
        - \bsample\b: {from: title}
    <<: *tv-series
    configure_series:
      <<: *tv-series-from
      settings:
        tracking: no
        upgrade: yes
    accept_all: true


  Sync-Trakt-Shows-Deleted:
    priority: 10
    template: no_global
    seen: no
    inputs:
      - next_trakt_episodes:
          <<: *tv-trakt-list-tv-shows
          context: collected
          position: next
      - next_trakt_episodes:
          <<: *tv-trakt-ak-list-tv-shows
          context: collected
          position: next
    all_series:
      tracking: no
      parse_only: yes
    accept_all: yes
    exists_series:
      - /media/raid/videos/TV Shows
      - /media/raid/videos/AK Shows
    series_remove: yes


  Follow-Trakt-Shows:
    priority: 20
    template: [no_global,tv-trakt-follow]
    trakt_list:
      <<: *tv-trakt-list-tv-shows
      type: episodes
      strip_dates: yes
    list_remove:
      - trakt_list:
          <<: *tv-trakt-list-tv-shows
          strip_dates: yes
    list_add:
      - trakt_list:
          <<: *tv-trakt-list-tv-shows
          type: shows
          strip_dates: yes


  Follow-Trakt-Shows-AK:
    priority: 20
    template: [no_global,tv-trakt-follow]
    trakt_list:
      <<: *tv-trakt-ak-list-tv-shows
      type: episodes
      strip_dates: yes
    list_remove:
      - trakt_list:
          <<: *tv-trakt-ak-list-tv-shows
          strip_dates: yes
    list_add:
      - trakt_list:
          <<: *tv-trakt-ak-list-tv-shows
          type: shows
          strip_dates: yes


  My-TV-Shows:
    priority: 30
    template:
      - tv-global
      - tv-filter
    rss:
      url: 'http://rss.torrentleech.org/{? torrentleech.rss_key ?}'
      other_fields: [category]
    if:
      - "has_field('category')":
          regexp:
            reject_excluding:
              - '^Episodes( HD)?$': {from: category}
    archive: [tv]
    discover:
      <<: *tv-discover-from
      what:
        - next_series_seasons:
            backfill: yes
            from_start: yes
            threshold: 4
        - next_series_episodes:
            backfill: yes
            from_start: yes
    max_reruns: 2


  # Cleans movies from the movie queue (and Trakt) that we already have
  Clean-Movie-Queue:
    priority: 90
    template: no_global
    seen: no
    filesystem:
      path: /media/raid/videos/Movies/
      recursive: no
      retrieve: dirs
    imdb_lookup: yes
    tmdb_lookup: yes
    require_field: [movie_name, movie_year]
    accept_all: yes
    list_remove:
      - movie_list: movie queue
      - trakt_list:
          <<: *movie-trakt-list-movies
      - trakt_list:
          <<: *movie-trakt-ak-list-movies


  # This task queues all of the movies in my Trakt "Movie Queue" playlist
  Movie-Queue:
    priority: 100 # Always run before My-Movies task
    template: no_global # None of the global templates make sense here
    seen: local
    sequence:
      - trakt_list:
          <<: *movie-trakt-list-movies
      - trakt_list:
          <<: *movie-trakt-ak-list-movies
    no_entries_ok: yes
    accept_all: yes
    list_add:
      - movie_list: movie queue


  # The next two tasks download the queue from the previous task effectively implementing
  # a 2 day timeframe for 1080p movies, then falls back to 720p
  My-Movies-1080p:
    priority: 110
    template:
      - movies-queued
      - movies-global
    quality: 1080p+ bluray+ h264+ truehd|dtshd|dd5.1|dts


  My-Movies-720p:
    priority: 120
    template:
      - movies-queued
      - movies-global
    quality: 720p+ dvdrip+ xvid+ truehd|dtshd|dd5.1|dts|ac3
    torrent_alive:
      min_seeds: 5
    delay: 28 days # Wait 28 days for a 1080p movie before trying downloading 720p


schedules:

  #
  # Local
  #
  - tasks: [ 'Local-Torrents-*' ]
    interval:
      minutes: 15

  #
  # Series
  #
  - tasks: [ 'Follow-Trakt-Shows*', 'Sync-Trakt-Shows-Deleted' ]
    schedule:
      hour: 8
  - tasks: [ 'My-TV-Shows' ]
    schedule:
      minute: 3,18,33,48

  #
  # Movies
  #
  - tasks: [ 'Movie-Queue', 'My-Movies-*' ]
    interval:
      hours: 1

  - tasks: [ 'Clean-Movie-Queue' ]
    interval:
      weeks: 1

{'fraction_non_alphanumeric': 0.12196596700354151, 'fraction_numerical': 0.009559183438426766, 'mean_word_length': 1.9361738101276524, 'pattern_counts': {'":': 8, '<': 129, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2596100', 'n_tokens_mistral': 11962, 'n_tokens_neox': 11304, 'n_words': 2779}