Skip to content

Commit

Permalink
Add support for BubbleUPNP (#428)
Browse files Browse the repository at this point in the history
* Add bubbleupnp media controller

* Fix argument names

* Linter fixes
  • Loading branch information
Eerovil authored Dec 10, 2020
1 parent 00027dc commit 81983e1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/bubbleupnp_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Example on how to use the BubbleUPNP Controller
"""
import logging
import sys
from time import sleep

import pychromecast
from pychromecast.controllers.bubbleupnp import BubbleUPNPController


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

URL = "https://c3.toivon.net/toivon/toivon_3?mp=/stream"

logging.basicConfig(level=logging.DEBUG)

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

cast = list(chromecasts)[0]
# Start socket client's worker thread and wait for initial status update
cast.wait()

bubbleupnp = BubbleUPNPController()
cast.register_handler(bubbleupnp)
bubbleupnp.launch()
bubbleupnp.play_media(URL, "audio/mp3", stream_type="LIVE")
cast.wait()

sleep(10)
1 change: 1 addition & 0 deletions pychromecast/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
APP_HOME_ASSISTANT = "B12CE3CA"
APP_SUPLA = "A41B766D"
APP_YLEAREENA = "A9BCCB7C"
APP_BUBBLEUPNP = "3927FA74"


def get_possible_app_ids():
Expand Down
20 changes: 20 additions & 0 deletions pychromecast/controllers/bubbleupnp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Simple Controller to use BubbleUPNP as a media controller.
"""

from ..config import APP_BUBBLEUPNP
from .media import MediaController


class BubbleUPNPController(MediaController):
""" Controller to interact with BubbleUPNP app namespace. """

# pylint: disable=useless-super-delegation
def __init__(self):
super(BubbleUPNPController, self).__init__()
self.app_id = APP_BUBBLEUPNP
self.supporting_app_id = APP_BUBBLEUPNP

def quick_play(self, media_id=None, media_type="video/mp4", **kwargs):
""" Quick Play """
self.play_media(media_id, media_type, **kwargs)
9 changes: 9 additions & 0 deletions pychromecast/quick_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .controllers.youtube import YouTubeController
from .controllers.supla import SuplaController
from .controllers.yleareena import YleAreenaController
from .controllers.bubbleupnp import BubbleUPNPController


def quick_play(cast, app_name, data):
Expand All @@ -24,6 +25,8 @@ def quick_play(cast, app_name, data):
media_type: string
Type of the media identified by `media_id`. e.g. "program" if the media is a
program name instead of a direct item id.
When using a regular media controller (e.g. BubbleUPNP) this should be the
content_type ('audio/mp3')
enqueue: boolean
Enqueue the media to the current playlist, if possible.
index: string
Expand All @@ -40,6 +43,10 @@ def quick_play(cast, app_name, data):
Supla-specific:
is_live: boolean
Whether the media is a livestream
Media controller (BubbleUPNP)-specific:
stream_type: string
"BUFFERED" or "LIVE"
"""

if app_name == "youtube":
Expand All @@ -48,6 +55,8 @@ def quick_play(cast, app_name, data):
controller = SuplaController()
elif app_name == "yleareena":
controller = YleAreenaController()
elif app_name == "bubbleupnp":
controller = BubbleUPNPController()
else:
raise NotImplementedError()

Expand Down

0 comments on commit 81983e1

Please sign in to comment.