示例#1
0
int main(int argc, char *argv[]) {
  flickcurl *fc;
  flickcurl_photo *photo;
  flickcurl_photo_field_type field_type;
  int i;

  flickcurl_init(); /* optional static initialising of resources */
  fc = flickcurl_new();

#if defined(WIN32) && defined(_MSC_VER)
  flickcurl_config_read_ini(fc, ".flickcurl.conf", "flickr", fc, flickcurl_config_var_handler);
#else
  /* Set configuration explicitly: ... */
  flickcurl_set_oauth_client_key(fc, "...");
  flickcurl_set_oauth_client_secret(fc, "...");
  flickcurl_set_oauth_token(fc, "...");
  flickcurl_set_oauth_token_secret(fc, "...");

  /* or could read from an INI config file like this: */
  /*
  flickcurl_config_read_ini(fc, "/home/user/.flickcurl.conf", "flickr",
                            fc, flickcurl_config_var_handler);
  */  
#endif
  /* Pick your own photo ID */
  #define PHOTO_ID "123456789"

  photo = flickcurl_photos_getInfo(fc, PHOTO_ID); 
  if(!photo) {
    fprintf(stderr, "flickcurl_photos_getInfo(%s) failed\n", PHOTO_ID);
  } else {
    for(field_type = 0; field_type <= PHOTO_FIELD_LAST; field_type++) {
      flickcurl_field_value_type datatype = photo->fields[field_type].type;

      if(datatype != VALUE_TYPE_NONE)
        fprintf(stderr, "field %s (%d) with %s value: '%s' / %d\n", 
                flickcurl_get_photo_field_label(field_type), (int)field_type,
                flickcurl_get_field_value_type_label(datatype),
                photo->fields[field_type].string,
                photo->fields[field_type].integer);
    }

    for(i = 0; i < photo->tags_count; i++) {
      flickcurl_tag* tag=photo->tags[i];
      fprintf(stderr,
              "%d) %s tag: id %s author ID %s name %s raw '%s' cooked '%s' count %d\n",
              i, (tag->machine_tag ? "machine" : "regular"),
              tag->id, tag->author, 
              (tag->authorname ? tag->authorname : "(Unknown)"), 
              tag->raw, tag->cooked,
              tag->count);
    }

    flickcurl_free_photo(photo);
  }
  
  flickcurl_free(fc);
  flickcurl_finish(); /* optional static free of resources */

  return 0;
}
示例#2
0
int
main(int argc, char *argv[]) 
{
  flickcurl *fc = NULL;
  int rc = 0;
  int usage = 0;
  int help = 0;
  const char* home;
  char config_path[1024];
  char* photo_id = NULL;
  const char* prefix_uri = "http://www.flickr.com/photos/";
  size_t prefix_uri_len = strlen(prefix_uri);
  const char *serializer_syntax_name = "ntriples";
  raptor_uri* base_uri = NULL;
  raptor_serializer* serializer = NULL;
  int request_delay= -1;
  flickcurl_serializer* fs = NULL;
  flickcurl_photo* photo = NULL;

  program = my_basename(argv[0]);

  flickcurl_init();

  rworld = raptor_new_world();
  raptor_world_open(rworld);

  home = getenv("HOME");
  if(home)
    sprintf(config_path, "%s/%s", home, config_filename);
  else
    strcpy(config_path, config_filename);
  

  while (!usage && !help)
  {
    int c;
    
#ifdef HAVE_GETOPT_LONG
    int option_index = 0;

    c = getopt_long (argc, argv, GETOPT_STRING, long_options, &option_index);
#else
    c = getopt (argc, argv, GETOPT_STRING);
#endif
    if (c == -1)
      break;

    switch (c) {
      case 0:
      case '?': /* getopt() - unknown option */
        usage = 1;
        break;

      case 'd':
        if(optarg)
          request_delay = atoi(optarg);
        break;
        
      case 'D':
        debug = 1;
        break;
        
      case 'h':
        help = 1;
        break;

      case 'o':
        if(optarg) {
          if(raptor_world_is_serializer_name(rworld, optarg))
            serializer_syntax_name = optarg;
          else {
            int i;
            
            fprintf(stderr,
                    "%s: invalid argument `%s' for `" HELP_ARG(o, output) "'\n",
                    program, optarg);
            fprintf(stderr, "Valid arguments are:\n");
            for(i = 0; 1; i++) {
              const raptor_syntax_description *d;

              d = raptor_world_get_serializer_description(rworld, i);
              if(!d)
                break;
              printf("  %-12s for %s\n", d->names[0], d->label);
            }
            usage = 1;
            break;
            
          }
        }
        break;
        
      case 'v':
        fputs(flickcurl_version_string, stdout);
        fputc('\n', stdout);

        exit(0);
    }
    
  }

  argv+= optind;
  argc-= optind;
  
  if(!help && argc < 1)
    usage = 2; /* Title and usage */

  if(!help && !argc) {
    fprintf(stderr, "%s: No photo URI given\n", program);
    usage = 1;
    goto usage;
  }

  if(usage || help)
    goto usage;

  photo_id = argv[0];
  if(strncmp(photo_id, prefix_uri, prefix_uri_len))
    usage = 1;
  else {
    size_t len;

    photo_id+= prefix_uri_len;
    len = strlen(photo_id);
    if(!len)
      usage = 1;
    else {
      if(photo_id[len-1] == '/')
        photo_id[--len] = '\0';
      
      while(*photo_id && *photo_id != '/')
        photo_id++;
      if(!*photo_id)
        usage = 1;
      else
        photo_id++;
    }
  }

  if(usage) {
    fprintf(stderr,
            "%s: Argument is not a Flickr photo URI like\n"
            "  http://www.flickr.com/photos/USER/PHOTO/\n", 
            program);
    goto usage;
  }


  serializer = raptor_new_serializer(rworld, serializer_syntax_name);
  if(!serializer) {
    fprintf(stderr, 
            "%s: Failed to create raptor serializer type %s\n", program,
            serializer_syntax_name);
    return(1);
  }

  base_uri = raptor_new_uri(rworld, (const unsigned char*)argv[0]);

  raptor_serializer_start_to_file_handle(serializer, base_uri, stdout);


  /* Initialise the Flickcurl library */
  fc = flickcurl_new();
  if(!fc) {
    rc = 1;
    goto tidy;
  }

  flickcurl_set_error_handler(fc, my_message_handler, NULL);

  if(!access((const char*)config_path, R_OK)) {
    if(flickcurl_config_read_ini(fc, config_path, config_section, fc,
                                 flickcurl_config_var_handler)) {
      rc = 1;
      goto tidy;
    }
  }
  
 usage:
  if(usage) {
    if(usage>1) {
      fprintf(stderr, title_format_string, flickcurl_version_string);
      fputs("Flickcurl home page: ", stderr);
      fputs(flickcurl_home_url_string, stderr);
      fputc('\n', stderr);
      fputs(flickcurl_copyright_string, stderr);
      fputs("\nLicense: ", stderr);
      fputs(flickcurl_license_string, stderr);
      fputs("\n\n", stderr);
    }
    fprintf(stderr, "Try `%s " HELP_ARG(h, help) "' for more information.\n",
            program);
    rc = 1;
    goto tidy;
  }

  if(help) {
    int i;

    printf(title_format_string, flickcurl_version_string);
    puts("Get Triples from Flickr photos.");
    printf("Usage: %s [OPTIONS] FLICKR-PHOTO-URI\n\n", program);

    fputs(flickcurl_copyright_string, stdout);
    fputs("\nLicense: ", stdout);
    puts(flickcurl_license_string);
    fputs("Flickcurl home page: ", stdout);
    puts(flickcurl_home_url_string);

    fputs("\n", stdout);

    puts(HELP_TEXT("d", "delay DELAY     ", "Set delay between requests in milliseconds"));
    puts(HELP_TEXT("D", "debug           ", "Print lots of output"));
    puts(HELP_TEXT("h", "help            ", "Print this help, then exit"));
    puts(HELP_TEXT("o", "output FORMAT   ", "Set output format to one of:"));
    for(i = 0; 1; i++) {
      const raptor_syntax_description* d;

      d = raptor_world_get_serializer_description(rworld, i);
      if(!d)
        break;

      if(!strcmp(d->names[0], serializer_syntax_name))
        printf("      %-15s %s (default)\n", d->names[0], d->label);
      else
        printf("      %-15s %s\n", d->names[0], d->label);
    }
#ifdef HAVE_RAPTOR
    printf("    via Raptor %s serializers\n", raptor_version_string);
#else
    puts("    via internal RDF serializer");
#endif
    puts(HELP_TEXT("v", "version         ", "Print the flickcurl version"));

    rc = 0;
    goto tidy;
  }


  if(request_delay >= 0)
    flickcurl_set_request_delay(fc, request_delay);
  
  fs = flickcurl_new_serializer(fc, serializer, &flickrdf_serializer_factory);
  if(!fs) {
    fprintf(stderr, "%s: Failed to create Flickcurl serializer\n", program);
    goto tidy;
  }
  
  photo = flickcurl_photos_getInfo(fc, photo_id);

  if(!photo)
    goto tidy;

  if(debug)
    fprintf(stderr, "%s: Photo with URI %s ID %s has %d tags\n",
            program, photo->uri, photo->id, photo->tags_count);

  rc = flickcurl_serialize_photo(fs, photo);

 tidy:
  if(photo)
    flickcurl_free_photo(photo);

  if(fs)
    flickcurl_free_serializer(fs);

  if(fc)
    flickcurl_free(fc);

  if(serializer)
    raptor_free_serializer(serializer);
  if(base_uri)
    raptor_free_uri(base_uri);

  if(rworld)
    raptor_free_world(rworld);

  flickcurl_finish();

  return(rc);
}
示例#3
0
	void ThreadFunc(void* args){
		//checking if we have right args
		if(!args)
			return;
		
		//getting thread info
		ThreadInfo* t = (ThreadInfo*)args;

		uint CurImage = 0;
		t->CurImage = 0;

		//main loop
		do{
			//checking if thread is paused
			WaitForSingleObject(t->Running, INFINITE);

			//checking if thread is not terminated
			if(!t->Terminate){
				//checking if we need list and downloading it
				if(!t->ResultList){
					t->ResultList = flickcurl_photos_search_params(t->Flickcurl, 
						&t->SearchParams, &t->ListParams);

					if(t->ResultList)
						t->TotalImages = t->ResultList->total_count;
					
					CurImage = 0;
					t->ListParams.page++; //updating page
				}

				//checking if anything were found
				if(t->ResultList){
					t->CurImage++;

					//creating new image
					Image* img = new(Image);
					InitImage(img);

					//downloading photo meta if needed
					if(t->WantMeta)
						img->Meta = flickcurl_photos_getInfo(t->Flickcurl, t->ResultList->photos[CurImage]->id);
				
					//downloading photo exif if needed
					if(t->WantEXIF)
						img->EXIF = flickcurl_photos_getExif(t->Flickcurl, t->ResultList->photos[CurImage]->id,
									t->ResultList->photos[CurImage]->fields[PHOTO_FIELD_secret].string);
				
					//downloading photo itself if needed
					if(t->WantImage)
						img->Img = DownloadImage(t, t->ResultList->photos[CurImage]);

					//checking if we've got any data
					if(img->EXIF || img->Img != "" || img->Meta)
						AddCache(t, img); //adding to cache
					else
						FreeImage(img); //or killing intance

					//updating image number
					if(CurImage < t->ResultList->photos_count - 1)
						CurImage++;
					else{
						CurImage = 0;
						flickcurl_free_photos_list(t->ResultList);
						t->ResultList = 0;
					}
				}else
					if(!t->Terminate)
						ResetEvent(t->Running); //pause thread if nothing were found
			}
		}while(!t->Terminate);
	};