1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/usr/bin/env bash
- INSTANCE=""
- OUTFILE=playlist.json
- PLID=1
- TOKEN=""
- while getopts "i:o:p:t:" arg; do
- case $arg in
- i)
- INSTANCE=${OPTARG}
- ;;
- p)
- PLID=${OPTARG}
- ;;
- o)
- OUTFILE=${OPTARG}
- ;;
- t)
- TOKEN=${OPTARG}
- ;;
- esac
- done
- shift $((OPTIND-1))
- if [ -z "${INSTANCE}" ]; then
- echo No instance given
- exit 1
- fi
- if [ -z "${TOKEN}" ]; then
- echo No token given
- exit 1
- fi
- plurl="https://${INSTANCE}/api/v1/playlists/${PLID}"
- answer="$(curl -s -X 'GET' -H 'Authorization: Bearer '${TOKEN} -H 'accept: application/json' ${plurl})"
- if [ "$(echo ${answer}|jq -r '.id')" != "${PLID}" ]; then
- echo Could not grab the right Playlist ${PLID} from instance ${INSTANCE}
- exit 1
- fi
- echo ${answer} > ${PLID}.pl.json
- tracks="$(curl -s -X 'GET' -H 'Authorization: Bearer '${TOKEN} -H 'accept: application/json' ${plurl}/tracks/)"
- echo ${tracks} > ${PLID}.tracks.json
|