elif key == 'y' or key == 'yes': break url = 'https://www.youtube.com' + results['vidoeos'][0]['link'] print('Accessing Youtube URL...') video = YouTube(url, on_progress_callback=on_progress) title = video.title description = video.description stream = video.streams.get_highest_resolution() file_size = round(stream.filesize / 1000000, 2) print('Downloading video... [' + str(file_size) + ' MB]') # change file paths according to your system stream.download(filename=title) file_path = os.getcwd() + title + '.mp4' results.append([title, file_path, description]) print('\n') csv_file_name = 'yt_info.csv' with open(csv_file_name, 'w', newline='') as file: writer = csv.writer(file) writer.writerow(['Video Title', 'Video Location', 'Video Description']) writer.writerows(results) print('Video data exported to ' + csv_file_name + '.') print('Done.') else: print('Invalid input. Check commands.')