-
Notifications
You must be signed in to change notification settings - Fork 7
/
gfv
executable file
·142 lines (123 loc) · 4.14 KB
/
gfv
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
135
136
137
138
139
140
141
142
#!/usr/bin/env ruby
args = ARGV
if args.reject{|arg|arg[/^-\w/]}.empty? or args.delete("--help")
puts "Youtube-DL Wrapper!"
puts
puts "Usage:"
puts " gfv [options] <youtube url(s)>"
puts
puts "Options:"
puts " -h High quality mode"
puts " -l Low(ish) quality mode"
puts " -3 <= 360p"
puts " -4 <= 480p"
puts " -7 <= 720p"
puts " -n Number the files when downloading playlists"
puts " -p Parallel downloader with multiple (5) threads (requires axel)"
puts " -a Download audio only"
puts " -s Download subtitles only"
puts " -S No subtitles!"
puts " -c Download chatlogs w/ subtitles"
puts " -o <filename>"
puts " Set output filename."
puts " ( For a list of variables that can be inserted into the filename, see:"
puts " https://github.com/rg3/youtube-dl/blob/master/README.md#output-template )"
puts
puts "(any other options will be passed directly to youtube-dl)"
puts
exit 1
end
cmd = %w[
youtube-dl
--no-mtime
--xattrs
--add-metadata
--trim-filenames 220
]
urls, opts = args.partition { |arg| arg[%r{^\w{2,20}://.}] }
# --sub-lang=en --write-sub
# --convert-subtitles=srt --sub-lang=en --embed-subs
# if opts.delete("-c")
# slangs << ",live_chat"
# cmd += %w[--write-subs --skip-download --sub-langs live_chat]
# end
unless opts.delete("-S")
slangs = "en.*"
slangs << ",live_chat" if opts.delete("-c")
cmd += ["--sub-format", "srt/ass/vtt/best", "--sub-langs", slangs, "--write-sub"]
end
numbering = opts.delete("-n")
# filename formatter
unless opts.include?("-o")
cmd << "-o"
if numbering
cmd << "%(playlist_index)s. %(title)0.235s.%(ext)s"
else
if urls.any? { |u| u["tiktok.com/"] }
cmd << "%(uploader)s - %(title)0.50s - %(description)0.150s.%(ext)s"
else
cmd << "%(title)0.240s.%(ext)s"
end
end
end
if opts.delete("-a") or urls.all? { |url| url =~ %r{\.bandcamp\.com/} }
cmd << "--extract-audio"
cmd << "--embed-thumbnail"
unless args.include?("-f")
if urls.first =~ %r{\.bandcamp\.com/}
cmd += ["-f", "(mp3-v0/ba[ext=mp3]/ba[ext=m4a]/ba)[acodec!~='([af]lac|wav|aiff)']"]
else
cmd += ["-f", "ba[ext=m4a]/ba[ext=mp3]/ba"]
end
end
elsif opts.delete("-s")
cmd << "--skip-download"
cmd << "--write-auto-sub"
elsif opts.delete("-3")
cmd += %w[-f bestvideo[ext=mp4,height<=?360]+bestaudio[ext=m4a]/best]
elsif opts.delete("-4")
cmd += %w[-f bestvideo[ext=mp4,height<=?480]+bestaudio[ext=m4a]/best]
elsif opts.delete("-7")
cmd += %w[-f bestvideo[ext=mp4,height<=?720]+bestaudio[ext=m4a]/best]
elsif opts.delete("-l")
## youtube-dl defaults to the best quality, so this isn't necessary -- it just causes problems
cmd += %w[-f best --youtube-skip-dash-manifest]
end
# parallel download
if opts.delete("-p")
cmd += ["--downloader", "axel", "--downloader-args", "--num-connections=3"]
end
cmd += opts
urls.each_with_index do |url, i|
n = i+1
#if url =~ %r{^plugin://plugin\.video\.youtube/play/\?video_id=(.+)$}
if url =~ %r{/(?:play/?|watch)\?(?:video_id|v)=([\w\-]+)}
url = "https://youtu.be/#{$1}"
end
url = url.gsub(%r{/nitter\.[^/]+/}, "/twitter.com/")
if url =~ /(youtu\.be|(you|hook)tube\.com|vimeo\.com)/
unless cmd.include?("--skip-download") or cmd.include?("-f") or opts.delete("-h")
cmd += %w[-f bestvideo[width<=?1920][height<=?1080][ext=mp4]+bestaudio[ext=m4a]/best]
# cmd += %w[-f bestvideo[ext=mp4]+bestaudio[ext=m4a]]
end
end
# when numbering is chosen and this isn't a playlist, substitute the arg number into the filename (little hacky, sorry me)
if numbering and not url =~ /(playlist|album)/
pos = cmd.index { |arg| arg == "-o" }
if pos and cmd[pos+1] =~ /playlist_index/
numberstr = "%0.2d" % n
cmd = cmd.dup
# cmd << "%(playlist_index)s. %(title)0.235s.%(ext)s"
cmd[pos+1] = cmd[pos+1].gsub("%(playlist_index)s", numberstr)
end
end
# git it
puts "-------------------------------------------------"
puts " Downloading #{url}"
puts "-------------------------------------------------"
puts
puts "Commandline:"
puts " #{cmd.join(" ")} #{url}"
puts
system *cmd, url
end