Mittwoch, 12. Dezember 2012

[Bash] Play Flash-video with your player

I just improved my code from yesterday (http://urfoex.blogspot.de/2012/12/bash-play-flash-video-with-mplayer.html).

The player of choice is now nvlc which is a ncurses version of VLC. I took it because it still is command line but also has some console user interface with playlist and such things.
Why?

Because now the scripts not just plays "deleted" videos but also videos that are still lying around in cache. This is kind of the old style of how to access flash-movie e.g. for saving it.
The search-path for that is
"~/.mozilla/firefox/*.*/Cache" for firefox and
"~/.cache/chromium/*/*" for chromium.

For the playlist that is created a temporary file in "/tmp/browserFlashFiles.cache.log" is used and after finishing it will be deleted.
The minimum filesize of the videos is set to 1M.

Oh. There is also vim involved. It is used to delete some characters from the playlist. I guess there is an easy way without it. But hey! It works ;-)


YouTube uses some other way to save there videos. Therefor this script won't play those files.
Youtube-dl ( http://rg3.github.com/youtube-dl/ ) is a good place to start. When you start to download a video you should immediately be able to also play the still growing file.

The way would be for example:
youtube-dl -oyt_dl http://www.youtube.com/watch?v=VKDiap_6wGo & nvlc yt_dl.part


Another way is to use http://en.savefrom.net/
For a YouTube-video like e.g. 
http://www.youtube.com/watch?v=VKDiap_6wGo
you add "ss" before the youtube.com/... so it looks like this:
http://www.ssyoutube.com/watch?v=VKDiap_6wGo

You should be getting to a website with some download links on the right site for e.g. MP4 360p and MP4 720p. For different videos there are different versions available. Copy your preferred link location and open it with your player.
For me it looks like this:
mplayer "http://r18---sn-i5h7ln76.c.youtube.com/videoplayback?upn=BLCvLQhSTJY&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=909713%2C927900%2C910019%2C910207%2C922401%2C912806%2C925703%2C925706%2C928001%2C922403%2C922405%2C929901%2C913605%2C913546%2C913556%2C920201%2C901632%2C911116%2C901451%2C902556&key=yt1&expire=1355371144&itag=22&ipbits=8&sver=3&ratebypass=yes&mt=1355346792&ip=94.223.213.238&mv=m&source=youtube&ms=au&cp=U0hUSlNST19JTkNONF9LTFNCOi1rQmVxYzVGbEpZ&id=54a0e26a9ffac06a&newshard=yes&signature=8CDA08919F0C6B8CD77A4F7B823C92E7ED543F99.7F40EABAA9B0598C9B02DFC3B24E26F150F8053D&quality=hd720&title=QtDD12%20-%20Welcome%20-%20Kalle%20Dalheimer"


Happy watching!



Btw.: Now here is the new code:
( http://paste.kde.org/624344/ )
#!/bin/sh
#You should be able to change this variable to the player of your liking
myplayer=nvlc

pid=`pgrep -f flashplayer.so`
cacheFile="/tmp/browserFlashFiles.cache.log"
pathFF=~/.mozilla/firefox/*.*/Cache
pathChrome=~/.cache/chromium/*/*

`echo "" > $cacheFile`
rm $cacheFile
for p in $pid
do
    deles=`ls -l1 /proc/$p/fd/ | grep deleted`
    wcDeles=`echo $deles | wc -w`
    wlDeles=`ls -l1 /proc/$p/fd/ | grep -c deleted`

    wPerLine=`expr $wcDeles / $wlDeles`
    offset=3
    i=1
    dval=""
    for d in $deles
    do
        dval=$d
        for numLine in `seq 1 $wlDeles`
        do
            pos=`expr $wPerLine \* $numLine - $offset`
            if [ $i -eq $pos ]
            then
                echo "/proc/$pid/fd/$dval" >> $cacheFile
            fi
        done
        i=`expr $i + 1`
    done
done

`find $pathFF -size +1M -type f -exec file {} \; | grep -E "(Media|Video)" >> $cacheFile`
`find $pathChrome -size +1M -type f -exec file {} \; | grep -E "( Media|Video)" >> $cacheFile`
vim $cacheFile "+%s/:.*//" "+wq"
cat $cacheFile
$myplayer `cat $cacheFile`
rm $cacheFile