You are not logged in.

#1 2007-12-31 22:27:37

finferflu
Forum Fellow
From: Manchester, UK
Registered: 2007-06-21
Posts: 1,899
Website

Youtube videos workaround

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 tongue

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 big_smile

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

#2 2007-12-31 22:54:47

sarah32
Member
Registered: 2007-12-31
Posts: 16

Re: Youtube videos workaround

that would be smarter wink

#!/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 cool

Offline

#3 2007-12-31 23:01:58

finferflu
Forum Fellow
From: Manchester, UK
Registered: 2007-06-21
Posts: 1,899
Website

Re: Youtube videos workaround

Yeah! that's already much better big_smile

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

#4 2008-01-01 00:30:35

finferflu
Forum Fellow
From: Manchester, UK
Registered: 2007-06-21
Posts: 1,899
Website

Re: Youtube videos workaround

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? big_smile

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

#5 2008-01-01 00:42:02

sarah32
Member
Registered: 2007-12-31
Posts: 16

Re: Youtube videos workaround

Oh yeah? cool

Actually my fault on the first modification, did not see finferflu had the variable assigned the ls output... (ehehe) tongue

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

#6 2008-01-01 00:57:50

finferflu
Forum Fellow
From: Manchester, UK
Registered: 2007-06-21
Posts: 1,899
Website

Re: Youtube videos workaround

Yeah, that's much better and also works well. I don't know enough about the if clause...
Thanks smile


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

#7 2008-01-01 02:15:52

iBertus
Member
From: Greenville, NC
Registered: 2004-11-04
Posts: 2,228

Re: Youtube videos workaround

too bad we can't get something like this to work with ALL flash-based video sites.

Offline

Board footer

Powered by FluxBB