-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvd.sh
executable file
·134 lines (120 loc) · 4.43 KB
/
vd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/zsh
# Author: Onur Yildirim ([email protected])
# -------------------------------------
# CONSTANTS
# -------------------------------------
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# -------------------------------------
# IMPORTS
# -------------------------------------
# create if does not exist
touch ~/.bash_profile
source ~/.zshrc
source "$CURRENT_DIR"/shelper.sh
source "$CURRENT_DIR"/workflowHandler.sh
# -------------------------------------
# VARIABLES
# -------------------------------------
#yt="$CURRENT_DIR/bin/youtube-dl"
#yt="$CURRENT_DIR/bin/yt-dlp"
yt="yt-dlp"
instagram_cookie="$CURRENT_DIR/cookies/instagram.com_cookies.txt"
facebook_cookie="$CURRENT_DIR/cookies/facebook.com_cookies.txt"
youtube_cookie="$CURRENT_DIR/cookies/youtube.com_cookies.txt"
twitter_cookie="$CURRENT_DIR/cookies/twitter.com_cookies.txt"
download_dir=~/youtube-dl/
output_format="$download_dir%(title)s-%(id)s.%(ext)s"
ffmpeg_installed=$(program_exists "ffmpeg")
aria2c_installed=$(program_exists "aria2c")
#ffmpeg_installed=true
video_url="$1" # "{query}"
video_format="$2"
video_size="$3"
play=$(contains_str "$4" "-play")
extract_audio=$(contains_str "$5" "-audio")
options="--restrict-filenames -i -q -o "$output_format" "
#options="--restrict-filenames -i -q -o "$output_format" --recode-video mov "
message=""
audio_format=""
video_filter=""
# -------------------------------------
# PROGRAM ROUTINE
# -------------------------------------
#echo "format = $video_format size = $video_size"
mkdir -p $download_dir
if $extract_audio; then
if $ffmpeg_installed; then
audio_format="mp3"
options=""$options" --extract-audio --embed-thumbnail --audio-format "$audio_format""
else
echo "Failed! Install ffmpeg for audio conversion."
echo "Type \"vd-help\" for instructions."
exit 1
fi
else
#if ! [ -z "$video_format" ]; then
if ! [ $video_format -eq -1 ]; then
#video_format="[ext="$video_format"]"
#audio_format="[ext=m4a]"
options="$options --recode-video $video_format "
#echo "$video_format"
#video_filter="vcodec:h264,acodec:m4a,br,res"
video_filter="codec:$video_format"
fi
if ! [ $video_size -eq -1 ]; then
#video_size="[height<="$video_size"]"
#echo "$video_size"
video_filter="res:$video_size,"$video_filter""
fi
options="$options -S "$video_filter",br,ext "
#options="$options -f "\(bv"$video_size""$video_format"+ba"$audio_format"/b\)[vcodec=av01] / \(bv"$video_size""$video_format"+ba"$audio_format"/b\)[vcodec=h264] / \(bv"$video_size""$video_format"+ba"$audio_format"/b\)[vcodec=vp9] /\(bv*"$video_size"+ba"$audio_format"/best\) " "
#options="$options -f "bestvideo"$video_size""$video_format"+bestaudio"$audio_format"/best"$video_size""$video_format"/best""
if $aria2c_installed; then
options=""$options" --external-downloader aria2c --external-downloader-args "-x 16 -s16 -k 1M" "
fi
fi
if [[ $video_url == *"instagram"* ]]; then
cookie=$instagram_cookie
fi
if [[ $video_url == *"facebook"* ]] || [[ $video_url == *"fb.watch"* ]]; then
cookie=$facebook_cookie
fi
if [[ $video_url == *"youtube"* ]] || [[ $video_url == *"youtu.be"* ]]; then
cookie=$youtube_cookie
fi
if [[ $video_url == *"twitter"* ]] || [[ $video_url == *"twitt"* ]]; then
cookie=$twitter_cookie
fi
if [[ -e $cookie ]]; then
#options="$options --cookies-from-browser vivaldi"
options=""$options" --cookies "$cookie""
fi
#echo "$yt $video_url $options"
yt_output="$($yt "$video_url" $options 2>&1)"
download_result=$?
if [ $download_result -eq 0 ]; then
filepathOpt="--restrict-filenames --get-filename"
if [[ -e $cookie ]]; then
filepathOpt=""$filepathOpt" --cookies "$cookie""
fi
filepath="$($yt $filepathOpt "$video_url")"
if ! [ -f "$filepath" ]; then
filepath="$(remove_ext "$filepath")".mp4;
fi
if [[ "$extract_audio" == true && "$ffmpeg_installed" == true ]]; then
#filepath="$(remove_ext "$filepath").$audio_format";
filepath="$(remove_ext "$filepath")."$audio_format"";
#echo $filepath
fi
if $play; then
sleep 2
open "$download_dir/$filepath"
echo "Now Playing: "$filepath""
else
echo "$download_dir/$filepath"
#echo "Download complete: $filepath"
fi
else
echo "Download failed -> $download_result"
echo $yt_output
fi