Skip to main content
Version: Latest

Macros

Macros are a great way to enhance your workflow by adding custom logic/data processing to the input data provided by autobrr. Macros are currently supported by input fields by Filters, in two sections: Actions and External (filters).

Implementation

The template functionality is provided by the Go template engine. This is an extremely powerful scripting platform that can perform operations, evaluations, and manipulate values at the user configuration level. Further information on the functionality of this platform can be found on its official documentation page.

Autobrr enhances the Go template engine with Sprig template functions which provide the possibility for workflows involving more complex logic than initially provided by the Go template engine.

Please take note that Sprig has some of its own edge-cases:

Most of the [Sprig] regex functions are unfortunately significantly broken when it comes to using them in pipelines. By broken I mean the functions technically work, but their usage I don't think would be intuitive to anyone, and that usage is difficult.

-- Open issue on Sprig's Github page

Another intricate edge-case from which Sprig suffers from is that every RegEx directive containing a backslash has to be escaped twice. Put another way, what was once a single backslash, now becomes a double backslash. For example, \d becomes \\d.

Available functions

For the functions provided by the Go template engine, please reference its its official documentation page.

Available Sprig function, along with the relevant examples can be found at Pydio.com.

Available variables

Click to view supported variables
VariableTypeDescription
{{.Artists}}stringArtists
{{.Audio}}[]stringAudio codecs/formats array
{{.AudioChannels}}stringAudio channels configuration
{{.AudioFormat}}stringAudio format
{{.Bitrate}}stringRelease bitrate
{{.Bonus}}[]stringBonus features array
{{.Categories}}[]stringCategories
{{.Category}}stringCategory
{{.Codec}}[]stringVideo codecs array
{{.Container}}stringContainer format
{{.CurrentDay}}intCurrent Day
{{.CurrentHour}}intCurrent Hour
{{.CurrentMinute}}intCurrent Minute
{{.CurrentMonth}}intCurrent Month
{{.CurrentSecond}}intCurrent Second
{{.CurrentYear}}intCurrent Year
{{.Day}}intRelease day
{{.Description}}stringRelease description
{{.DownloadURL}}stringDownload URL
{{.Episode}}intParsed episode
{{.FilterID}}intFilter identifier
{{.FilterName}}stringFilter name
{{.Freeleech}}boolFreeleech status
{{.FreeleechPercent}}intFreeleech percentage
{{.Group}}stringRelease group
{{.GroupID}}stringGroupID
{{.HasCue}}boolHas .cue file
{{.HasLog}}boolHas log file
{{.HDR}}stringParsed HDR (DV, HDR, HDR10)
{{.Implementation}}stringImplementation type
{{.Indexer}}stringIndexer identifier
{{.IndexerIdentifier}}stringIndexer identifier
{{.IndexerIdentifierExternal}}stringExternal indexer identifier
{{.IndexerName}}stringIndexer name
{{.InfoUrl}}stringInfo URL
{{.IsDuplicate}}boolIs duplicate release
{{.Language}}[]stringLanguage array
{{.Leechers}}intNumber of leechers
{{.LogScore}}intLog score for music releases
{{.MagnetURI}}stringMagnet link URI
{{.MetaIMDB}}stringIMDB ID
{{.Month}}intRelease month
{{.Origin}}stringRelease origin
{{.Other}}[]stringOther attributes array
{{.PreTime}}stringPre time
{{.Proper}}boolIs proper release
{{.Protocol}}stringProtocol type
{{.RecordLabel}}stringRecord label
{{.Region}}stringRegion information
{{.Repack}}boolIs repack release
{{.Resolution}}stringParsed resolution (1080p)
{{.Season}}intParsed season
{{.Seeders}}intNumber of seeders
{{.Size}}uintSize (in bytes)
{{.SizeString}}stringSizeString (including unit string)
{{.SkipDuplicateProfileID}}intSkip duplicate profile ID
{{.SkipDuplicateProfileName}}stringSkip duplicate profile name
{{.Source}}stringParsed source (BluRay, WEB-DL)
{{.Tags}}stringRelease tags (comma separated)
{{.Title}}stringParsed title (That Movie)
{{.TorrentDataRawBytes}}[]byteRaw torrent file data
{{.TorrentHash}}stringTorrent hash
{{.TorrentID}}stringTorrentID
{{.TorrentName}}stringRelease name as announced
{{.TorrentPathName}}stringPath to downloaded .torrent file in /tmp
{{.TorrentTmpFile}}stringTemporary torrent file path
{{.TorrentUrl}}stringFull url to download torrent
{{.Type}}stringType e.g. episode
{{.Uploader}}stringRelease uploader
{{.Website}}stringWebsite URL
{{.Year}}intParsed year

Examples

Simple examples of this extensive functionality can be found below.

  • Escape torrent name - {{ .TorrentName | js }}

Dynamic categories in qBittorrent

Dynamic resolution for eg movies or tv. Very useful to keep things separated and easy to manage. With well-named releases this works great as a Plex library.

Category: movies-{{ .Resolution }} = movies-1080p, movies-2160p

Tags

Dynamic tags based on indexer, resolution or other

  • Tags: {{ .Indexer }} = mockindexer
  • Tags: {{ .Resolution }} = 2160p

Dynamic date and time

Could be used to build dynamic save paths etc.

  • {{ .CurrentYear }}
  • {{ .CurrentMonth | printf "%02d"}}

Dynamic movie filter with hdr/dv

Category: movies-{{ .Resolution }}{{ if .HDR }}-{{ .HDR }}{{ end }}

Custom regex example

One user in our Discord wanted to have a custom watch folder for TV shows but without the episode in the name. The best solution we could find was to use... a bit of regex. It's not great, but it's not terrible either.

The relevant query is:

{{- $filename := (regexReplaceAll "(?i)(.*).torrent$" (osBase .TorrentPathName) "${1}") -}}
{{- $pattern := "([\\.\\s\\-\\(])([Ss]\\d+)[\\.\\s\\-]?([Ee]\\d+)?([\\.\\s\\-\\)])" -}}
{{- $repl := "${1}${2}${4}" -}}
{{- if ge (len .TorrentName) (len $filename) -}}
{{- regexReplaceAll $pattern .TorrentName $repl -}}
{{- else -}}
{{- regexReplaceAll $pattern $filename $repl -}}
{{- end -}}
Heads up

Do note that the minus (-) signs here denote that the template bars are not allowed to emit/allow any whitespace before/after them (as would've been the case without the minus signs).