Advertisement
misiekii123

MovieProjection

Dec 22nd, 2023 (edited)
916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | Movies | 0 0
  1. import vlc
  2. import time
  3. import schedule
  4. import threading
  5. import os
  6. import requests
  7.  
  8. # Adres IP i token Twojego urządzenia SmartThings
  9. smartthings_ip = "192.168.1.2"  # Zastąp własnym adresem IP
  10. smartthings_token = "YOUR_ACCESS_TOKEN"  # Zastąp własnym tokenem dostępu
  11.  
  12. def playMovie():
  13.     # Przełącz źródło na Smart TV przed rozpoczęciem filmu
  14.     switch_source("your_tv_device_id", "your_tv_input_source_id")
  15.  
  16.     instance = vlc.Instance()
  17.     player = instance.media_player_new()
  18.     media = instance.media_new(sciezka)
  19.     player.set_media(media)
  20.     player.set_fullscreen(True)
  21.  
  22.     # Rozpoczęcie odtwarzania
  23.     player.play()
  24.  
  25.     # Oczekiwanie na zakończenie odtwarzania
  26.     while not player.get_state() == vlc.State.Ended:
  27.         time.sleep(1)
  28.  
  29.     # Twój kod do wykonania po zakończeniu odtwarzania
  30.     print("Film zakończony.")
  31.  
  32.     # Zatrzymaj odtwarzacz po zakończeniu filmu
  33.     player.stop()
  34.  
  35.     # Przełącz źródło na Smart TV po zakończeniu filmu
  36.     switch_source("your_tv_device_id", "your_tv_default_source_id")
  37.  
  38. def switch_source(device_id, source_id):
  39.     url = f"http://{smartthings_ip}:39500/devices/{device_id}/commands"
  40.     headers = {
  41.         "Authorization": f"Bearer {smartthings_token}",
  42.         "Content-Type": "application/json",
  43.     }
  44.     payload = {
  45.         "commands": [
  46.             {
  47.                 "capability": "switchLevel",
  48.                 "command": "setLevel",
  49.                 "arguments": [source_id],
  50.             }
  51.         ]
  52.     }
  53.     response = requests.post(url, headers=headers, json=payload)
  54.     if response.status_code == 200:
  55.         print("Źródło przełączone pomyślnie.")
  56.     else:
  57.         print(f"Błąd podczas przełączania źródła. Kod błędu: {response.status_code}")
  58.  
  59. def schedule_play():
  60.     print(f"Odtwarzanie filmu o godzinie: {time_to_start}")
  61.     schedule.every().day.at(time_to_start).do(playMovie)
  62.  
  63. print('''Wybierz opcję:
  64.      1. 9.30
  65.      2. 11.00
  66.      3. Inne\n''')
  67. x = int(input())
  68.  
  69. if x == 1:
  70.     time_to_start = "09:30"
  71.     sciezka = input("Podaj ścieżkę filmu: ")
  72.     os.system("cls")
  73. elif x == 2:
  74.     time_to_start = "11:00"
  75.     sciezka = input("Podaj ścieżkę filmu: ")
  76.     os.system("cls")
  77. else:
  78.     time_to_start = input("Podaj godzinę rozpoczęcia: ")
  79.     sciezka = input("Podaj ścieżkę filmu: ")
  80.     os.system("cls")
  81.  
  82.  
  83. # Zarejestruj zadanie w harmonogramie
  84. schedule_play()
  85.  
  86. def run_schedule():
  87.     while True:
  88.         schedule.run_pending()
  89.         time.sleep(1)
  90.  
  91. # Uruchom harmonogram w osobnym wątku
  92. schedule_thread = threading.Thread(target=run_schedule)
  93. schedule_thread.start()
  94.  
  95. # Czekaj na zakończenie wątku harmonogramu
  96. schedule_thread.join()
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement