Ejemplo n.º 1
0
ResultContainer AnitomyWrapper::parse(const QString &t_filename) {
  AnitomyString title = toAnitomyFormat(t_filename);

  // Parse the filename through anitomy
  try {
    m_anitomy.Parse(title);
  } catch (std::regex_error &e) {
    qWarning() << "Error parsing: " << fromAnitomyFormat(title);
    qWarning() << e.what();
    return ResultContainer();
  }

  auto &elements = m_anitomy.elements();

  /* Standardize the resolutions a bit
   * anitomy grabs the resolution based on the filename
   * Possibilities:
   *   1920x1080
   *   1280X720
   *   480p
   */
  QString res =
      fromAnitomyFormat(elements.get(anitomy::kElementVideoResolution));

  if (res.contains("x")) {
    // If res contains an 'x', just assume it's of the form WIDTHxHEIGHT
    // Convert it to HEIGHTp instead
    res = res.split("x").last() + "p";
  } else if (res.contains("X")) {
    // If res contains an 'X', just assume it's of the form WIDTHXHEIGHT
    // Convert it to HEIGHTp instead
    res = res.split("X").last() + "p";
  } else if (res.isEmpty()) {
    // If we don't have anything stored for res, assume it's 720p
    // Most subgroups don't list a resolution if they just release 720p
    res = "720p";
  }

  ResultContainer data;

  data.insert(Result::Title,
              fromAnitomyFormat(elements.get(anitomy::kElementAnimeTitle)));
  data.insert(Result::Episode,
              fromAnitomyFormat(elements.get(anitomy::kElementEpisodeNumber)));
  data.insert(Result::SubGroup,
              fromAnitomyFormat(elements.get(anitomy::kElementReleaseGroup)));
  data.insert(Result::Resolution, res);

  return data;
}