Skip to content

Instantly share code, notes, and snippets.

@ngregoire
Created April 6, 2020 17:59
Show Gist options
  • Save ngregoire/43891d80fde3c6cbb1a52a5a6468fe41 to your computer and use it in GitHub Desktop.
Save ngregoire/43891d80fde3c6cbb1a52a5a6468fe41 to your computer and use it in GitHub Desktop.
Shell script downloading videos embedded in tweets
#!/bin/bash
# Usage: $0 TWEET_URL <DEST_FILE>
# If the second parameter is omitted, the video is saved to a timestamped file
DLWD_URL=https://www.savetweetvid.com/fr/downloader
TWEET_URL=$1
DEST_FILE=$2
if [ "$TWEET_URL" = "--help" ] || [ "$TWEET_URL" = "-h" ]
then
echo "- Usage: $0 TWEET_URL <DEST_FILE>"
echo "- If the second parameter is omitted, the video is saved to a timestamped file"
exit 0
fi
# First argument
if [ -z "$TWEET_URL" ]
then
echo "- Missing 'URL' parameter! Use option '-h' or '--help'..."
exit 1
fi
# Second argument
if [ -z "$DEST_FILE" ]
then
OUTPUT_FILE=`date +%F-%s`.mp4
else
OUTPUT_FILE=$DEST_FILE
fi
# Get video URL
echo "+ Fetching video URL..."
VIDEO_URL=`curl -s -d "url=${TWEET_URL}" ${DLWD_URL} | grep 'text:' | cut -d\" -f2`
# Download video
if [ -z "$VIDEO_URL" ]
then
echo "- Cannot find video URL :-/"
exit 2
else
echo "+ Source: ${VIDEO_URL}"
echo "+ Destination: ${OUTPUT_FILE}"
echo "+ Downloading..."
wget -q -O ${OUTPUT_FILE} ${VIDEO_URL}
touch ${OUTPUT_FILE}
echo "+ Done"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment