flickrer 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. key=$(getnetrc flickr login)
  3. secret=$(getnetrc flickr)
  4. getfrob() {
  5. local sig=$(printf %b ${secret}api_key${key}methodflickr.auth.getFrob | md5sum | awk '{print $1}')
  6. local out=$(curl -s "https://api.flickr.com/services/rest/?method=flickr.auth.getFrob&api_key=${key}&api_sig=${sig}")
  7. frob=$(echo "$out" | grep frob | sed -e 's/<frob>\(.*\)<\/frob>/\1/')
  8. auth
  9. }
  10. auth() {
  11. local sig=$(printf %b ${secret}api_key${key}frob${frob}permswrite | md5sum | awk '{print $1}')
  12. xdg-open "https://flickr.com/services/auth/?api_key=${key}&perms=write&frob=${frob}&api_sig=${sig}"
  13. echo "Authorize the webapp (should be open in your default browser) then hit enter"
  14. read line
  15. get_token
  16. }
  17. get_token() {
  18. local sig=$(printf %b ${secret}api_key${key}frob${frob}methodflickr.auth.getToken | md5sum | awk '{print $1}')
  19. local out=$(curl -s "https://api.flickr.com/services/rest/?method=flickr.auth.getToken&api_key=${key}&frob=${frob}&api_sig=${sig}")
  20. token=$(echo "$out" | grep token | sed -e 's/<token>\(.*\)<\/token>/\1/' -e 's/^[ \t]*//')
  21. upload
  22. }
  23. upload() {
  24. local sig=$(printf '%b' "${secret}api_key${key}auth_token${token}is_public1title${title}" | md5sum | awk '{print $1}')
  25. curl -s \
  26. -F api_key="${key}" \
  27. -F auth_token="${token}" \
  28. -F is_public=1 \
  29. -F title="${title}" \
  30. -F api_sig="${sig}" \
  31. -F photo=@"${file}" \
  32. https://api.flickr.com/services/upload/
  33. }
  34. main() {
  35. if (( $# < 2 )); then
  36. echo "USAGE: $(basename "$0") </path/to/file> <title>"
  37. exit 1
  38. fi
  39. file="$1"
  40. title="$2"
  41. getfrob
  42. }
  43. main "$@"