Skip to content

Commit

Permalink
Very late spring cleaning (#126)
Browse files Browse the repository at this point in the history
* Fix cosmetic stuff

* Make code more concise

* Make slight change to StreamInfo._is_direct_link

..so the clause is only truthy when the value of the "direct" key is "True".
  • Loading branch information
theychx committed Sep 9, 2018
1 parent cdbf75b commit 64135f5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions catt/cli.py
Expand Up @@ -97,7 +97,7 @@ def cli(ctx, delete_cache, device):
ctx.obj["device"] = device


@cli.command(short_help="Write the name of default Chromecast " "device to config file.")
@cli.command(short_help="Write the name of default Chromecast device to config file.")
@click.pass_obj
def write_config(settings):
if settings.get("device"):
Expand All @@ -109,7 +109,7 @@ def write_config(settings):


def hunt_subtitle(video):
""""Searches for subtitles in the current folder"""
"""Searches for subtitles in the current folder"""

video_path = Path(video)
video_path_stem_lower = video_path.stem.lower()
Expand Down Expand Up @@ -195,7 +195,7 @@ def process_subtitle(ctx, param, value):
type=YTDL_OPT,
multiple=True,
metavar="OPT",
help="YouTube-DL option. Should be passed as `-y option=value`, and can be specified multiple times",
help="YouTube-DL option. Should be passed as `-y option=value`, and can be specified multiple times.",
)
@click.pass_obj
def cast(settings, video_url, subtitle, force_default, random_play, no_subs, ytdl_option):
Expand Down
6 changes: 4 additions & 2 deletions catt/controllers.py
Expand Up @@ -383,12 +383,12 @@ def cast_info(self):
@property
def is_streaming_local_file(self):
status = self._cast.media_controller.status
return True if status.content_id.endswith("?loaded_from_catt") else False
return status.content_id.endswith("?loaded_from_catt")

@property
def _is_seekable(self):
status = self._cast.media_controller.status
return True if (status.duration and status.stream_type == "BUFFERED") else False
return status.duration and status.stream_type == "BUFFERED"

@property
def _is_audiovideo(self):
Expand All @@ -407,12 +407,14 @@ def _is_idle(self):

def _prep_app(self):
"""Make sure desired chromecast app is running."""

if not self._cast_listener.app_ready.is_set():
self._cast.start_app(self._cast_listener.app_id)
self._cast_listener.app_ready.wait()

def _prep_control(self):
"""Make sure chromecast is in an active state."""

if self._cast.app_id == BACKDROP_APP_ID or not self._cast.app_id:
raise CattCastError("Chromecast is inactive.")
self._cast.media_controller.block_until_active(1.0)
Expand Down
8 changes: 2 additions & 6 deletions catt/stream_info.py
Expand Up @@ -39,11 +39,7 @@ def __init__(self, video_url, model=None, device_type=None, ytdl_options=None):
self.port = random.randrange(45000, 47000)
self.is_local_file = True
else:
self._ydl = (
youtube_dl.YoutubeDL(DEFAULT_YTDL_OPTS)
if not ytdl_options
else youtube_dl.YoutubeDL(dict(ytdl_options))
)
self._ydl = youtube_dl.YoutubeDL(dict(ytdl_options) if ytdl_options else DEFAULT_YTDL_OPTS)
self._preinfo = self._get_stream_preinfo(video_url)
# Some playlist urls needs to be re-processed (such as youtube channel urls).
if self._preinfo.get("ie_key"):
Expand Down Expand Up @@ -71,7 +67,7 @@ def is_remote_file(self):

@property
def _is_direct_link(self):
return self.is_remote_file and "direct" in self._info
return self.is_remote_file and self._info.get("direct")

@property
def is_playlist(self):
Expand Down

0 comments on commit 64135f5

Please sign in to comment.