-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathytdownload.py
More file actions
executable file
·63 lines (52 loc) · 2.02 KB
/
ytdownload.py
File metadata and controls
executable file
·63 lines (52 loc) · 2.02 KB
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
import subprocess as sb
import os
#global shit
app = "youtube-dl"
path = "-o '$HOME/Downloads/youtube-dl_songs/%(channel)s/%(title)s - %(channel)s.%(ext)s'"
title = "-f 140 -o '%(title)s - %(channel)s.%(ext)s'"
audiodownload = "-f 140 --extract-audio --audio-format mp3 --audio-quality 0"
thumbnaildownload = "--write-thumbnail --skip-download"
filename = "--get-filename"
#function to check if name is present or not
def check_name(name):
names = []
#load names form the history file
with open("/home/sohamch/yt-download_history.txt",'r') as f:
for line in f.readlines():
l = line.strip("\n")
names.append(l)
f.close()
if name in names:
return True
else:
return False
#generate bash file
def generate_bash():
with open("/home/sohamch/command.sh","w") as f:
f.write(f"{app} {path} {audiodownload} {link}\n")
f.write(f"{app} {path} {thumbnaildownload} {link}\n")
f.write(f"{app} {title} {link} {filename} >> $HOME/yt-download_history.txt\n")
f.write("find ~/Downloads/youtube-dl_songs -name '*.webp' -exec magick {} {}.png \; -exec rm {} \;\n")
f.write("sort -o $HOME/yt-download_history.txt $HOME/yt-download_history.txt")
f.close()
link = input()
#get the video name
command = f"{app} {title} {link} {filename}"
name = sb.check_output(command,shell=True).decode().strip("\n")
if check_name(name):
print("[*] Song is already Downloaded\n[*] Want to download again: ")
x = input()
if x == "y" or x =="Y":
#store data in command.sh file and execute it
generate_bash()
os.system("/home/sohamch/command.sh")
else:
exit(1)
else:
generate_bash()
os.system("/home/sohamch/command.sh")
# with open('command.sh','w') as f:
# f.write(f"{app} {title} {filename} {link} | python check.py\n")
# f.write(f"{app} {path} {audiodownload} {link}\n")
# f.write(f"{app} {path} {thumbnaildownload} {link}\n")
# f.write(f"{app} {title} {filename} {link} >> yt-download_history.txt")