Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess, pyperclip, tqdm, sys
- import pytube.request
- from pytube.cli import on_progress # Импорт стандартного обработчика прогресса
- from pytube import YouTube, Stream
- # Вставьте ссылку на видео
- video_url = pyperclip.paste()
- video_url ="https://www.youtube.com/watch?v=KCCoy_BTSuY"
- output_path = "/home/egor/Рабочий стол/%(title)s.%(ext)s"
- # # Строим команду без использования .format(), передавая аргументы отдельно
- # bash_command = 'yt-dlp -f "bestvideo+bestaudio/best" -o "{}" "{}"'.format(output_path, video_url)
- #
- # # Формируем команду для запуска в gnome-terminal
- # show_list_id = '''gnome-terminal -- bash -c '{}; echo "Скачивание лучшего качества видео завершено."; sleep 3; exit;' '''.format(bash_command)
- #
- # subprocess.run(['bash', '-c', show_list_id])
- # Создаем объект YouTube
- yt = YouTube(video_url)
- # Выбираем самое высокое доступное качество видео
- video = yt.streams.get_highest_resolution()
- pytube.request.default_range_size = 9437184
- # Функция прогресса, которая обновляет статус-бар
- def progress_function(chunk, file_handle, bytes_remaining):
- global filesize
- contentsize = video.filesize
- size = contentsize - bytes_remaining
- print('\r' + '[Download progress]:[%s%s]%.2f%%;' % (
- '█' * int(size * 20 / contentsize), ' ' * (20 - int(size * 20 / contentsize)), float(size / contentsize * 100)), end='')
- # Устанавливаем функцию обратного вызова на объекте YouTube
- yt.register_on_progress_callback(progress_function)
- # Скачиваем видео
- video.download('/home/egor/Рабочий стол/')
- show_list_id = '''#!/bin/bash
- gnome-terminal -- bash -c '
- echo "Ok"
- sleep 3
- exit
- exec bash'
- ''' # показать список устройств в терминале
- subprocess.run(['bash', '-c', show_list_id])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement