Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

78 righe
2.8 KiB

  1. import sys
  2. from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QPushButton, QLineEdit, QVBoxLayout, QFileDialog, QWidget
  3. import firebase_admin
  4. from firebase_admin import credentials, storage
  5. class VideoUploader(QMainWindow):
  6. def __init__(self):
  7. super(VideoUploader, self).__init__()
  8. # Initialize Firebase Admin SDK
  9. cred = credentials.Certificate("/home/knight/Python_Prog/UI/chatbot.json")
  10. firebase_admin.initialize_app(cred, {'storageBucket': 'chatbot-402717.appspot.com'})
  11. self.init_ui()
  12. def init_ui(self):
  13. self.setWindowTitle('Video Uploader')
  14. self.setGeometry(100, 100, 400, 200)
  15. self.title_label = QLabel('Video Title:', self)
  16. self.title_input = QLineEdit(self)
  17. self.browse_button = QPushButton('Browse', self)
  18. self.upload_button = QPushButton('Upload', self)
  19. self.status_label = QLabel(self)
  20. layout = QVBoxLayout()
  21. layout.addWidget(self.title_label)
  22. layout.addWidget(self.title_input)
  23. layout.addWidget(self.browse_button)
  24. layout.addWidget(self.upload_button)
  25. layout.addWidget(self.status_label)
  26. widget = QWidget()
  27. widget.setLayout(layout)
  28. self.setCentralWidget(widget)
  29. self.browse_button.clicked.connect(self.browse_video)
  30. self.upload_button.clicked.connect(self.upload_video)
  31. def browse_video(self):
  32. options = QFileDialog.Options()
  33. options |= QFileDialog.DontUseNativeDialog
  34. file_name, _ = QFileDialog.getOpenFileName(self, "Choose Video File", "", "Video Files (*.mp4 *.mkv *.avi);;All Files (*)", options=options)
  35. if file_name:
  36. self.video_path = file_name
  37. self.status_label.setText(f'Selected video: {file_name}')
  38. def upload_video(self):
  39. try:
  40. title = self.title_input.text()
  41. if not title:
  42. self.status_label.setText('Please enter a title for the video.')
  43. return
  44. if not hasattr(self, 'video_path'):
  45. self.status_label.setText('Please select a video to upload.')
  46. return
  47. # Get a reference to the Firebase Storage bucket
  48. bucket = storage.bucket()
  49. # Upload the video to Firebase Storage within the specified title folder
  50. blob = bucket.blob(f'{title}/{title}.mp4')
  51. blob.upload_from_filename(self.video_path)
  52. print("Video path: ", self.video_path)
  53. self.status_label.setText('Video uploaded successfully.')
  54. except Exception as e:
  55. self.status_label.setText(f'Error: {str(e)}')
  56. print (e)
  57. if __name__ == '__main__':
  58. app = QApplication(sys.argv)
  59. window = VideoUploader()
  60. window.show()
  61. sys.exit(app.exec_())