Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from ytcc.database import Video
from ytcc.exceptions import BadConfigException, ChannelDoesNotExistException, \
DuplicateChannelException, BadURLException, DatabaseOperationalError
from ytcc.terminal import printt, printtln
from ytcc.utils import unpack_optional
try:
ytcc_core = core.Ytcc() # pylint: disable=C0103
COLUMN_FILTER = [ytcc_core.config.table_format.getboolean("ID"),
ytcc_core.config.table_format.getboolean("Date"),
ytcc_core.config.table_format.getboolean("Channel"),
ytcc_core.config.table_format.getboolean("Title"),
ytcc_core.config.table_format.getboolean("URL"),
ytcc_core.config.table_format.getboolean("Watched")]
COLORS = ytcc_core.config.color
except BadConfigException:
print(_("The configuration file has errors!"))
sys.exit(1)
INTERACTIVE_ENABLED = True
DESCRIPTION_ENABLED = True
NO_VIDEO = False
DOWNLOAD_PATH = ""
HEADER_ENABLED = True
TABLE_HEADER = [_("ID"), _("Date"), _("Channel"), _("Title"), _("URL"), _("Watched")]
_REGISTERED_OPTIONS: Dict[str, "Option"] = dict()
def register_option(option_name, exit=False, is_action=True): # pylint: disable=redefined-builtin
def decorator(func):
nargs = len(inspect.signature(func).parameters)
_REGISTERED_OPTIONS[option_name] = Option(
"date": Video.publish_date,
"channel": Channel.displayname,
"title": Video.title,
"url": Video.yt_videoid,
"watched": Video.watched
}
for key in self._config["YTCC"]["orderBy"].split(","):
sort_spec = list(map(lambda s: s.strip().lower(), key.split(":")))
col = sort_spec[0]
desc = ""
if len(sort_spec) == 2:
desc = sort_spec[1]
column = unpack_or_raise(col_mapping.get(col),
BadConfigException(f"Cannot order by {key.strip()}"))
column = column.collate("NOCASE")
yield column.desc() if desc == "desc" else column
def init_action(self) -> str:
action = self._config["YTCC"]["defaultAction"]
if not action:
return "PLAY_VIDEO"
actions = {"PLAY_VIDEO", "PLAY_AUDIO", "MARK_WATCHED", "DOWNLOAD_AUDIO", "DOWNLOAD_VIDEO"}
action = action.upper()
if action not in actions:
raise BadConfigException(f"Unknown action: {action}")
return action