audiokeychain-clients/audiokeychain.sh

38 lines
2.3 KiB
Bash
Raw Permalink Normal View History

2016-06-15 15:50:18 +02:00
#!/bin/bash
2016-06-19 00:09:48 +02:00
# Audiokeychain.com client
# Licensed under GPLV3
# Created by Daniil Gentili (https://daniil.it)
2016-06-19 00:53:17 +02:00
cd "$( dirname "${BASH_SOURCE[0]}" )"
2016-06-15 15:50:18 +02:00
if [ "$1" = "" ]; then
echo "Usage: $0 music.mp3"
exit
fi
sha256=$(sha256sum "$1" | sed 's/\s.*//g')
cookies="/tmp/audiokeychain"$sha256".txt"
2016-06-19 00:09:48 +02:00
bucket=$(curl -s 'https://www.audiokeychain.com/bucket' -H 'Host: www.audiokeychain.com' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -c $cookies)
2016-06-15 15:50:18 +02:00
if [ "$bucket" = "" ]; then
echo "Couldn't obtain bucket code"
exit 1
fi
2016-06-19 00:09:48 +02:00
uploadresult=$(curl -s 'https://www.audiokeychain.com/upload' -H 'Host: www.audiokeychain.com' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'Content-Type: multipart/form-data;' -H 'Connection: keep-alive' -F "XUploadForm[file]=@$1" -F "zwa=$bucket" -b $cookies | ./JSON.sh -s)
2016-06-15 15:50:18 +02:00
if ! echo "$uploadresult" | grep -q 'name'; then
echo "Couldn't upload file."
exit 1
fi
2016-06-19 00:09:48 +02:00
while [ "$(curl -s "https://www.audiokeychain.com/progress/$bucket" -H 'Host: www.audiokeychain.com' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -b $cookies)" != "0" ];do
result=$(printf "$(curl -s "https://www.audiokeychain.com/queue/$bucket" -H 'Host: www.audiokeychain.com' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data 'errors=%5B%5D' -b $cookies | ./JSON.sh -s | sed '/^\["tracks",0\]\t/!d;s/^\["tracks",0\]\t//g;s/^"//g;s/"$//g;s/[<]\/tr[>].*//g;s/[<]td/\
<td/g')" | sed 's/^\s*//g;s/\s*$//g;/^[<]td/!d;s/^[<]td class="//g;s/"[>]/: /;s/[<]\/td[>]$//')
sleep 2
done
2016-06-15 15:50:18 +02:00
2016-06-19 00:09:48 +02:00
echo "$result"
2016-06-15 15:50:18 +02:00
rm $cookies