There's a chance that this is beyond the range of this forum, and if it is I apologize. However I think there is a chance that someone more familiar with shell scripting than me may have an idea.
When browsing the web on my Mac, I often find links to pages with audio files that I want to quickly add to Overcast, my podcast player of choice. My main method so far has been to download them and upload them to Overcast with another macro.
Recently, a feature was introduced for Overcast Premium members. By logging into the Overcast website, you can submit an URL that points to an audio file. The audio will be immediately added to Overcast. I tried for a long time to script this.
In a perfect world, I could be on the audio file’s web page and use a Keyboard Maestro macro to:
- Get the current URL in Chrome.
- Call a script with the URL as input which…
- Sends the URL directly to Overcast, which downloads the audio.
Here is a script (slightly modified from this) that takes audio files as input and uploads them to any Overcast account.
#!/usr/bin/env bash
if [[ -z "$1" ]]
then
echo "Please enter a file to upload."
exit 1
fi
if [[ ! -f $1 ]]
then
echo "File $1 not found."
exit 1
fi
overcast_email=email@example.com
overcast_password=password123
if [[ -z "$overcast_email" ]] \
|| [[ -z "$overcast_password" ]]
then
echo "Please set your credentials in ~/.overcast_auth like this:"
echo ""
echo 'export overcast_email="yourEmail@example.com"'
echo 'export overcast_password="yourPassword"'
echo ""
exit 1
fi
echo "Logging in as $overcast_email"
curl -Ls --compressed \
-d "then=uploads" \
-d "email=$overcast_email" \
-d "password=$overcast_password" \
-c overcast_cookies \
-o upload.tmp \
https://overcast.fm/login \
|| exit 1
policy=$(grep -o -E \
'<input type="hidden" id="upload_policy" name="policy" value="[^\\"]+' \
upload.tmp \
| sed \
's/<input type="hidden" id="upload_policy" name="policy" value="//g' \
)
signature=$(grep -o -E \
'<input type="hidden" id="upload_signature" name="signature" value="[^\\"]+' \
upload.tmp \
| sed \
's/<input type="hidden" id="upload_signature" name="signature" value="//g' \
)
AWSAccessKeyId=$(grep -o -E \
'<input type="hidden" name="AWSAccessKeyId" value="[^\\"]+' \
upload.tmp \
| sed \
's/<input type="hidden" name="AWSAccessKeyId" value="//g' \
)
key=$(grep -o -E \
'data-key-prefix="[^\\"]+' \
upload.tmp \
| sed \
's/data-key-prefix="//g' \
)
filename=$(basename $1)
if [[ -z "$policy" ]] \
|| [[ -z "$signature" ]] \
|| [[ -z "$AWSAccessKeyId" ]] \
|| [[ -z "$key" ]] \
|| [[ -z "$filename" ]]
then
echo "There was a problem fetching the upload page."
echo "Make sure your email and password are correct."
exit 1
fi
rm upload.tmp
echo Uploading $filename
curl -Ls --compressed \
-F "bucket=uploads-overcast" \
-F "key=$key$filename" \
-F "AWSAccessKeyId=$AWSAccessKeyId" \
-F "acl=authenticated-read" \
-F "policy=$policy" \
-F "signature=$signature" \
-F "Content-Type=application/x-www-form-urlencoded" \
-F "file=@$1" \
-b overcast_cookies \
https://uploads-overcast.s3.amazonaws.com/ \
|| exit 1
curl -Ls --compressed \
-F "key=$key$filename" \
-b overcast_cookies \
https://overcast.fm/podcasts/upload_succeeded \
> /dev/null \
|| exit 1
rm overcast_cookies
echo Done!
I have tried many different ideas to modify this script to accept URLs instead of audio files. I have tried changing the content type of the request to "application/x-www-form-urlencoded" and encoding the URL but this has not worked.
I know I'm on the right track because I will successfully upload blank audio tracks to Overcast, with the same title as the URL I tried to upload. Of course, this is very different than actually uploading the audio of that same URL.
This has to be possible somehow.