Skip to content

Commit

Permalink
fix: Allow use of info cmds on idle/inactive cc (#345)
Browse files Browse the repository at this point in the history
* Black and flake doesnt agree on linebreaks

..before binary operators

* Allow use of info cmds on idle/inactive cc

* Dummy commit
  • Loading branch information
theychx authored May 19, 2021
1 parent 0a6ec03 commit cb9cf00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
23 changes: 16 additions & 7 deletions catt/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ def setup_cast(device_desc, video_url=None, controller=None, ytdl_options=None,
elif prep == "app" and stream and not stream.is_local_file:
app = get_app(stream.extractor, cast_type, show_warning=True)

elif prep in ["control", "info"]:
if app_id and app_id != BACKDROP_APP_ID:
app = get_app(app_id, cast_type)
else:
elif prep == "control":
if not app_id or app_id == BACKDROP_APP_ID:
raise CastError("Chromecast is inactive")
app = get_app(app_id, cast_type)

else:
app = get_app("default")
Expand Down Expand Up @@ -317,8 +316,13 @@ def media_info(self):

@property
def cast_info(self):
cinfo = {"volume_level": str(int(round(self._cast.status.volume_level, 2) * 100))}

if self._is_idle:
return cinfo

cinfo.update(self.media_info)
status = self._cast.media_controller.status
cinfo = self.media_info

if self._is_seekable:
duration, current = status.duration, status.current_time
Expand All @@ -329,7 +333,6 @@ def cast_info(self):
if self._is_audiovideo:
cinfo.update({"player_state": status.player_state})

cinfo.update({"volume_level": str(int(round(self._cast.status.volume_level, 2) * 100))})
return cinfo

@property
Expand Down Expand Up @@ -359,7 +362,13 @@ def _is_idle(self):
status = self._cast.media_controller.status
# Dashcast (and maybe others) does not support the google media namespace, and thus
# "player_state" will be "UNKNOWN" for such apps, regardless of state.
return status.player_state in ["UNKNOWN", "IDLE"] and self._supports_google_media_namespace

app_id = self._cast.app_id
return (
not app_id
or app_id == BACKDROP_APP_ID
or (status.player_state in ["UNKNOWN", "IDLE"] and self._supports_google_media_namespace)
)

def volume(self, level: float) -> None:
self._cast.set_volume(level)
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ universal = 1

[flake8]
exclude = docs
ignore = E501
ignore = E501,W503
import-order-style = smarkets

[bdist_wheel]
Expand All @@ -28,4 +28,3 @@ skip = migrations,node_modules
version_variable = catt/__init__.py:__version__

[bumpversion:file:catt/__init__.py]

0 comments on commit cb9cf00

Please sign in to comment.