Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- ##############################################
- # Usage: python seu_script.py "URL_DO_VIDEO" #
- ##############################################
- from os import system
- from sys import exit, argv
- class YoutubeDownloader:
- def __init__(self, url):
- self.url = url
- @staticmethod
- def execute_with_sudo(command):
- system(f'sudo bash -c "{command}"')
- @staticmethod
- def is_youtube_dl_installed():
- return system("which youtube-dl") == 0
- @staticmethod
- def install_youtube_dl():
- YoutubeDownloader.execute_with_sudo("wget https://yt-dl.org/latest/youtube-dl -O /usr/local/bin/youtube-dl")
- YoutubeDownloader.execute_with_sudo("chmod a+rx /usr/local/bin/youtube-dl")
- def download_video(self):
- if not self.url:
- print("Por favor, forneça o URL do vídeo do YouTube.")
- exit(1)
- system(f'youtube-dl "{self.url}"')
- def main():
- if len(argv) < 2:
- print("Uso: python seu_script.py URL_DO_VIDEO")
- exit(1)
- url_do_video = argv[1]
- youtube_downloader = YoutubeDownloader(url_do_video)
- if not youtube_downloader.is_youtube_dl_installed():
- print("O youtube-dl não está instalado. Tentando instalá-lo...")
- youtube_downloader.install_youtube_dl()
- youtube_downloader.download_video()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement