Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import vlc
- import time
- import schedule
- import threading
- import os
- import requests
- # Adres IP i token Twojego urządzenia SmartThings
- smartthings_ip = "192.168.1.2" # Zastąp własnym adresem IP
- smartthings_token = "YOUR_ACCESS_TOKEN" # Zastąp własnym tokenem dostępu
- def playMovie():
- # Przełącz źródło na Smart TV przed rozpoczęciem filmu
- switch_source("your_tv_device_id", "your_tv_input_source_id")
- instance = vlc.Instance()
- player = instance.media_player_new()
- media = instance.media_new(sciezka)
- player.set_media(media)
- player.set_fullscreen(True)
- # Rozpoczęcie odtwarzania
- player.play()
- # Oczekiwanie na zakończenie odtwarzania
- while not player.get_state() == vlc.State.Ended:
- time.sleep(1)
- # Twój kod do wykonania po zakończeniu odtwarzania
- print("Film zakończony.")
- # Zatrzymaj odtwarzacz po zakończeniu filmu
- player.stop()
- # Przełącz źródło na Smart TV po zakończeniu filmu
- switch_source("your_tv_device_id", "your_tv_default_source_id")
- def switch_source(device_id, source_id):
- url = f"http://{smartthings_ip}:39500/devices/{device_id}/commands"
- headers = {
- "Authorization": f"Bearer {smartthings_token}",
- "Content-Type": "application/json",
- }
- payload = {
- "commands": [
- {
- "capability": "switchLevel",
- "command": "setLevel",
- "arguments": [source_id],
- }
- ]
- }
- response = requests.post(url, headers=headers, json=payload)
- if response.status_code == 200:
- print("Źródło przełączone pomyślnie.")
- else:
- print(f"Błąd podczas przełączania źródła. Kod błędu: {response.status_code}")
- def schedule_play():
- print(f"Odtwarzanie filmu o godzinie: {time_to_start}")
- schedule.every().day.at(time_to_start).do(playMovie)
- print('''Wybierz opcję:
- 1. 9.30
- 2. 11.00
- 3. Inne\n''')
- x = int(input())
- if x == 1:
- time_to_start = "09:30"
- sciezka = input("Podaj ścieżkę filmu: ")
- os.system("cls")
- elif x == 2:
- time_to_start = "11:00"
- sciezka = input("Podaj ścieżkę filmu: ")
- os.system("cls")
- else:
- time_to_start = input("Podaj godzinę rozpoczęcia: ")
- sciezka = input("Podaj ścieżkę filmu: ")
- os.system("cls")
- # Zarejestruj zadanie w harmonogramie
- schedule_play()
- def run_schedule():
- while True:
- schedule.run_pending()
- time.sleep(1)
- # Uruchom harmonogram w osobnym wątku
- schedule_thread = threading.Thread(target=run_schedule)
- schedule_thread.start()
- # Czekaj na zakończenie wątku harmonogramu
- schedule_thread.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement