Ĉi tiu deponejo arĥiviĝis je 2024-01-29. Vi povas vidi kaj elŝuti dosierojn, sed ne povas puŝi nek raporti problemojn nek tirpeti.
shellTube/lib/yt-down

111 lines
2.7 KiB
Plaintext
Raw Normal View History

2016-12-11 19:33:57 -06:00
#!/bin/sh
#####################
# Name: yt-download.sh
# Date: 2016-12-10
# Lisc: GPLv2
# Auth: iluaster
# Main: jadedctrl
# Desc: Fetches YT videos.
#####################
# Based on https://github.com/iluaster/Youtube_downloader
# Usage: yt-download.sh $video_id
2016-12-26 03:58:01 -06:00
if [ "$1" = "-s" ]
2016-12-11 19:33:57 -06:00
then
stream_mode=1
id=$2
else
stream_mode=0
id=$1
fi
if echo "$id" | grep "youtube.com"
then
2016-12-26 03:58:01 -06:00
id="$(echo "$id" | sed 's/.*video_id=//')"
elif [ -z "$id" ]
2016-12-11 19:33:57 -06:00
then
echo "No video specified."
exit 1
else
id="$id"
fi
name="http://www.youtube.com/get_video_info?video_id=$id"
2016-12-26 03:58:01 -06:00
declare -i line=0 2> /dev/null
2016-12-11 19:33:57 -06:00
2016-12-26 03:58:01 -06:00
if $? 2> /dev/null
then
echo > /dev/null
else
line=0
fi
select_option ()
2016-12-11 19:33:57 -06:00
{
echo "Formats:"
2016-12-26 03:58:01 -06:00
cat /tmp/video_type_option.txt | while IFS='' read -r i
2016-12-11 19:33:57 -06:00
do
2016-12-26 03:58:01 -06:00
line=$((line+1))
# Replace this pipe method so $line isn't lost
2016-12-11 19:33:57 -06:00
echo "${line}. $i"
done
2016-12-23 11:12:07 -06:00
printf '\033[0;32m>>>\033[0m '
2016-12-26 03:58:01 -06:00
IFS=''
2016-12-11 19:33:57 -06:00
read -r n
2016-12-26 03:58:01 -06:00
if [ $n -le 5 ];
2016-12-11 19:33:57 -06:00
then
head -n "$n" /tmp/tmp3.txt | tail -n 1 > /tmp/tmp4.txt
else
2016-12-26 03:58:01 -06:00
echo "$line $n"
2016-12-11 19:33:57 -06:00
echo "Input Error!"
line=0
select_option
fi
}
2016-12-26 03:58:01 -06:00
st-download "$name" "/tmp/${id}_url.txt"
2016-12-11 19:33:57 -06:00
# Cut and filter mp4 url
cp "/tmp/${id}_url.txt" /tmp/tmp2.txt
sed -e 's/&/\n/g' /tmp/tmp2.txt| grep 'url_encoded_fmt_stream_map'> /tmp/tmp3.txt
sed -i -e 's/%2C/,/g' /tmp/tmp3.txt
sed -i -e 's/,/\n/g' /tmp/tmp3.txt
# Print out total video format name and quality
perl -ne 'print "$2,$1\n" if /quality%3D(.*?)%.*video%252F(.*?)(%|\n)/' /tmp/tmp3.txt > /tmp/video_type_option.txt
# If video format name is prior to quality
perl -ne 'print "$1,$2\n" if /video%252F(.*?)%.*quality%3D(.*?)(%|\n)/' /tmp/tmp3.txt >> /tmp/video_type_option.txt
sed -i -e 's/x-flv/flv/g' /tmp/video_type_option.txt
select_option
# Set file extension name variable and video quality variable
extension_name=$(head -n "$n" /tmp/video_type_option.txt | tail -n 1 | cut -d "," -f 1)
quality_name=$(head -n "$n" /tmp/video_type_option.txt | tail -n 1 | cut -d "," -f 2)
sed -i -e 's/%26/\&/g' /tmp/tmp4.txt
sed -i -e 's/&/\n/g' /tmp/tmp4.txt
grep 'http' /tmp/tmp4.txt > /tmp/tmp5.txt
grep 'sig%3D' /tmp/tmp4.txt >> /tmp/tmp5.txt
perl -pe 's/\n//g' /tmp/tmp5.txt | sed -e 's/sig%3D/\&signature%3D/g' > /tmp/tmp6.txt
sed -i -e 's/url%3D//g' /tmp/tmp6.txt
# url decoding
cat /tmp/tmp6.txt | sed -e 's/%25/%/g' -e 's/%25/%/g' -e 's/%3A/:/g' -e 's/%2F/\//g' -e 's/%3F/\?/g' -e 's/%3D/=/g' -e 's/%26/\&/g' > /tmp/tmp7.txt
if [ $stream_mode -eq 1 ]
then
2016-12-26 03:58:01 -06:00
st-video "$(cat /tmp/tmp7.txt)"
2016-12-11 19:33:57 -06:00
else
2016-12-26 03:58:01 -06:00
st-download "$(cat /tmp/tmp7.txt)" "${id}_${quality_name}.${extension_name}"
2016-12-11 19:33:57 -06:00
fi
2016-12-26 03:58:01 -06:00
rm -f /tmp/tmp[2-7].txt "/tmp/${id}_url.txt" /tmp/video_type_option.txt