Advertisement
egor230

Скачать с youtube

May 14th, 2024
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | Source Code | 0 0
  1. import subprocess, pyperclip, tqdm, sys
  2. import pytube.request
  3. from pytube.cli import on_progress # Импорт стандартного обработчика прогресса
  4. from pytube import YouTube, Stream
  5. # Вставьте ссылку на видео
  6. video_url = pyperclip.paste()
  7.  
  8. video_url ="https://www.youtube.com/watch?v=KCCoy_BTSuY"
  9. output_path = "/home/egor/Рабочий стол/%(title)s.%(ext)s"
  10.  
  11. # # Строим команду без использования .format(), передавая аргументы отдельно
  12. # bash_command = 'yt-dlp -f "bestvideo+bestaudio/best" -o "{}" "{}"'.format(output_path, video_url)
  13. #
  14. # # Формируем команду для запуска в gnome-terminal
  15. # show_list_id = '''gnome-terminal -- bash -c '{}; echo "Скачивание лучшего качества видео завершено."; sleep 3; exit;' '''.format(bash_command)
  16. #
  17. # subprocess.run(['bash', '-c', show_list_id])
  18.  
  19. # Создаем объект YouTube
  20. yt = YouTube(video_url)
  21.  
  22. # Выбираем самое высокое доступное качество видео
  23. video = yt.streams.get_highest_resolution()
  24.  
  25. pytube.request.default_range_size = 9437184
  26. # Функция прогресса, которая обновляет статус-бар
  27. def progress_function(chunk, file_handle, bytes_remaining):
  28.   global filesize
  29.   contentsize = video.filesize
  30.   size = contentsize - bytes_remaining
  31.   print('\r' + '[Download progress]:[%s%s]%.2f%%;' % (
  32.     '█' * int(size * 20 / contentsize), ' ' * (20 - int(size * 20 / contentsize)), float(size / contentsize * 100)), end='')
  33.  
  34. # Устанавливаем функцию обратного вызова на объекте YouTube
  35. yt.register_on_progress_callback(progress_function)
  36.  
  37. # Скачиваем видео
  38. video.download('/home/egor/Рабочий стол/')
  39.  
  40. show_list_id = '''#!/bin/bash
  41. gnome-terminal -- bash -c '
  42. echo "Ok"
  43. sleep 3
  44. exit
  45. exec bash'
  46. ''' # показать список устройств в терминале
  47. subprocess.run(['bash', '-c', show_list_id])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement