Don't use two reports, just gather all info ({Fullname} + {Tags}) in one
Don't use the inner foreach loop, instead regexescape the current tag (if necessary) and use a regexmatch to
gather all files with that tag. Reformat that result, write it to the file.
Untested, no time to build any sample data:
Long version:
Code: Select all
$allInfo = report("{FullName}?{Tags}<crlf>");
$allTags = regexmatches($allInfo, "\?.*?(?=$)");
foreach ($tag, formatlist(replace($allTags, "?"), "nde", "|")) {
$list = "";
$escTag = regexreplace($tag, "([\\^$.+*|?(){\[])", "\$1");
$matches = regexmatches($allInfo, "^.*?\?.*?$escTag.*?(?=$)", "<crlf>");
if ($matches) {
$list = $list . "<crlf>" . formatlist(regexreplace($matches, "\?.*(?=$)"), "nde", "<crlf>");
}
writefile("<curpath>\$tag.m3u8", $list, , "tu");
}
If all tags don't need to be escaped and all items contain at least one tag, an even shorter version could be used:
Code: Select all
$allInfo = report("{FullName}?{Tags}<crlf>");
$allTags = regexmatches($allInfo, "\?.*?(?=$)");
foreach ($tag, formatlist(replace($allTags, "?"), "nde", "|")) {
$list = "";
$matches = regexmatches($allInfo, "^.*?\?.*?$tag.*?(?=$)", "<crlf>");
$list = $list . "<crlf>" . formatlist(regexreplace($matches, "\?.*(?=$)"), "nde", "<crlf>");
writefile("<curpath>\$tag.m3u8", $list, , "tu");
}
The rule of thumb is: Always try to replace a foreach loop (with ENOUGH entries) with a regexmatch (if possible).