Skip to content

Instantly share code, notes, and snippets.

@rlaphoenix
Last active July 26, 2021 04:13
Show Gist options
  • Save rlaphoenix/22c482980f0f7d2d683c6df6153dc575 to your computer and use it in GitHub Desktop.
Save rlaphoenix/22c482980f0f7d2d683c6df6153dc575 to your computer and use it in GitHub Desktop.
FraMeSToR style P2P Movies and TV filebot template
{
// Requirements: MediaInfo and libmediainfo v19.09 or newer.
// Examples:
// "The.IT.Crowd.S01E01.Yesterdays.Jam.AMZN.1080p.DDP.5.1.AVC.WEB-DL-FraMeSToR"
// "Luca.2021.Repack.BluRay.2160p.HDR.DDP.5.1.Atmos.HEVC.REMUX-FraMeSToR"
def Movie = true;
def Group = "FraMeSToR"; // Only used if no Group Tag is detected in the original filenames
def Source = "BluRay"; // e.g. BluRay, DVD, and so on
def Edition = "Unrated Open Matte"; // If empty or not set, it will be detected from the original filename
def Tags = "HYBRID REMUX";
// =========================== //
if ((m = fn =~ /-(\w+)$/)) {
Group = m.group(1)
}
if (!Edition) {
Edition = []
if ((m = fn.space(".") =~ /(?i)\b(open\.matte|unrated|extended)\b/)) {
Edition.add(m.group(1).tokenize(".")*.toLowerCase()*.capitalize().join(" "))
}
if ((m = fn.space(".") =~ /(?i)\b(repack|proper)\b/)) {
Edition.add(m.group(1).tokenize(".")*.toLowerCase()*.capitalize().join(" "))
}
Edition = Edition.join(" ")
}
def Ac = audio[0].format_commercial
def Ach = (any{ audio.ChannelLayout*.replaceAll(/Object Based/)*.split()*.collect{ it.replace(/LFE/, '0.1').replaceFirst(/(\b(?:L|R|C)(?:b+|s+|w+)?\b)/, '1').toDouble() }*.sum().collect{ it == null ? audio.findAll{ it.ChannelLayout == /Object Based/ }.Channels*.replace(/8/,'7.1')*.replace(/6/,'5.1')[0] + ' (Objs)' : it }[0] }{ audio.Channels[0].toDouble() }).toString()
switch (Ac) {
case "Dolby TrueHD with Dolby Atmos": Ac = "TrueHD Atmos"; break
case "Dolby TrueHD": Ac = "TrueHD"; break
case "DTS-HD Master Audio": Ac = "DTS-HD MA"; break
case "DTS-ES Matrix": Ac = "DTS-ES"; break
case "Dolby Digital": Ac = "DD"; break
case "Dolby Digital Plus": Ac = "DDP"; break
case "HE-AAC": Ac = "AAC"; break
}
if(any{audio[0].format_additionalfeatures}{false}){
switch(audio[0].format_additionalfeatures) {
case "XLL X": Ac = audio[0].format + "-X"; break
}
}
def Fn = [
// Title
n.replace(" - ", " "),
// Year or S00E00 and Episode Name
Movie ? y : (S00E00 + " " + t),
// Edition, e.g. Repack, Proper, Open Matte, Unrated, Extended, etc.
Edition,
// Source, e.g. BluRay, DVD, and so on
Source,
// Resolution and Scan, e.g. 480i, 576p, 1080i, 1080p, etc.
vf.replaceAll(/[^0-9]/)+(any{hpi}{vf}.replace("m", "i").replaceAll(/[^a-z]/)),
// Audio Codec and Channels, e.g. AAC 2.0, DDP 5.1, TrueHD 7.1 Atmos, etc.
Ac.contains("@") ? Ac.replace('@', Ach) : (Ac + " " + Ach),
// Dynamic Range
any{hdr}{" "},
// Video Codec
video[0].Format,
// Tags
Tags
].join(" ") + "-" + Group
// Condense spaces, replace spaces with dots
Fn = Fn.replaceAll(/[ ]{2,}/, " ").space(".")
// Remove special characters that may not be usable on some file systems
Fn = Fn.replaceAll(/([<>:"\/\\!|?*,'()_]|\s|[\x00-\x1F\x7F]|(?:(?!\p{IsLatin})\p{L})|\.$)/).ascii()
return Fn
}