Guest User

Untitled

a guest
Apr 2nd, 2025
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #!/usr/bin/python3
  2. from yt_dlp import YoutubeDL
  3. from gradio_client import Client, handle_file
  4. import sys
  5. import os
  6.  
  7. class MyLogger:
  8. def debug(self, msg):
  9. # For compatibility with youtube-dl, both debug and info are passed into debug
  10. # You can distinguish them by the prefix '[debug] '
  11. if msg.startswith('[debug] '):
  12. pass
  13. else:
  14. self.info(msg)
  15.  
  16. def info(self, msg):
  17. pass
  18.  
  19. def warning(self, msg):
  20. pass
  21.  
  22. def error(self, msg):
  23. print(msg)
  24.  
  25. def my_hook(d):
  26. if d['status'] == 'finished':
  27. global status_dict
  28. status_dict = d
  29.  
  30. def help_menu():
  31. print("No options yet lol get rekt")
  32.  
  33. def main():
  34. if len(sys.argv) == 1:
  35. print("Usage: command URL")
  36. print("For help: command -h")
  37. return
  38. if sys.argv[1] == "-h":
  39. help_menu()
  40. return
  41.  
  42. URL = sys.argv[1]
  43. ytdl_opts = {
  44. 'format': 'worst*[vcodec=none][acodec!=none]',
  45. 'postprocessor_hooks': [my_hook],
  46. 'logger': MyLogger()
  47. }
  48. out_file = ""
  49. with YoutubeDL(ytdl_opts) as ydl:
  50. result = ydl.download(URL)
  51. info_dict = ydl.extract_info(URL, download=False)
  52. out_file = ydl.prepare_filename(info_dict)
  53. filename, file_extension = os.path.splitext(out_file)
  54. os.rename(out_file, 'tmp' + file_extension)
  55. client = Client("Nick088/Fast-Subtitle-Maker")
  56. result = client.predict(
  57. input_file=handle_file('tmp' + file_extension),
  58. prompt="",
  59. language="en",
  60. auto_detect_language=True,
  61. model="whisper-large-v3-turbo",
  62. include_video=False,
  63. font_selection="Arial",
  64. font_file=None,
  65. font_color="#FFFFFF",
  66. font_size=24,
  67. outline_thickness=1,
  68. outline_color="#000000",
  69. api_name="/generate_subtitles"
  70. )
  71. out_filename, out_fileextension = os.path.splitext(result[0])
  72. os.replace(result[0], filename + out_fileextension)
  73. os.remove("tmp" + file_extension)
  74.  
  75. if __name__ == "__main__":
  76. main()
Advertisement
Add Comment
Please, Sign In to add comment