Exemplo n.º 1
0
QString VideoMetadata::FilenameToMeta(const QString &file_name, int position)
{
    // position 1 returns title, 2 returns season,
    //          3 returns episode, 4 returns subtitle

    QString cleanFilename = file_name.left(file_name.lastIndexOf('.'));
    cleanFilename.replace(QRegExp("%20"), " ");
    cleanFilename.replace(QRegExp("_"), " ");
    cleanFilename.replace(QRegExp("\\."), " ");

    QString season_translation = QObject::tr("Season");
    QString episode_translation = QObject::tr("Episode");

    // Primary Regexp
    QString separator = "(?:\\s?(?:-|/)?\\s?)?";
    QString regexp = QString(
                  "^(.*[^s0-9])" // Title
                  "%1" // optional separator
                  "(?:s|(?:%2))?" // season marker
                  "%1" // optional separator
                  "(\\d{1,4})" // Season
                  "%1" // optional separator
                  "(?:[ex/]|%3)" // episode marker
                  "%1" // optional separator
                  "(\\d{1,3})" // Episode
                  "%1" // optional separator
                  "(.*)$" // Subtitle
                  ).arg(separator)
                   .arg(season_translation).arg(episode_translation);
    QRegExp filename_parse(regexp,
                  Qt::CaseInsensitive, QRegExp::RegExp2);

    // Cleanup Regexp
    QString regexp2 = QString("(%1(?:%2%1\\d*%1)*%1)$")
                             .arg(separator).arg(season_translation);
    QRegExp title_parse(regexp2, Qt::CaseInsensitive, QRegExp::RegExp2);

    int pos = filename_parse.indexIn(cleanFilename);
    if (pos > -1)
    {
        QString title = filename_parse.cap(1);
        QString season = filename_parse.cap(2);
        QString episode = filename_parse.cap(3);
        QString subtitle = filename_parse.cap(4);

        // Clean up the title
        int pos2 = title_parse.indexIn(title);
        if (pos2 > -1)
            title = title.left(pos2);
        title = title.right(title.length() -
                     title.lastIndexOf('/') -1);

        // Return requested value
        if (position == 1 && !title.isEmpty())
            return title.trimmed();
        else if (position == 2)
            return season.trimmed();
        else if (position == 3)
            return episode.trimmed();
        else if (position == 4)
            return subtitle.trimmed();
    }
    else if (position == 1)
    {
        QString title = cleanFilename;

        // Clean up the title
        title = title.right(title.length() -
                     title.lastIndexOf('/') -1);

        title = eatBraces(title, "[", "]");
        title = eatBraces(title, "(", ")");
        title = eatBraces(title, "{", "}");
        return title.trimmed();
    }
    else if (position == 2 || position == 3)
        return QString("0");

    return QString();
}
Exemplo n.º 2
0
gchar * rs_enfuse(RS_BLOB *rs, GList *files, gboolean quick, gint boundingbox)
{
  gint num_selected = g_list_length(files);
  gint i;
  gchar *name = NULL;
  gchar *file = NULL;
  GString *outname = g_string_new("");
  GString *fullpath = NULL;
  gchar *align_options = NULL;
  GString *enfuse_options = g_string_new("");
  gdouble extend_negative = 0.0;
  gdouble extend_positive = 0.0;
  gdouble extend_step = 0.0;

  GTimer *timer = g_timer_new();
  g_timer_start(timer);

  if (!rs_conf_get_double(
			  (num_selected == 1) ? CONF_ENFUSE_EXTEND_NEGATIVE_SINGLE : CONF_ENFUSE_EXTEND_NEGATIVE_MULTI,
			  &extend_negative))
    extend_negative = (num_selected == 1) ? DEFAULT_CONF_ENFUSE_EXTEND_NEGATIVE_SINGLE : DEFAULT_CONF_ENFUSE_EXTEND_NEGATIVE_MULTI;

  if (!rs_conf_get_double(
			  (num_selected == 1) ? CONF_ENFUSE_EXTEND_POSITIVE_SINGLE : CONF_ENFUSE_EXTEND_POSITIVE_MULTI,
			  &extend_positive))
    extend_positive = (num_selected == 1) ? DEFAULT_CONF_ENFUSE_EXTEND_POSITIVE_SINGLE : DEFAULT_CONF_ENFUSE_EXTEND_POSITIVE_MULTI;

  if (!rs_conf_get_double(
			  (num_selected == 1) ? CONF_ENFUSE_EXTEND_STEP_SINGLE : CONF_ENFUSE_EXTEND_STEP_MULTI,
			  &extend_step))
    extend_step = (num_selected == 1) ? DEFAULT_CONF_ENFUSE_EXTEND_STEP_SINGLE : DEFAULT_CONF_ENFUSE_EXTEND_STEP_MULTI;

  gboolean align = DEFAULT_CONF_ENFUSE_ALIGN_IMAGES;
  rs_conf_get_boolean_with_default(CONF_ENFUSE_ALIGN_IMAGES, &align, DEFAULT_CONF_ENFUSE_ALIGN_IMAGES);

  gboolean extend = DEFAULT_CONF_ENFUSE_EXTEND;
  rs_conf_get_boolean_with_default(CONF_ENFUSE_EXTEND, &extend, DEFAULT_CONF_ENFUSE_EXTEND);

  gint method = 0;
  if (!rs_conf_get_integer(CONF_ENFUSE_METHOD, &method))
    method = DEFAULT_CONF_ENFUSE_METHOD;

  if (boundingbox == -1) 
    {
      if (!rs_conf_get_integer(CONF_ENFUSE_SIZE, &boundingbox))
	boundingbox = DEFAULT_CONF_ENFUSE_SIZE;
    }

  gchar *method_options = NULL;
  if (method == ENFUSE_METHOD_EXPOSURE_BLENDING_ID) {
    method_options = g_strdup(ENFUSE_OPTIONS_EXPOSURE_BLENDING);
  } else if (method == ENFUSE_METHOD_FOCUS_STACKING_ID) {
    method_options = g_strdup(ENFUSE_OPTIONS_FOCUS_STACKING);
    extend = FALSE;
  }

  if (quick)
    enfuse_options = g_string_append(enfuse_options, ENFUSE_OPTIONS_QUICK);
  else
    enfuse_options = g_string_append(enfuse_options, ENFUSE_OPTIONS);
  enfuse_options = g_string_append(enfuse_options, " ");
  enfuse_options = g_string_append(enfuse_options, method_options);

  gchar *first = NULL;
  gchar *parsed_filename = NULL;
  gchar *temp_filename = g_strdup("/tmp/.rawstudio-temp.png");

  RS_PROGRESS *progress = NULL;
  if (quick == FALSE)
    {
      progress = gui_progress_new("Enfusing...", 5);
      GUI_CATCHUP();
    }

  /* if only one picture is selected we have to do extending, it doesn't make sense to run enfuse on a single photo otherwise... */
  if (num_selected == 1)
      extend = TRUE;

  if (g_list_length(files))
    {
      for(i=0; i<num_selected; i++)
	{
	  name = (gchar*) g_list_nth_data(files, i);
	  if (first == NULL)
	    first = g_strdup(name);
	  file = g_malloc(sizeof(char)*strlen(name));
	  sscanf(g_path_get_basename(name), "%[^.]", file);
	  outname = g_string_append(outname, file);
	  g_free(file);
	  if (i+1 != num_selected)
	    outname = g_string_append(outname, "+");
	}
      fullpath = g_string_new(g_path_get_dirname(name));
      fullpath = g_string_append(fullpath, "/");
      fullpath = g_string_append(fullpath, outname->str);
      fullpath = g_string_append(fullpath, "_%2c");
      fullpath = g_string_append(fullpath, ".rse");
      parsed_filename = filename_parse(fullpath->str, g_strdup(first), 0, FALSE);
      g_string_free(outname, TRUE);
      g_string_free(fullpath, TRUE);
    }

  if (quick == FALSE)
    {
      g_usleep(500000); /* FIXME */
      gui_progress_advance_one(progress); /* 1 - initiate */
    }

  GList *exported_names = export_images(rs, files, extend, extend_negative, extend_step, extend_positive, extend_step, boundingbox, quick);

  if (quick == FALSE)
    gui_progress_advance_one(progress); /* 2 - after exported images */

  GList *aligned_names = NULL;
  if (has_align_image_stack() && num_selected > 1 && quick == FALSE && align == TRUE)
    {
      aligned_names = align_images(exported_names, align_options);
      g_free(align_options);
    }
  else
      aligned_names = exported_names;

  if (quick == FALSE)
    gui_progress_advance_one(progress); /* 3 - after aligned images */

  enfuse_images(aligned_names, temp_filename, enfuse_options->str, has_enfuse_mp());
  g_string_free(enfuse_options, TRUE);

  if (quick == FALSE)
    gui_progress_advance_one(progress); /* 4 - after enfusing */

  /* delete all temporary files */
  if (exported_names != aligned_names) {
      delete_files_in_list(aligned_names);
      g_list_free(aligned_names);
  }
  delete_files_in_list(exported_names);
  g_list_free(exported_names);

  /* FIXME: should use the photo in the middle as it's averaged between it... */
  rs_exif_copy(first, temp_filename, "sRGB", RS_EXIF_FILE_TYPE_PNG);
  if (first)
    g_free(first);

  GString *mv = g_string_new("mv ");
  mv = g_string_append(mv, temp_filename);
  mv = g_string_append(mv, " ");
  mv = g_string_append(mv, parsed_filename);
  printf("command: %s\n", mv->str);
  if(system(mv->str)); 
  g_string_free(mv, TRUE);

  if (quick == FALSE)
    {
      gui_progress_advance_one(progress); /* 5 - misc file operations */
      gui_progress_free(progress);
    }

  g_timer_stop(timer);
  printf("Total execution time: %.2f\n", g_timer_elapsed(timer, NULL));

  return parsed_filename;
}