Advertisement
Rnery

new class

Nov 1st, 2023 (edited)
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | Source Code | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. ##############################################
  5. # Usage: python seu_script.py "URL_DO_VIDEO" #
  6. ##############################################
  7.  
  8. from os import system
  9. from sys import exit, argv
  10.  
  11. class YoutubeDownloader:
  12.     def __init__(self, url):
  13.         self.url = url
  14.  
  15.     @staticmethod
  16.     def execute_with_sudo(command):
  17.         system(f'sudo bash -c "{command}"')
  18.  
  19.     @staticmethod
  20.     def is_youtube_dl_installed():
  21.         return system("which youtube-dl") == 0
  22.  
  23.     @staticmethod
  24.     def install_youtube_dl():
  25.         YoutubeDownloader.execute_with_sudo("wget https://yt-dl.org/latest/youtube-dl -O /usr/local/bin/youtube-dl")
  26.         YoutubeDownloader.execute_with_sudo("chmod a+rx /usr/local/bin/youtube-dl")
  27.  
  28.     def download_video(self):
  29.         if not self.url:
  30.             print("Por favor, forneça o URL do vídeo do YouTube.")
  31.             exit(1)
  32.         system(f'youtube-dl "{self.url}"')
  33.  
  34. def main():
  35.     if len(argv) < 2:
  36.         print("Uso: python seu_script.py URL_DO_VIDEO")
  37.         exit(1)
  38.  
  39.     url_do_video = argv[1]
  40.     youtube_downloader = YoutubeDownloader(url_do_video)
  41.    
  42.     if not youtube_downloader.is_youtube_dl_installed():
  43.         print("O youtube-dl não está instalado. Tentando instalá-lo...")
  44.         youtube_downloader.install_youtube_dl()
  45.    
  46.     youtube_downloader.download_video()
  47.  
  48. if __name__ == "__main__":
  49.     main()
  50.  
Tags: python python3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement