erengy / atf

Advanced title formatting (WIP)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

atf

atf is an implementation of the scripting language known as Advanced Title Formatting or Tagz. The language has been used by some popular applications such as Winamp, foobar2000, Mp3tag and MusicBrainz Picard.

Basically, it converts this:

[%artist% - ][%album% - ][$num(%track%,2) - ]$if2(%title%,$filepart(%filename%))

...to this:

Iron Maiden - Brave New World - 04 - Blood Brothers

Usage

(atf is currently not in a usable state.)

The library doesn't have any fields on its own. Applications have to override the EvaluateField virtual function in order to provide the data to corresponding fields:

std::string CustomAtf::EvaluateField(const std::string& field) const {
  const std::map<std::string, std::string> fields{
    {"artist", "Iron Maiden"},
    {"album", "Brave New World"},
    {"track", "4"},
    {"title", "Blood Brothers"},
  };

  auto it = fields.find(field);
  return it != fields.end() ? it.second : std::string();
}

The library does provide you with a basic set of functions such as if and len. You may override the EvaluateFunction virtual function according to your application's needs:

std::string CustomAtf::EvaluateFunction(
    const std::string& name, const std::vector<std::string>& params) const {
  std::string result;

  // $reverse(x)
  // Reverses the order of the characters in string x.
  if (name == "reverse" && params.size() == 1) {
    const auto& x = params.back();
    std::copy_backward(x.begin(), x.end(), result.end());
    return result;
  }

  return Atf::EvaluateFunction(name, params);
}

Documentation

License

atf is licensed under the MIT License.

About

Advanced title formatting (WIP)

License:MIT License


Languages

Language:C++ 100.0%