-
Notifications
You must be signed in to change notification settings - Fork 0
/
d-pro.py
521 lines (401 loc) · 18.1 KB
/
d-pro.py
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
#!/bin/python
"""
# All in One video Downloader By ToxicNoob Inc.
# Author: ToxicNoob Inc.
# GitHub: https://github.com/toxic-noob
# Supports some Famous video sharing Websites
# Including: YouTube, Facebook, Tiktok, Insproces
# Downloaded files are saved in /sdcard/Download
# Used online API to Download Videos, so no extra Libraries Needed
# Supports MP4 + MP3
# Supports YouTube Playlist Downloading
# API Resources:
01. yt1s.com (For single YouTube Videos)
02. getfvid.com (For Facebook Videos)
03. videodownloaderpro.net (For YouTube Playlist and Random website Videos)
04. youtubemultidownloader.org (For Extracting Video URLs from Playlist)
"""
import requests
import time
import os
import sys
import shutil
import re
from datetime import datetime
columns = shutil.get_terminal_size().columns
def psb(z, end = "\n"):
z = printAZ(z, True)
for p in z + end:
sys.stdout.write(p)
sys.stdout.flush()
time.sleep(0.01)
# Logo
def logo():
os.system("clear")
print("\033[94m┌────────────────────────────────────────┐".center(columns+5))
print("\033[94m│ \033[92m▛▀▖ ▜ ▌▛▀▖ \033[94m │".center(columns+15))
print("\033[94m│ \033[92m▌ ▌▞▀▖▌ ▌▛▀▖▐ ▞▀▖▝▀▖▞▀▌▙▄▘▙▀▖▞▀▖\033[94m │".center(columns+15))
print("\033[94m│ \033[92m▌ ▌▌ ▌▐▐▐ ▌ ▌▐ ▌ ▌▞▀▌▌ ▌▌ ▌ ▌ ▌\033[94m │".center(columns+15))
print("\033[94m│ \033[92m▀▀ ▝▀ ▘▘ ▘ ▘ ▘▝▀ ▝▀▘▝▀▘▘ ▘ ▝▀ \033[94m │".center(columns+15))
print("\033[94m│ \033[94m │".center(columns+9))
print("\033[94m│ \033[95mAuthor : ToxicNoob \033[94m│".center(columns+15))
print("│ \033[95mTool : All Video Downloader \033[94m│".center(columns+9))
print("│ \033[95mGitHub : https://github.com/Toxic-Noob \033[94m│".center(columns+9))
print("│ \033[95mCoder : HunterSl4d3 \033[37mV1.0\033[94m│".center(columns+15))
print("\033[94m└────────────────────────────────────────┘".center(columns+5))
# Print with Color (Using this to avoid color code confusion and external lirary)
def printAZ(text, returnT=False):
printText = text.replace("cWhite", "\033[37m").replace("cGreen", "\033[92m").replace("cRed", "\033[91m").replace("cBlue", "\033[94m")
if (returnT):
return printText
print(printText)
# Show Error Message
def errorMsg(errorCode = 0):
if (errorCode == 2):
psb("\ncGreen [cRed!cGreen] cWhiteInvalid Video URL!")
else:
print("error")
psb("\ncGreen [cRed!cGreen] cWhiteAn Error Occured!")
psb("cGreen [cRed!cGreen] cWhiteTry Checking Your Internet Connection or Video URL")
sys.exit("\033[37m")
exit()
# Get User Option Input
def getOptionNumber(o):
opList = [str(x) for x in range(1, int(o)+1)]
op = input(printAZ("\ncGreen [cWhite*cGreen] cWhiteEnter Your Choice:> cGreen", True))
if (op[0] == "0"): op = op[1:]
if not (op in opList):
psb("\ncGreen [cRed!cGreen] cWhitePlease Enter a Correct Option!")
op = getOptionNumber(o)
return op
#Print Video Details
def printDetails(videoTitle, videoSource, videoDuration, videoExt):
logo()
psb("\ncGreen [cWhite*cGreen] Video Title: cWhite" + (videoTitle if videoTitle == "YouTube" else videoTitle.title()))
psb("cGreen [cWhite*cGreen] Video Duration: cWhite" + videoDuration)
psb("cGreen [cWhite*cGreen] Video Source: cWhite" + videoSource)
psb("\ncGreen [cWhite#cGreen] cWhiteChoose Your File Format:\n")
sl = 1
for qual in videoExt:
if (len(str(sl)) == 1):
serial = "0" + str(sl)
else:
serial = str(sl)
formate = qual["formate"].upper()
quality = qual["quality"]
size = qual["size"]
if (size == ""):
size = "UNKNOWN"
printAZ("cGreen [cWhite" + serial + "cGreen] cWhite" + formate + " cWhite(cGreen" + quality + "cWhite) cBlue[cWhite Size: cGreen" + size + "cBlue]")
sl += 1
#####################################
# Video Dowenload Processes Starting Here
#
# 01. Process FaceBook Video Download
# 02. Process Random Website Video Download
# 03. Process YouTube Video/Playlist Download
#### 01. Single Video
#### 02. Video Playlist
#
#####################################
# 01, Process FaceBook Video Download
vidExt = []
def downloadFacebook(videoUrl):
from bs4 import BeautifulSoup
psb("\ncGreen [cWhite#cGreen] cWhiteFetching Video DatacGreen: cWhite", end="")
url = "https://www.getfvid.com/downloader"
headers = {
"Host": "www.getfvid.com",
"cache-control": "max-age=0",
"upgrade-insecure-requests": "1",
"origin": "https://www.getfvid.com",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"referer": "https://www.getfvid.com/",
"accept-language": "en-US,en;q=0.9",
"cookie": "cookieconsent_status=dismiss",
}
data = {"url" : videoUrl}
response = requests.post(url, headers=headers, data=data)
if not (response.status_code == 200):
errorMsg()
responseData = response.text
htmlData = BeautifulSoup(responseData, "html.parser")
try:
videoLinks = [item['href'] for item in htmlData.find_all('a', attrs={'href' : True, 'download' : True})]
videoTitle = htmlData.find('input', {'id' : 'title_video'})['value'].replace("-facebookFacebook WatchVideo UnavailableSorry, this video could not be played.Learn more", "").replace("\n", " ")
except:
errorMsg()
print("Done")
time.sleep(0.5)
logo()
psb("\ncGreen [cWhite#cGreen] cWhiteVideo Title: cGreen" + videoTitle)
psb("cGreen [cWhite#cGreen] cWhiteVideo Source: cGreenFaceBook")
psb("\ncGreen [cWhite*cGreen] cWhiteChoose Your File Format:\n")
o = 1
for link in videoLinks:
qText = htmlData.find('a', {'href' : link}).text
if ("Audio" in qText):
vidExt.append("mp3")
else:
vidExt.append("mp4")
printAZ("cGreen [cWhite" + ("0" + str(o) if (len(str(o))) == 1 else str(o)) + "cGreen] cWhite" + qText)
o += 1
printAZ("cGreen [cWhite" + ("0" + str(o) if (len(str(o))) == 1 else str(o)) + "cGreen] cWhiteExit")
op = getOptionNumber(o)
if (op == o):
sys.exit("\033[37m")
downloadUrl = videoLinks[int(op) - 1]
downloadPath = "/sdcard/Download/" + videoTitle.replace("\"", "\\\"").replace("/", "\/")[:125] + "_D-Pro." + vidExt[int(op) - 1]
psb("\ncGreen [cWhite#cGreen] cWhiteStarting Download Process: \ncGreen")
os.system("wget -O \"" + downloadPath + "\" \"" + downloadUrl + "\" -q --show-progress --no-check-certificate")
os.system("touch -d \"" + str(datetime.now()) + "\" \"" + downloadPath + "\"")
printAZ("\ncGreen [cWhite#cGreen] cWhiteDownload Complete!")
printAZ("cGreen [cWhite#cGreen] cWhiteFile Saved In cGreenDownloads")
sys.exit("\n\033[37m")
# 02. Process Random Website Video Download
def randomDownload(videoUrl):
psb("\ncGreen [cWhite#cGreen] cWhiteFetching Video DatacGreen: cWhite", end="")
try:
response = requests.post("https://api.videodownloaderpro.net/api/convert", json = {"url": videoUrl})
except:
errorMsg()
if not (response.status_code == 200):
errorMsg()
videoData = response.json()
if ("Convert failed" in videoData):
errorMsg()
print("Done")
time.sleep(0.5)
logo()
videoTitle = videoData["meta"]["title"]
try:
videoDuration = videoData["meta"]["duration"]
except KeyError:
videoDuration = "UNKNOWN"
videoSourceUrl = videoData["meta"]["source"]
dots = [m.start() for m in re.finditer("\.", videoSourceUrl)]
if (len(dots) == 1):
videoSource = videoSourceUrl[:dots[0]]
else:
videoSource = videoSourceUrl[dots[0]+1:dots[-1]]
tmpUrlData = videoData["url"]
tmpVidData = []
# Filtering Uncommon File Formates and Audioless Videos
for v in tmpUrlData:
support = ["mp4", "mp3", "m4a"]
if (v["ext"] in support):
if ("audio" in v.keys()):
if not ((v["audio"] == False) and (v["no_audio"] == True)):
tmpVidData.append(v)
else:
tmpVidData.append(v)
# Making a easy-to-understand Dictionary List
videoExt = []
for tmp in tmpVidData:
try:
size = tmp["contentLength"]
size = size / (1024*1024)
if (size < 1):
size = str(size * 1024)[:4] + " KB"
else:
size = str(size) + " MB"
except KeyError:
size = "UNKNOWN"
formate = tmp["ext"]
try:
quality = tmp["quality"]
if (formate == "mp4"):
quality = quality + "p"
else:
quality = quality + "Kbps"
except:
quality = "UNKNOWN"
data = {"size": size, "formate": formate, "quality": quality, "url": tmp["url"]}
videoExt.append(data)
printDetails(videoTitle, videoSource, videoDuration, videoExt)
sl = len(videoExt) + 1
printAZ("cGreen [cWhite" + ("0" + str(sl) if (len(str(sl))) == 1 else str(sl)) + "cGreen] cWhiteExit")
op = getOptionNumber(sl)
if (op == str(sl)):
sys.exit("\033[37m")
selected = videoExt[int(op) - 1]
psb("\ncGreen [cWhite#cGreen] cWhiteConverting VideocGreen: cWhite", end="")
downloadUrl = selected["url"]
time.sleep(1)
print("Done")
downloadPath = "/sdcard/Download/" + videoTitle.replace("\"", "\\\"").replace("/", "\/")[:125] + "_D-Pro." + selected["formate"]
psb("\ncGreen [cWhite#cGreen] cWhiteStarting Download Process: \ncGreen")
os.system("wget -O \"" + downloadPath + "\" \"" + downloadUrl + "\" -q --show-progress --no-check-certificate")
os.system("touch -d \"" + str(datetime.now()) + "\" \"" + downloadPath + "\"")
printAZ("\ncGreen [cWhite#cGreen] cWhiteDownload Complete!")
printAZ("cGreen [cWhite#cGreen] cWhiteFile Saved In cGreenDownloads")
sys.exit("\n\033[37m")
# 03. Process YouTube Video/Playlist Download
#### 01. Single Video
# Fetching video Download Data
def fetchYTurl(videoUrl):
url = "https://yt1s.com/api/ajaxSearch/index"
data = {"q" : videoUrl,"vt" : "home"}
responseData = requests.post(url, data = data).json()
try:
if not (responseData["p"] == "convert"):
errorMsg()
except:
errorMsg()
try:
videoCode = responseData["vid"]
videoTitle = responseData["title"]
videoLinks = responseData["links"]
tmpTime = responseData["t"]
except:
errorMsg()
# Making an easy-to-understand Dictionary List
videoData = []
for type in videoLinks:
for i in videoLinks[type]:
tmp = videoLinks[type][i]
data = {"size": tmp["size"], "formate": tmp["f"], "quality": tmp["q"], "code": tmp["k"]}
videoData.append(data)
videoDur = time.strftime("%H:%M:%S", time.gmtime(tmpTime))
returnData = {"title": videoTitle, "code": videoCode, "source": "YouTube", "duration": videoDur, "extracters": videoData}
return returnData
# Fetching Video Url
def downloadYouTube(videoUrl):
psb("\ncGreen [cWhite#cGreen] cWhiteFetching Video DatacGreen: cWhite", end="")
videoData = fetchYTurl(videoUrl)
videoTitle = videoData["title"]
videoCode = videoData["code"]
videoSource = videoData["source"]
videoDuration = videoData["duration"]
videoExt = videoData["extracters"]
print("Done")
time.sleep(0.5)
printDetails(videoTitle, videoSource, videoDuration, videoExt)
sl = len(videoExt) + 1
printAZ("cGreen [cWhite" + ("0" + str(sl) if (len(str(sl))) == 1 else str(sl)) + "cGreen] cWhiteExit")
op = getOptionNumber(sl)
if (op == str(sl)):
sys.exit("\033[37m")
selected = videoExt[int(op) - 1]
psb("\ncGreen [cWhite#cGreen] cWhiteConverting VideocGreen: cWhite", end="")
url = "https://yt1s.com/api/ajaxConvert/convert"
data = {"vid" : videoCode,"k" : selected["code"]}
responseData = requests.post(url, data=data).json()
if not (responseData["c_status"] == "CONVERTED"):
errorMsg()
downloadUrl = responseData["dlink"]
print("Done")
downloadPath = "/sdcard/Download/" + videoTitle.replace("\"", "\\\"").replace("/", "\/")[:125] + "_D-Pro." + selected["formate"]
psb("\ncGreen [cWhite#cGreen] cWhiteStarting Download Process: \ncGreen")
os.system("wget -O \"" + downloadPath + "\" \"" + downloadUrl + "\" -q --show-progress --no-check-certificate")
os.system("touch -d \"" + str(datetime.now()) + "\" \"" + downloadPath + "\"")
printAZ("\ncGreen [cWhite#cGreen] cWhiteDownload Complete!")
printAZ("cGreen [cWhite#cGreen] cWhiteFile Saved In cGreenDownloads")
sys.exit("\033[37m")
#### 02. Video Playlist
# Downloader for Videos from Playlist
def downloadFromList(video, formate, retrying=False):
videoUrl = video["url"]
videoTitle = video["title"]
ext = formate["formate"]
ext2 = "none"
if (ext == "mp3"):
ext2 = "m4a"
quality = formate["qualNo"]
if not (retrying):
psb("\ncGreen[cWhite Fetching cGreen] cWhite" + videoTitle + "cGreen: cWhite", end = "")
try:
response = requests.post("https://api.videodownloaderpro.net/api/convert", json = {"url": videoUrl})
except:
print("Error")
psb("cGreen[cWhite*cGreen] cWhiteRetryingcGreen: cWhite", end = "")
downVid(video, formate)
return
if not (response.status_code == 200):
print("Error")
psb("cGreen[cWhite*cGreen] cWhiteRetryingcGreen: cWhite", end = "")
downVid(video, formate)
return
videoData = response.json()["url"]
tmpVidData = []
for v in videoData:
support = ["mp4", "mp3", "m4a"]
if (v["ext"] in support):
if ("audio" in v.keys()):
if not ((v["audio"] == False) and (v["no_audio"] == True)):
tmpVidData.append(v)
else:
tmpVidData.append(v)
formfilt = []
for v in tmpVidData:
if (v["ext"] == ext) or (v["ext"] == ext2):
formfilt.append(v)
quallist = []
for v in formfilt:
quallist.append(v["quality"])
quallist.sort()
if not (quality in quallist):
quality = quallist[-1]
for v in formfilt:
if (v["quality"] == quality):
downloadUrl = v["url"]
break
printAZ("DonecGreen")
downloadPath = "/sdcard/Download/" + videoTitle.replace("\"", "\\\"").replace("/", "\/")[:125] + "_D-Pro." + ext
os.system("wget -O \"" + downloadPath + "\" \"" + downloadUrl + "\" -q --show-progress --no-check-certificate")
os.system("touch -d \"" + str(datetime.now()) + "\" \"" + downloadPath + "\"")
psb("cGreen[cWhite#cGreen] cWhiteSystem Sleeping: cGreen", end="")
for i in [5, 4, 3, 2, 1, 0]:
sys.stdout.write("\b" + str(i))
sys.stdout.flush()
time.sleep(1)
print("")
# Fetch Playlist Data
def downloadPlaylist(playlistUrl):
psb("\ncGreen [cWhite#cGreen] cWhiteFetching Playlist DatacGreen: cWhite", end="")
try:
playlistData = requests.get("https://youtubemultidownloader.org/scrapp/backend/yt-get.php?url=" + playlistUrl).json()
except:
errorMsg()
if (playlistData["status"] == False):
errorMsg()
videoList = playlistData["items"]
print("Done")
time.sleep(0.5)
logo()
videoFormates = {"1": {"formate": "mp4", "quality": "240p", "qualNo": "240"}, "2": {"formate": "mp4", "quality": "360p", "qualNo": "360"}, "3": {"formate": "mp4", "quality": "720p", "qualNo": "720"}, "4": {"formate": "mp3", "quality": "128kbps", "qualNo": "128"}}
psb("\ncGreen [cWhite*cGreen] Video Source: cWhiteYouTube")
psb("cGreen [cWhite*cGreen] Note: cWhiteClosest Quality will be Downloaded If the Choosen Quality doesn't exist")
psb("\ncGreen [cWhite#cGreen] cWhiteChoose Your File Format: \n")
for i in videoFormates:
printAZ("cGreen [cWhite0" + i + "cGreen] cWhite" + videoFormates[i]["formate"].upper() + " (cGreen" + videoFormates[i]["quality"] + "cWhite) cBlue[cWhite Size: cGreen Auto cBlue]")
printAZ("cGreen [cWhite05cGreen] cWhiteExit")
op = str(getOptionNumber(5))
if (op == "5"):
sys.exit("\033[37m")
for video in videoList:
downloadFromList(video, videoFormates[op])
printAZ("\ncGreen [cWhite#cGreen] cWhitePlaylist Download Complete!")
printAZ("cGreen [cWhite#cGreen] cWhiteFiles Saved In cGreenDownloads")
sys.exit("\n\033[37m")
# Process URL
def processUrl(videoUrl = None):
if not (videoUrl):
videoUrl = input(printAZ("\ncGreen [cWhite*cGreen] cWhiteEnter Your Video/Playlist URL:> cGreen", True))
if not (videoUrl.startswith("http://")) and not (videoUrl.startswith("https://")):
errorMsg(2)
if ("facebook.com" in videoUrl.lower()) or ("fb.watch" in videoUrl.lower()):
downloadFacebook(videoUrl)
elif ("youtube.com/playlist?list=" in videoUrl.lower()):
downloadPlaylist(videoUrl)
elif ("youtube.com" in videoUrl.lower()) or ("youtu.be" in videoUrl.lower()):
downloadYouTube(videoUrl)
else:
randomDownload(videoUrl)
if (__name__ == "__main__"):
try:
videoUrl = sys.argv[1]
processUrl(videoUrl)
except IndexError:
logo() # Removable
processUrl()