Exemple #1
0
int upload_photo(const char *photoset, const char *photo, const char *path) {
    flickcurl_upload_status* status;
    flickcurl_upload_params params;
    cached_photoset *cps;
    cached_photo *cp;
    int retval = FAIL;

    pthread_rwlock_wrlock(&cache_lock);

    cps = g_hash_table_lookup(photoset_ht, photoset);

    if(!cps)
        goto fail;

    if(!(cp = g_hash_table_lookup(cps->photo_ht, photo)))
        goto fail;

    memset(&params, '\0', sizeof(flickcurl_upload_params));
    params.safety_level = 1;    /* default safety */
    params.content_type = 1;    /* default photo */
    params.photo_file = path;
    params.description = "Uploaded using FlickrMS";
    params.title = cp->ci.name;

    status = flickcurl_photos_upload_params(fc, &params);

    if(status) {
        if( cps->ci.dirty == DIRTY ) { // if photoset is dirty, create it
            char * photosetid = flickcurl_photosets_create(fc, cps->ci.name, NULL, status->photoid, NULL);

            if( photosetid ) {
                cps->ci.id = photosetid;
                cps->ci.dirty = CLEAN;
            }
        }
        else if( strcmp( cps->ci.id, "" ) ) { // if photoset has an id, add new photo to it
            flickcurl_photosets_addPhoto(fc, cps->ci.id, status->photoid);
        }

        flickcurl_free_upload_status(status);
    }

    cp->ci.dirty = CLEAN;

    cps->set = CACHE_UNSET;

    retval = SUCCESS;

fail: pthread_rwlock_unlock(&cache_lock);
    return retval;
}
Exemple #2
0
int set_photo_photoset(const char *photoset, const char *photo, const char *new_photoset) {
    cached_photoset *cps;
    cached_photoset *new_cps;
    cached_photo *cp;
    int retval = FAIL;

    pthread_rwlock_wrlock(&cache_lock);

    cps = g_hash_table_lookup(photoset_ht, photoset);
    new_cps = g_hash_table_lookup(photoset_ht, new_photoset);

    if(!cps || !new_cps)
        goto fail;

    if(!(cp = g_hash_table_lookup(cps->photo_ht, photo)))
        goto fail;

    if(strcmp(cps->ci.id, "")) {
        flickcurl_photosets_removePhoto(fc, cps->ci.id, cp->ci.id);
    }

    if(strcmp(new_cps->ci.id, "")) {
        flickcurl_photosets_addPhoto(fc, new_cps->ci.id, cp->ci.id);
    }

    g_hash_table_foreach_remove(cps->photo_ht, free_photo_ht, NULL);
    g_hash_table_foreach_remove(new_cps->photo_ht, free_photo_ht, NULL);

    cps->set = CACHE_UNSET;
    new_cps->set = CACHE_UNSET;

    retval = SUCCESS;

fail: pthread_rwlock_unlock(&cache_lock);
    return retval;
}
Exemple #3
0
int
store (dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, const int imgid, dt_imageio_module_format_t *format, dt_imageio_module_data_t *fdata,
       const int num, const int total, const gboolean high_quality)
{
  gint result=1;
  dt_storage_flickr_params_t *p=(dt_storage_flickr_params_t *)sdata;
  flickcurl_upload_status *photo_status;
  gint tags=0;

  const char *ext = format->extension(fdata);

  // Let's upload image...

  /* construct a temporary file name */
  char fname[4096]= {0};
  dt_loc_get_tmp_dir (fname,4096);
  g_strlcat (fname,"/darktable.XXXXXX.",4096);
  g_strlcat(fname,ext,4096);

  char *caption = NULL;
  char *description = NULL;


  gint fd=g_mkstemp(fname);
  fprintf(stderr,"tempfile: %s\n",fname);
  if(fd==-1)
  {
    dt_control_log("failed to create temporary image for flickr export");
    return 1;
  }
  close(fd);
  const dt_image_t *img = dt_image_cache_read_get(darktable.image_cache, imgid);

  // If title is not existing, then use the filename without extension. If not, then use title instead
  GList *title = dt_metadata_get(img->id, "Xmp.dc.title", NULL);
  if(title != NULL)
  {
    caption = g_strdup(title->data);
    g_list_free_full(title, &g_free);
  }
  else
  {
    caption = g_path_get_basename(img->filename);
    (g_strrstr(caption,"."))[0]='\0'; // chop extension...
  }

  GList *desc = dt_metadata_get(img->id, "Xmp.dc.description", NULL);
  if(desc != NULL)
  {
    description = desc->data;
  }
  dt_image_cache_read_release(darktable.image_cache, img);

  if(dt_imageio_export(imgid, fname, format, fdata, high_quality) != 0)
  {
    fprintf(stderr, "[imageio_storage_flickr] could not export to file: `%s'!\n", fname);
    dt_control_log(_("could not export to file `%s'!"), fname);
    result = 0;
    goto cleanup;
  }

#ifdef _OPENMP
  #pragma omp critical
#endif
  {
    //TODO: Check if this could be done in threads, so we enhance export time by using
    //      upload time for one image to export another image to disk.
    // Upload image
    // Do we export tags?
    if( p->export_tags == TRUE )
      tags = imgid;
    photo_status = _flickr_api_upload_photo( p, fname, caption, description, tags );
  }

  if( !photo_status )
  {
    result=0;
    goto cleanup;
  }

//  int fail = 0;
  // A photoset is only created if we have an album title set
  if( p->flickr_api->current_album == NULL && p->flickr_api->new_album == TRUE)
  {
    char *photoset_id;
    photoset_id = _flickr_api_create_photoset(p->flickr_api, photo_status->photoid);

    if( photoset_id == NULL)
    {
      dt_control_log("failed to create flickr album");
//      fail = 1;
    }
    else
    {
//      p->flickr_api->new_album = FALSE;
      p->flickr_api->current_album = flickcurl_photosets_getInfo(p->flickr_api->fc,photoset_id);
    }
  }

//  if(fail) return 1;
// TODO: What to do if photoset creation fails?

  // Add to gallery, if needed
  if (p->flickr_api->current_album != NULL && p->flickr_api->new_album != TRUE)
  {
    flickcurl_photosets_addPhoto (p->flickr_api->fc, p->flickr_api->current_album->id, photo_status->photoid);
    // TODO: Check for errors adding photo to gallery
  }
  else
  {
    if (p->flickr_api->current_album != NULL && p->flickr_api->new_album == TRUE)
    {
      p->flickr_api->new_album = FALSE;
    }
  }

cleanup:

  // And remove from filesystem..
  unlink( fname );
  g_free( caption );
  if(desc)
    g_list_free_full(desc, &g_free);

  if (result)
  {
    //this makes sense only if the export was successful
    dt_control_log(_("%d/%d exported to flickr webalbum"), num, total );
  }
  return result;
}