Skip to content

Commit

Permalink
update pycrhomecast to 10.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
guirem committed Dec 1, 2021
1 parent b3cdbfc commit 4361239
Show file tree
Hide file tree
Showing 37 changed files with 599 additions and 384 deletions.
12 changes: 0 additions & 12 deletions resources/pychromecast/.travis.yml

This file was deleted.

Empty file removed resources/pychromecast/__init__.py
Empty file.
8 changes: 2 additions & 6 deletions resources/pychromecast/examples/bbciplayer_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,13 @@
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = chromecasts[0]
# Start socket client's worker thread and wait for initial status update
cast.wait()
print(
'Found chromecast with name "{}", attempting to play "{}"'.format(
args.cast, args.media_id
)
)
print(f'Found chromecast with name "{args.cast}", attempting to play "{args.media_id}"')

quick_play.quick_play(cast, app_name, app_data)

Expand Down
8 changes: 2 additions & 6 deletions resources/pychromecast/examples/bbcsounds_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,13 @@
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = chromecasts[0]
# Start socket client's worker thread and wait for initial status update
cast.wait()
print(
'Found chromecast with name "{}", attempting to play "{}"'.format(
args.cast, args.media_id
)
)
print(f'Found chromecast with name "{args.cast}", attempting to play "{args.media_id}"')

quick_play.quick_play(cast, app_name, app_data)

Expand Down
8 changes: 2 additions & 6 deletions resources/pychromecast/examples/bubbleupnp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,13 @@
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = list(chromecasts)[0]
# Start socket client's worker thread and wait for initial status update
cast.wait()
print(
'Found chromecast with name "{}", attempting to play "{}"'.format(
args.cast, args.url
)
)
print(f'Found chromecast with name "{args.cast}", attempting to play "{args.url}"')
bubbleupnp = BubbleUPNPController()
cast.register_handler(bubbleupnp)
bubbleupnp.launch()
Expand Down
2 changes: 1 addition & 1 deletion resources/pychromecast/examples/custom_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def callback(chromecast):
if t > 50:
break
else:
print("=> Waiting for discovery of cast '{}'...".format(args.cast))
print(f"=> Waiting for discovery of cast '{args.cast}'...")
time.sleep(1)

print("All done, shutting down discovery")
Expand Down
6 changes: 3 additions & 3 deletions resources/pychromecast/examples/dashcast_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import zeroconf

import pychromecast
import pychromecast.controllers.dashcast as dashcast
from pychromecast.controllers import dashcast

# Change to the friendly name of your Chromecast
CAST_NAME = "Living Room"
Expand Down Expand Up @@ -43,7 +43,7 @@
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = chromecasts[0]
Expand All @@ -54,7 +54,7 @@
cast.register_handler(d)

print()
print(cast.device)
print(cast.cast_info)
time.sleep(1)
print()
print(cast.status)
Expand Down
8 changes: 4 additions & 4 deletions resources/pychromecast/examples/discovery_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ def list_devices():
"""Print a list of known devices."""
print("Currently known cast devices:")
for uuid, service in browser.services.items():
print(" {} {}".format(uuid, service))
print(f" {uuid} {service}")


class MyCastListener(pychromecast.discovery.AbstractCastListener):
"""Listener for discovering chromecasts."""

def add_cast(self, uuid, _service):
"""Called when a new cast has beeen discovered."""
print("Found cast device with UUID {}".format(uuid))
print(f"Found cast device with UUID {uuid}")
list_devices()

def remove_cast(self, uuid, _service, cast_info):
"""Called when a cast has beeen lost (MDNS info expired or host down)."""
print("Lost cast device with UUID {} {}".format(uuid, cast_info))
print(f"Lost cast device with UUID {uuid} {cast_info}")
list_devices()

def update_cast(self, uuid, _service):
"""Called when a cast has beeen updated (MDNS info renewed or changed)."""
print("Updated cast device with UUID {}".format(uuid))
print(f"Updated cast device with UUID {uuid}")
list_devices()


Expand Down
4 changes: 1 addition & 3 deletions resources/pychromecast/examples/get_chromecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,5 @@
print("Found cast devices:")
for cast in casts:
print(
' "{}" on mDNS service {} with UUID:{}'.format(
cast.name, cast._services, cast.uuid # pylint: disable=protected-access
)
f' "{cast.name}" on mDNS/host service {cast.cast_info.services} with UUID:{cast.uuid}' # pylint: disable=protected-access
)
74 changes: 74 additions & 0 deletions resources/pychromecast/examples/homeassistant_media_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Example on how to use the Home Assistant Media app to play an URL.
"""
# pylint: disable=invalid-name

import argparse
import logging
import sys
from time import sleep

import zeroconf

import pychromecast
from pychromecast import quick_play


# Change to the friendly name of your Chromecast
CAST_NAME = "Kitchen speaker"

# Change to an audio or video url
MEDIA_URL = (
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
)

parser = argparse.ArgumentParser(
description="Example on how to use the Home Asssitant Media Controller to play an URL."
)
parser.add_argument(
"--cast", help='Name of cast device (default: "%(default)s")', default=CAST_NAME
)
parser.add_argument(
"--known-host",
help="Add known host (IP), can be used multiple times",
action="append",
)
parser.add_argument("--show-debug", help="Enable debug log", action="store_true")
parser.add_argument(
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true"
)
parser.add_argument(
"--url", help='Media url (default: "%(default)s")', default=MEDIA_URL
)
args = parser.parse_args()

app_name = "homeassistant_media"
app_data = {
"media_id": args.url,
}

if args.show_debug:
logging.basicConfig(level=logging.DEBUG)
if args.show_zeroconf_debug:
print("Zeroconf version: " + zeroconf.__version__)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)

# pylint: disable=unbalanced-tuple-unpacking
chromecasts, browser = pychromecast.get_listed_chromecasts(
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = list(chromecasts)[0]
# Start socket client's worker thread and wait for initial status update
cast.wait()
print(f'Found chromecast with name "{args.cast}", attempting to play "{args.url}"')

quick_play.quick_play(cast, app_name, app_data)

sleep(10)

browser.stop_discovery()
4 changes: 2 additions & 2 deletions resources/pychromecast/examples/media_enqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = chromecasts[0]

# Start socket client's worker thread and wait for initial status update
cast.wait()
print('Found chromecast with name "{}"'.format(args.cast))
print(f'Found chromecast with name "{args.cast}"')

cast.media_controller.play_media(MEDIA_URLS[0], "audio/mp3")

Expand Down
8 changes: 2 additions & 6 deletions resources/pychromecast/examples/media_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,13 @@
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = chromecasts[0]
# Start socket client's worker thread and wait for initial status update
cast.wait()
print(
'Found chromecast with name "{}", attempting to play "{}"'.format(
args.cast, args.url
)
)
print(f'Found chromecast with name "{args.cast}", attempting to play "{args.url}"')
cast.media_controller.play_media(args.url, "audio/mp3")

# Wait for player_state PLAYING
Expand Down
6 changes: 3 additions & 3 deletions resources/pychromecast/examples/media_example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = chromecasts[0]
Expand All @@ -65,7 +65,7 @@
cast.wait()

print()
print(cast.device)
print(cast.cast_info)
time.sleep(1)
print()
print(cast.status)
Expand All @@ -84,7 +84,7 @@
time.sleep(0.1)
t = t - 0.1

print('Playing media "{}"'.format(args.url))
print(f'Playing media "{args.url}"')
cast.play_media(args.url, "video/mp4")

t = 0
Expand Down
8 changes: 4 additions & 4 deletions resources/pychromecast/examples/multizone_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ class MyMultiZoneControllerListener(MultiZoneControllerListener):
"""MultiZoneControllerListener"""

def multizone_member_added(self, group_uuid):
print("New member: {}".format(group_uuid))
print(f"New member: {group_uuid}")

def multizone_member_removed(self, group_uuid):
print("Removed member: {}".format(group_uuid))
print(f"Removed member: {group_uuid}")

def multizone_status_received(self):
print("Members: {}".format(mz.members))
print(f"Members: {mz.members}")


chromecasts, browser = pychromecast.get_listed_chromecasts(
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = chromecasts[0]
Expand Down
2 changes: 1 addition & 1 deletion resources/pychromecast/examples/simple_listener_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def new_media_status(self, status):
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

chromecast = chromecasts[0]
Expand Down
4 changes: 2 additions & 2 deletions resources/pychromecast/examples/supla_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
PROGRAM = "aamulypsy"


result = requests.get("https://www.supla.fi/ohjelmat/{}".format(PROGRAM))
result = requests.get(f"https://www.supla.fi/ohjelmat/{PROGRAM}")
soup = BeautifulSoup(result.content)
MEDIA_ID = soup.select('a[title*="Koko Shitti"]')[0]["href"].split("/")[-1]
print(MEDIA_ID)
Expand All @@ -33,7 +33,7 @@

chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[CAST_NAME])
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(CAST_NAME))
print(f'No chromecast with name "{CAST_NAME}" discovered')
sys.exit(1)

cast = chromecasts[0]
Expand Down
4 changes: 2 additions & 2 deletions resources/pychromecast/examples/yleareena_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_kaltura_id(program_id):
httpclient = HttpClient(None)
stream_filters = StreamFilters()

url = "https://areena.yle.fi/{}".format(program_id)
url = f"https://areena.yle.fi/{program_id}"

extractor = extractor_factory(url, stream_filters, language_chooser, httpclient)
pid = extractor.program_id_from_url(url)
Expand All @@ -77,7 +77,7 @@ def get_kaltura_id(program_id):
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = chromecasts[0]
Expand Down
2 changes: 1 addition & 1 deletion resources/pychromecast/examples/youtube_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
friendly_names=[args.cast], known_hosts=args.known_host
)
if not chromecasts:
print('No chromecast with name "{}" discovered'.format(args.cast))
print(f'No chromecast with name "{args.cast}" discovered')
sys.exit(1)

cast = chromecasts[0]
Expand Down
Loading

0 comments on commit 4361239

Please sign in to comment.