Skip to content

Commit

Permalink
Add filter options to TUI (#49)
Browse files Browse the repository at this point in the history
This commit adds the common filter options from the list commands to the
TUI. This allows for a variety of filtering options without the need for
extra logic within the TUI class itself.
  • Loading branch information
EmRowlands authored Oct 3, 2020
1 parent 3168552 commit e220b6f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions ytcc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,19 @@ def update(max_fail: Optional[int], max_backlog: Optional[int]):
]


def list_videos_impl(tags: List[str], since: datetime, till: datetime, playlists: List[str],
ids: List[int], attributes: List[str], watched: bool) -> None:
def apply_filters(tags: List[str], since: datetime, till: datetime, playlists: List[str],
ids: List[int], watched: bool) -> None:
ytcc.set_tags_filter(tags)
ytcc.set_date_begin_filter(since)
ytcc.set_date_end_filter(till)
ytcc.set_playlist_filter(playlists)
ytcc.set_video_id_filter(ids)
ytcc.set_include_watched_filter(watched)


def list_videos_impl(tags: List[str], since: datetime, till: datetime, playlists: List[str],
ids: List[int], attributes: List[str], watched: bool) -> None:
apply_filters(tags, since, till, playlists, ids, watched)
if attributes:
printer.filter = attributes
else:
Expand Down Expand Up @@ -272,8 +277,17 @@ def list_ids(tags: List[str], since: datetime, till: datetime, playlists: List[s
list_videos_impl(tags, since, till, playlists, ids, ["id"], watched)


@cli.command()
def tui(tags: List[str], since: datetime, till: datetime, playlists: List[str],
ids: List[int], watched: bool):
"""Start an interactive terminal user interface."""
apply_filters(tags, since, till, playlists, ids, watched)
Interactive(ytcc).run()


list_ids.params.extend(common_list_options)
list_videos.params.extend(common_list_options)
tui.params.extend(common_list_options)


def _get_ids(ids: List[int]) -> Iterable[int]:
Expand Down Expand Up @@ -371,12 +385,6 @@ def download(ids: Tuple[int, ...], path: Path, audio_only: bool, no_mark: bool):
ytcc.mark_watched(video)


@cli.command()
def tui():
"""Start an interactive terminal user interface."""
Interactive(ytcc).run()


@cli.command()
@click.confirmation_option(
prompt="Do you really want to remove all watched videos from the database?"
Expand Down

0 comments on commit e220b6f

Please sign in to comment.