You are not logged in.
Pages: 1
Since Flash has got crappier with the last upgrade (it almost freezes my Firefox), I have written a script to avoid using it to watch videos on Youtube. Of course this involves youtube-dl
I only want to point out that if you see anything odd in my script, this is my first serious attempt to a script, and I don't know much about any programming language, including bash.
What my script does, is checking whether the file is already present in my /tmp folder, if it's there it plays it with MPlayer, if not, it downloads it and then plays it with MPlayer. I like to use the actual titles of the videos, so I can both recognise them, and have the title, which can always come handy.
So here we go:
#!/bin/bash
cd /tmp;
# Write the video title and URL to a file
youtube-dl -g2 $1 > videotitle
# trim out the URL, replace spaces with underscores and make all small caps
VAR="`sed -e '2d' videotitle -e 's/ /_/g' -e 's/[A-Z]/\L&/g' | more`"
# get the video filename
VIDEO="`ls | grep $VAR`"
# if there is a file with the video filename already on the hard disk, play it with gmplayer
if [ -n "$VIDEO" ]; then
gmplayer $VIDEO
else
# else download it
# write download output to a file
youtube-dl -t $1 > output
# strip out everything from the file, but the video filename
FILENAME="`cat output | grep renamed | grep flv | sed -e 's/Video file renamed to//' | more`"
gmplayer $FILENAME;
fi
Of course, if you have any idea for improving it or enhance its capabilities, make suggestions
Last edited by finferflu (2007-12-31 22:31:01)
Have you Syued today?
Free music for free people! | Earthlings
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery
Offline
that would be smarter
#!/bin/bash
cd /tmp;
# Write the video title and URL to a file
youtube-dl -g2 $1 > videotitle
# trim out the URL, replace spaces with underscores and make all small caps
VAR="`sed -e '2d' videotitle -e 's/ /_/g' -e 's/[A-Z]/\L&/g' | more`"
# get the video filename
VIDEO="`ls | grep $VAR`"
# if there is a file with the video filename already on the hard disk, play it with gmplayer
if [ -n "$VIDEO" ]; then
gmplayer $VIDEO
else
# else download it
# write download output to a file
youtube-dl -o $VIDEO $1
gmplayer $VIDEO;
fi
just a beginning to triger your thinking
Offline
Yeah! that's already much better
Edit
Too bad it doesn't work
Last edited by finferflu (2007-12-31 23:44:26)
Have you Syued today?
Free music for free people! | Earthlings
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery
Offline
Actually that gave me an inspiration for a rewrite, and a shorter code:
#!/bin/bash
# fetch video URL and title and copy output to file
youtube-dl -g2 $1 > videotitle
# delete the URL line and replace spaces with underscores
VAR="`sed -e '2d' videotitle -e 's/ /_/g'`"
# set the the video filename
FILENAME="$VAR.flv"
# check if there is any file with this video filename locally
VIDEO="`ls | grep $VAR`"
# if the video is present locally, play it with gmplayer
if [ -n "$VIDEO" ]; then
gmplayer $FILENAME
else
#else download it and play it
# download the video, set its file name to $FILENAME and play it with gmplayer
youtube-dl -o $FILENAME $1
gmplayer $FILENAME;
fi
How about this?
Last edited by finferflu (2008-01-01 00:42:16)
Have you Syued today?
Free music for free people! | Earthlings
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery
Offline
Oh yeah?
Actually my fault on the first modification, did not see finferflu had the variable assigned the ls output... (ehehe)
but finferflu, beat this :-p
#!/bin/bash
cd /tmp;
youtube-dl -g2 $1 > videotitle
VAR="`sed -e '2d' videotitle -e 's/ /_/g'`"
if [ ! -e "$VAR.flv" ]; then
youtube-dl -o $VAR.flv $1
fi
gmplayer $VAR.flv
No need to allocate the $VIDEO variable when you can do a simple test file in bash ;-) - and also no need to write twice gmplayer $VIDEO, you are going to play it anyway :-p
Last edited by debiannerd (2008-01-01 00:57:29)
Offline
Yeah, that's much better and also works well. I don't know enough about the if clause...
Thanks
Have you Syued today?
Free music for free people! | Earthlings
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery
Offline
too bad we can't get something like this to work with ALL flash-based video sites.
Offline
Pages: 1