Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified the code #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions ytdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def link_snatcher(url):

for m in mat:
new_m = m.replace('&', '&')
work_m = 'https://youtube.com/' + new_m
work_m = f'https://youtube.com/{new_m}'
# print(work_m)
if work_m not in our_links:
our_links.append(work_m)
Expand All @@ -80,7 +80,7 @@ def link_snatcher(url):
user_res = str(input()).lower()


print('...You choosed ' + user_res + ' resolution\n.')
print(f'...You choosed {user_res}' + ' resolution\n.')

our_links = link_snatcher(url)

Expand All @@ -103,7 +103,7 @@ def link_snatcher(url):
for name in files:
pathh = os.path.join(root, name)


if os.path.getsize(pathh) < 1:
os.remove(pathh)
else:
Expand All @@ -119,28 +119,27 @@ def link_snatcher(url):
try:
yt = YouTube(link)
main_title = yt.title
main_title = main_title + '.mp4'
main_title = f'{main_title}.mp4'
main_title = main_title.replace('|', '')

except:
print('connection problem..unable to fetch video info')
break


if main_title not in x:


if user_res == '360p' or user_res == '720p':
vid = yt.streams.filter(progressive=True, file_extension='mp4', res=user_res).first()
print('Downloading. . . ' + vid.default_filename + ' and its file size -> ' + str(round(vid.filesize / (1024 * 1024), 2)) + ' MB.')
vid.download(SAVEPATH)
print('Video Downloaded')
else:
print('something is wrong.. please rerun the script')
if main_title in x:
print(f'\n skipping "{main_title}" video \n')


elif user_res in {'360p', '720p'}:
vid = yt.streams.filter(progressive=True, file_extension='mp4', res=user_res).first()
print(
f'Downloading. . . {vid.default_filename} and its file size -> {str(round(vid.filesize / (1024 * 1024), 2))} MB.'
)
vid.download(SAVEPATH)
print('Video Downloaded')
else:
print(f'\n skipping "{main_title}" video \n')
print('something is wrong.. please rerun the script')


print(' downloading finished')
Expand Down