Lunar_Lamp
August 1st, 2006, 03:01 PM
Hi I'm tryihg to write a bash script that will help me when i have downloaded flv files from youtube etc. The idea is to have a script that will do three things (initially, and be expanded to be more complex later perhaps):
- Convert a file from flv to mpg
- Delete the flv file (if requested)
- Allow user to rename the mpg file to whatever they want (I know this could be done using a $2 variable, but I would prefer not to).
I'd appreciate it if people would look over it and let me know how to make this into a working script, as I am very new to bash and have just thrown together some thoughts based upon what I already know.
#!/bin/bash
#
# script written to convert flvs from places like youtube and googlevideos to mpg files.
#
# note to self: $1 = 'flv filename'
#
# todo:
# - sort the rename function out
# - combine the functions
# - make te script able to deal with multiple files
# - enable input variable to be the url, and make the script find the correct url to download and then convert
####################
# Convert Function #
####################
#this coverts the flv file specified ($1) to mpg
function convert {
ffmpeg -i $1 -ab 56 -ar 22050 -b 500 -s 320x240 $name
}
# -ab = averate bitrate of music (default=64)
# -ar = averate sampling rate
# -b =
# -s = resize
###################
# Rename Function #
###################
#this function asks what you want to call the new file created, and acts accordingly.
function rename {
echo "By default the file will be named $1.mpg - do you want to change this?"
if [ "$rename_answer" = "y" ];
then echo "What do you want to call it?"
read name
echo "Converting flv file to $name"
elif [ "$rename_answer" = "n" ];
name=$1.mpg
echo "Converting file to $1.mpg"
fi
}
#####################
# Deletion Function #
#####################
#this function asks if you want to delete the original file and acts accordingly.
function flvdelete {
echo "Do you want to delete original flv file? (Y/N)"
read reply
if [ "$reply" = "y" ];
then rm $1
echo "File deleted: $1"
elif [ "$reply" = "n" ];
then echo "Leaving file intact: $1"
fi
}
###############
# Main Script #
###############
$rename ;
$convert ;
$flvdelete
exit
- Convert a file from flv to mpg
- Delete the flv file (if requested)
- Allow user to rename the mpg file to whatever they want (I know this could be done using a $2 variable, but I would prefer not to).
I'd appreciate it if people would look over it and let me know how to make this into a working script, as I am very new to bash and have just thrown together some thoughts based upon what I already know.
#!/bin/bash
#
# script written to convert flvs from places like youtube and googlevideos to mpg files.
#
# note to self: $1 = 'flv filename'
#
# todo:
# - sort the rename function out
# - combine the functions
# - make te script able to deal with multiple files
# - enable input variable to be the url, and make the script find the correct url to download and then convert
####################
# Convert Function #
####################
#this coverts the flv file specified ($1) to mpg
function convert {
ffmpeg -i $1 -ab 56 -ar 22050 -b 500 -s 320x240 $name
}
# -ab = averate bitrate of music (default=64)
# -ar = averate sampling rate
# -b =
# -s = resize
###################
# Rename Function #
###################
#this function asks what you want to call the new file created, and acts accordingly.
function rename {
echo "By default the file will be named $1.mpg - do you want to change this?"
if [ "$rename_answer" = "y" ];
then echo "What do you want to call it?"
read name
echo "Converting flv file to $name"
elif [ "$rename_answer" = "n" ];
name=$1.mpg
echo "Converting file to $1.mpg"
fi
}
#####################
# Deletion Function #
#####################
#this function asks if you want to delete the original file and acts accordingly.
function flvdelete {
echo "Do you want to delete original flv file? (Y/N)"
read reply
if [ "$reply" = "y" ];
then rm $1
echo "File deleted: $1"
elif [ "$reply" = "n" ];
then echo "Leaving file intact: $1"
fi
}
###############
# Main Script #
###############
$rename ;
$convert ;
$flvdelete
exit