switch to InquirerPy in get_stream_url_from_user

This commit is contained in:
alacleaker 2024-04-22 23:36:50 -03:00
parent 6f08a4b2f9
commit 1baca4151b

View File

@ -2,8 +2,8 @@ from __future__ import annotations
from pathlib import Path
import click
from tabulate import tabulate
from InquirerPy import inquirer
from InquirerPy.base.control import Choice
from .downloader import Downloader
from .enums import PostQuality
@ -40,21 +40,18 @@ class DownloaderPost:
def get_stream_url_from_user(self, metadata: dict) -> str:
qualities = list(metadata["attributes"]["assetTokens"].keys())
table = [
[index, quality]
for index, quality in enumerate(
qualities,
start=1,
choices = [
Choice(
name=quality,
value=quality,
)
for quality in qualities
]
print(tabulate(table))
try:
choice = (
click.prompt("Choose a quality", type=click.IntRange(1, len(table))) - 1
)
except click.exceptions.Abort:
raise KeyboardInterrupt()
return metadata["attributes"]["assetTokens"][qualities[choice]]
selected = inquirer.select(
message="Select which quality to download",
choices=choices,
).execute()
return metadata["attributes"]["assetTokens"][selected]
def get_stream_url(self, metadata: dict) -> str:
if self.quality == PostQuality.BEST: