1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
"""
Example on how to use the Supla Controller
"""
# pylint: disable=invalid-name
import logging
from time import sleep
import sys
import requests
from bs4 import BeautifulSoup
import pychromecast
from pychromecast import quick_play
# Enable deprecation warnings etc.
if not sys.warnoptions:
import warnings
warnings.simplefilter("default")
# Change to the name of your Chromecast
CAST_NAME = "Kitchen Speaker"
# Change to the video id of the YouTube video
# video id is the last part of the url http://youtube.com/watch?v=video_id
PROGRAM = "aamulypsy"
result = requests.get(f"https://www.supla.fi/ohjelmat/{PROGRAM}", timeout=10)
soup = BeautifulSoup(result.content)
MEDIA_ID = soup.select('a[title*="Koko Shitti"]')[0]["href"].split("/")[-1] # type: ignore[union-attr]
print(MEDIA_ID)
logging.basicConfig(level=logging.DEBUG)
chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[CAST_NAME])
if not chromecasts:
print(f'No chromecast with name "{CAST_NAME}" discovered')
sys.exit(1)
cast = chromecasts[0]
# Start socket client's worker thread and wait for initial status update
cast.wait()
app_name = "supla"
app_data = {
"media_id": MEDIA_ID,
}
quick_play.quick_play(cast, app_name, app_data)
sleep(10)
|