-
Notifications
You must be signed in to change notification settings - Fork 3
/
yd.rb
188 lines (182 loc) · 5.52 KB
/
yd.rb
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# YT-Downloader
# Author : KasRoudra
# Github : https://github.com/KasRoudra
# Messenger : https://m.me/KasRoudra
# Email : kasroudrakrd@gmail.com
# Date : 26-08-2021
# Main Language: Ruby
# Description : Download any video or audio of youtube from command line
black="\033[0;30m"
red="\033[0;31m"
green="\033[0;32m"
yellow="\033[0;33m"
blue="\033[0;34m"
purple="\033[0;35m"
cyan="\033[0;36m"
white="\033[0;37m"
logo="""
"""+green+"""╭╮╱╱╭┳━━━━╮╭━━━╮╱╱╱╱╱╱╱╱╱╱╭╮╱╱╱╱╱╱╱╱╭╮
"""+red+"""┃╰╮╭╯┃╭╮╭╮┃╰╮╭╮┃╱╱╱╱╱╱╱╱╱╱┃┃╱╱╱╱╱╱╱╱┃┃
"""+yellow+"""╰╮╰╯╭┻╯┃┃╰╯╱┃┃┃┣━━┳╮╭╮╭┳━╮┃┃╭━━┳━━┳━╯┣━━┳━╮
"""+cyan+"""╱╰╮╭╯╱╱┃┃╭━━┫┃┃┃╭╮┃╰╯╰╯┃╭╮┫┃┃╭╮┃╭╮┃╭╮┃┃━┫╭╯
"""+red+"""╱╱┃┃╱╱╱┃┃╰━┳╯╰╯┃╰╯┣╮╭╮╭┫┃┃┃╰┫╰╯┃╭╮┃╰╯┃┃━┫┃
"""+green+"""╱╱╰╯╱╱╱╰╯╱╱╰━━━┻━━╯╰╯╰╯╰╯╰┻━┻━━┻╯╰┻━━┻━━┻╯
"""
ask = green + '[' + white + '?' + green + '] '+ yellow
success = green + '[' + white + '√' + green + '] '
error = red + '[' + white + '!' + red + '] '
info= yellow + '[' + white + '+' + yellow + '] '+ cyan
pw= yellow + '[' + white + '+' +yellow + ']'+' Please Wait!'
begin
require "httparty"
rescue LoadError => e
system("gem install httparty")
puts error+"Please restart"
exit
rescue Exception => e
print_exception(e, false)
exit
end
if not (File.file?("/usr/bin/wget") or File.file?("/data/data/com.termux/files/usr/bin/wget"))
system("apt install wget -y")
end
if Dir.exist?('/data/data/com.termux/files/home')
if not File.file?("/data/data/com.termux/files/usr/bin/termimage")
system("apt install termimage -y")
end
end
require "rubygems"
require "httparty"
system("clear")
puts logo+"\n\n"
print ask+"Choose one of the following:\n\n1.Audio\n2.Video\n0.Exit\n"+yellow+"---> "+ green
type=gets.chomp
case type
when "1"
print "\n"+ask+"Enter the youtube url:\n"+yellow+"---> "+ green
url=gets.chomp
if not url.include? "youtu"
puts error+"Error! This is not a youtube link!"
exit
end
puts pw+"\n"+cyan
begin
response = HTTParty.get("https://api.zeks.xyz/api/ytmp3?url=#{url}&apikey=apivinz")
rescue SocketError => e
puts error+"No internet"
sleep(1)
exit
rescue Exception => e
print_exception(e, false)
exit
end
post = response.parsed_response
status= "#{post['status']}"
while not post==""
if status==""
puts info+"Currently service not available. Server reached daily limit. Try again later."
exit
elsif status == "true"
break
elsif status == "false"
puts error+"Wrong url"
exit
else
puts error+"Error"
exit
end
end
link = "#{post['result']['url_audio']}"
when "2"
print ask+"Enter the youtube url:\n"+yellow+"---> "+ green
url=gets.chomp
if not url.include? "youtu"
puts error+"Error! This is not a youtube link!"
exit
end
puts pw+"\n"+cyan
begin
response = HTTParty.get("https://api.zeks.xyz/api/ytmp4?url=#{url}&apikey=apivinz")
rescue SocketError => e
puts error+"No internet"
sleep(1)
exit
rescue Exception => e
print_exception(e, false)
exit
end
post = response.parsed_response
status= "#{post['status']}"
while not post==""
if status==""
puts "Currently service not available. Server reached daily limit. Try agin later!"
exit
elsif status== "true"
break
elsif status == "false"
puts error+"Wrong url"
exit
else
puts error+"Error"
exit
end
end
link = "#{post['result']['url_video']}"
when "0"
exit
else
puts error+"Wrong input. Please choose 1 or 2"
exit
end
title = "#{post['result']['title']}"
thumbnail= "#{post['result']['thumbnail']}"
puts "Title : #{title}"
puts "Filesize : #{post['result']['size']}"
if Dir.exist?('/data/data/com.termux/files/home')
puts "Thumbnail :"
system("wget -O '#{title}.jpg' #{thumbnail} -q")
system("termimage '#{title}.jpg' && rm -rf '#{title}.jpg'")
end
puts "\n\n"+info+"Download Link : #{link}\n"
print "\n"+ask+"Start Download?(y/n) > "+green
confirm= gets.chomp()
if confirm=="y" && type== "1"
puts yellow+"\n[+] Starting Download....."
system("wget -O '#{title}.mp3' #{link} -q --show-progress")
puts "\n"+success+"#{title}.mp3 successfully downloaded!"
print "\n"+ask+"Move to a custom path?(y/n) > "+green
pt=gets.chomp
if pt=="y"
print "\n"+ask+"Enter path > "+green
path=gets.chomp
if Dir.exist?(path)
system("mv -f '#{title}.mp3' #{path}")
puts "\n"+success+"#{title}.mp3 moved to #{path}"
else
puts error+"Directory not found"
end
else
exit
end
elsif confirm=="y" && type== "2"
puts yellow+"\n[+] Starting Download....."
system("wget -O '#{title}.mp4' #{link} -q --show-progress")
puts "\n"+success+"#{title}.mp4 successfully downloaded!"
print "\n"+ask+"Move to a custom path?(y/n) > "+green
pt=gets.chomp
if pt=="y"
print "\n"+ask+"Enter path > "+green
path=gets.chomp
if Dir.exist?(path)
system("mv -f '#{title}.mp4' #{path}")
puts "\n"+success+"#{title}.mp4 moved to #{path}"
else
puts error+"Directory not found!"
exit
end
else
exit
end
else
exit
end