Last active
August 29, 2015 14:10
-
-
Save Habmala/5a0c04dd15df78fc466b to your computer and use it in GitHub Desktop.
scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
#v0.5 adds support for youtube-dl | |
###### | |
# Script to prompt for a URI to download, play and remove a podcastfile or online video. | |
# Depends on wget, awk and mplayer and youtube-dl | |
# | |
#NO ERROR HANDELING IMPLEMENTED | |
# | |
# Written by Sebastian Hellvin (habmala.se) | |
###### | |
### | |
# Setting up some help messages, slight debug and user input | |
### | |
if [ "$1" = "-h" ]; then | |
echo "################################################################" | |
echo -e "This script will download a file from the internet and play it before removing the file again.\n\n It will first prompt for a url that must point to the file you want to hear or see.\n It is assumed that the url is divided with slashes (/) and that after the last slash is the filename.\n\n The script is written in bash and needs \"wget\", \"mplayer\" and \"awk\" to function.\n\n version 0.5 also supports the options -y for using youtube-dl, otherwise wget will be used as normal. awk and mplayer are still needed eighter way." | |
echo "################################################################" | |
exit 0 | |
elif [ -n "$2" ]; then | |
echo "Only one command accepted. -h for help or -y for youtube-dl or -w for wget (default)" | |
exit 0 | |
elif [ "$1" = "-d" ]; then | |
echo "debug" #not implemented | |
fi | |
echo -e "Welcome to the podcast/internet video player script.\nBy entering a URL for a file or video site (depending on usage) it's downloaded,\nplayed locally and then removed.\n\nScript written by Sebastian Hellvin, -h for help and details." | |
### | |
# Setting up the variables | |
### | |
read -p "Enter your URL: " URL #Reads the users url | |
fileName="$(echo $URL | awk -F/ '{print $NF}')" #whatever is after the last / of the url will be the filename for the temporary file | |
#Change this if statement to swap the defaults | |
if [ "$1" = "-y" ]; then | |
downloader="youtube-dl -o $fileName" | |
else | |
downloader="wget" | |
fi | |
echo $URL #for testing | |
echo $fileName #for testing | |
### | |
# Acctual execusion | |
### | |
$downloader $URL #downloads the file | |
mplayer $fileName #plays with mplayer | |
rm $fileName #removes the file | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment