Blokovani pres konstantu
[mirrors/Programs.git] / bash / youtube.sh
1 #!/bin/bash
2 #KISS YouTube video downloader
3 #<~~Harvie 2oo8
4
5 echo "Harvie's automatic YouTube downloader";
6 echo " Now go and watch something on YouTube...";
7
8 download_video() {
9 VIDFILE="$2"."flv";
10 DLURL="$1";
11
12 echo Downloading captured video to "$VIDFILE" ...;
13 if [[ -a "$VIDFILE" ]]; then
14 echo File "$VIDFILE" already exists!
15 else
16 curl --url "$DLURL" -o "$VIDFILE" --location -s 2> /dev/null && echo "->" "$VIDFILE" complete! &
17 # wget "$DLURL" -O "$VIDFILE" 2> /dev/null && echo "->" "$VIDFILE" complete! &
18 echo Download started at background!
19 fi;
20 }
21
22 #remove "-p" option for ngrep to download videos wieved from other computers...
23 ngrep $@ -p port 80 | while read line; do
24
25 if [[ "$line" =~ "GET /get_video\?video_id=(.*)&t=(.*) HTTP" ]]; then
26 DLURL="http://www.youtube.com/get_video?video_id=${BASH_REMATCH[1]}&t=${BASH_REMATCH[2]}";
27 WURL="http://www.youtube.com/watch?v=${BASH_REMATCH[1]}"
28
29 echo ---------------------------------------------------;
30 echo;
31 echo Captured video download URL: "$DLURL";
32 echo Captured video watch URL: "$WURL";
33 echo Getting video info...;
34
35 curl "$WURL" 2> /dev/null | grep "<title>" | while read iline; do
36 if [[ "$iline " =~ "<title>YouTube - (.*)</title>" ]]; then
37 VIDTITLE=$( echo "${BASH_REMATCH[1]}" );
38 echo Captured video title: "$VIDTITLE";
39 download_video "$DLURL" "$VIDTITLE";
40 break;
41 fi;
42 done;
43 fi;
44
45 done;
This page took 0.522676 seconds and 4 git commands to generate.