A tool for adding anime to your anidb list.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

62 lignes
1.4KB

  1. #include <sys/stat.h>
  2. #include <stdio.h>
  3. #include <stdbool.h>
  4. #include "cmd.h"
  5. #include "error.h"
  6. #include "uio.h"
  7. #include "config.h"
  8. #include "ed2k_util.h"
  9. #include "ed2k.h"
  10. #include "util.h"
  11. struct cmd_ed2k_opts {
  12. bool link;
  13. };
  14. static enum error cmd_ed2k_output(const char *path, const uint8_t *hash,
  15. const struct stat *st, void *data)
  16. {
  17. struct cmd_ed2k_opts *eo = data;
  18. char buff[ED2K_HASH_SIZE * 2 + 1];
  19. bool upcase = eo->link;
  20. util_byte2hex(hash, ED2K_HASH_SIZE, upcase, buff);
  21. if (eo->link) {
  22. char *name_part = util_basename(path);
  23. printf("ed2k://|file|%s|%ld|%s|/\n", name_part, st->st_size, buff);
  24. } else {
  25. printf("%s\t%s\n", buff, path);
  26. }
  27. return NOERR;
  28. }
  29. enum error cmd_ed2k(void *data)
  30. {
  31. struct cmd_ed2k_opts opts = {0};
  32. struct ed2k_util_opts ed2k_opts = {
  33. .post_hash_fn = cmd_ed2k_output,
  34. .data = &opts,
  35. };
  36. bool *link;
  37. enum error err = NOERR;
  38. int fcount;
  39. fcount = config_get_nonopt_count();
  40. if (fcount == 0) {
  41. uio_error("No files specified");
  42. return ERR_CMD_ARG;
  43. }
  44. if (config_get_subopt("ed2k", "link", (void**)&link) == NOERR)
  45. opts.link = *link;
  46. for (int i = 0; i < fcount; i++) {
  47. ed2k_util_iterpath(config_get_nonopt(i), &ed2k_opts);
  48. /* Above may fail if the path doesn't exists or smth, but still continue */
  49. }
  50. return err;
  51. }