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;
}
Ejemplo n.º 2
0
QMap<QString, QString> AnitomyWrapper::parse(QString file_name) {
  anitomy_string title = toAnitomyFormat(file_name);

  QMap<QString, QString> data;

  try {
    anitomy.Parse(title);
  } catch (std::regex_error& e) {
    Q_UNUSED(e)
    qWarning() << "Error parsing: " << QString::fromWCharArray(title.c_str());
    return QMap<QString, QString>();
  }

  auto& elements = anitomy.elements();

  data.insert("title", QString::fromWCharArray(
                           elements.get(anitomy::kElementAnimeTitle).c_str()));
  data.insert("episode",
              QString::fromWCharArray(
                  elements.get(anitomy::kElementEpisodeNumber).c_str()));
  data.insert("subs", QString::fromWCharArray(
                          elements.get(anitomy::kElementReleaseGroup).c_str()));

  QString res = QString::fromWCharArray(
      elements.get(anitomy::kElementVideoResolution).c_str());

  // Standardize the resolutions a bit
  if (res.contains("x")) {
    res = res.split("x").last() + "p";
  } else if (res.contains("X")) {
    res = res.split("X").last() + "p";
  } else if (res.isEmpty()) {
    res = "720p";  // Let's assume it is 720p
  }
  data.insert("res", res);

  return data;
}