grab_single_playlist.sh 891 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. INSTANCE=""
  3. OUTFILE=playlist.json
  4. PLID=1
  5. TOKEN=""
  6. while getopts "i:o:p:t:" arg; do
  7. case $arg in
  8. i)
  9. INSTANCE=${OPTARG}
  10. ;;
  11. p)
  12. PLID=${OPTARG}
  13. ;;
  14. o)
  15. OUTFILE=${OPTARG}
  16. ;;
  17. t)
  18. TOKEN=${OPTARG}
  19. ;;
  20. esac
  21. done
  22. shift $((OPTIND-1))
  23. if [ -z "${INSTANCE}" ]; then
  24. echo No instance given
  25. exit 1
  26. fi
  27. if [ -z "${TOKEN}" ]; then
  28. echo No token given
  29. exit 1
  30. fi
  31. plurl="https://${INSTANCE}/api/v1/playlists/${PLID}"
  32. answer="$(curl -s -X 'GET' -H 'Authorization: Bearer '${TOKEN} -H 'accept: application/json' ${plurl})"
  33. if [ "$(echo ${answer}|jq -r '.id')" != "${PLID}" ]; then
  34. echo Could not grab the right Playlist ${PLID} from instance ${INSTANCE}
  35. exit 1
  36. fi
  37. echo ${answer} > ${PLID}.pl.json
  38. tracks="$(curl -s -X 'GET' -H 'Authorization: Bearer '${TOKEN} -H 'accept: application/json' ${plurl}/tracks/)"
  39. echo ${tracks} > ${PLID}.tracks.json