Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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(
run=func, exit=exit, nargs=nargs, is_action=is_action)
return func
return decorator
class Option(NamedTuple):
run: Callable
exit: bool
def update_all() -> None:
print(_("Updating channels..."))
try:
ytcc_core.update_all()
except DatabaseOperationalError:
print(_("Database error! Check if other processes of ytcc are running!"))
sys.exit(1)
action="store_true")
parser.add_argument("-o", "--columns",
help=_("specifies which columns will be printed when listing videos. COL "
"can be any of {columns}. All columns can be enabled with "
"'all'").format(columns=ytcc.cli.TABLE_HEADER),
nargs='+',
metavar="COL",
choices=["all", *ytcc.cli.TABLE_HEADER])
parser.add_argument("--no-header",
help=_("do not print the header of the table when listing videos"),
action="store_true")
parser.add_argument("-x", "--no-video",
help=_("plays or downloads only the audio part of a video"),
action="store_true")
parser.add_argument("-y", "--disable-interactive",
help=_("disables the interactive mode"),
action="store_true")
parser.add_argument("--import-from",
help=_("import YouTube channels from YouTube's subscription export "
"(available at https://www.youtube.com/subscription_manager)"),
metavar="PATH",
type=argparse.FileType("r"))
parser.add_argument("--export-to",
help=_("export YouTube channels in opml format"),
metavar="PATH",
type=argparse.FileType("wb"))
def list_videos() -> None:
videos = ytcc_core.list_videos()
if not videos:
print(_("No videos to list. No videos match the given criteria."))
else:
print_videos(videos)
def download_video(video: Video, audio_only: bool = False) -> None:
print(_('Downloading "{video.title}" by "{video.channel.displayname}"...').format(video=video))
success = ytcc_core.download_video(video=video, path=DOWNLOAD_PATH, audio_only=audio_only)
if not success:
print(_("An Error occured while downloading the video"))
"by the channel"),
nargs=2,
metavar=("NAME", "URL"))
parser.add_argument("-c", "--list-channels",
help=_("print a list of all subscribed channels"),
action="store_true")
parser.add_argument("-r", "--delete-channel",
help=_("unsubscribe from the channel identified by 'NAME'"),
metavar="NAME",
nargs='+',
type=str)
parser.add_argument("--rename",
help=_("rename channel 'OLDNAME' to 'NEWNAME'"),
metavar=("OLDNAME", "NEWNAME"),
nargs=2,
type=str)
parser.add_argument("-u", "--update",
help=_("update the video list"),
action="store_true")
parser.add_argument("-l", "--list",
help=_("print a list of videos that match the criteria given by the "
"filter options"),
action="store_true")
parser.add_argument("-w", "--watch",
help=_("play the videos identified by 'ID'. Omitting the ID will play all "
"videos specified by the filter options"),
help=_("mark videos identified by ID as watched. Omitting the ID will mark"
" all videos that match the criteria given by the filter options as "
"watched"),
nargs='*',
type=int,
metavar="ID")
parser.add_argument("-f", "--channel-filter",
help=_("plays, lists, marks, downloads only videos from channels defined "
"in the filter"),
nargs='+',
type=str,
metavar="NAME")
parser.add_argument("-n", "--include-watched",
help=_("include already watched videos to filter rules"),
action="store_true")
parser.add_argument("-s", "--since",
help=_("includes only videos published after the given date"),
metavar="YYYY-MM-DD",
type=is_date)
parser.add_argument("-t", "--to",
help=_("includes only videos published before the given date"),
metavar="YYYY-MM-DD",
type=is_date)
parser.add_argument("-p", "--path",
help=_("set the download path to PATH"),
metavar="PATH",
type=is_directory)
"can be any of {columns}. All columns can be enabled with "
"'all'").format(columns=ytcc.cli.TABLE_HEADER),
nargs='+',
metavar="COL",
choices=["all", *ytcc.cli.TABLE_HEADER])
parser.add_argument("--no-header",
help=_("do not print the header of the table when listing videos"),
action="store_true")
parser.add_argument("-x", "--no-video",
help=_("plays or downloads only the audio part of a video"),
action="store_true")
parser.add_argument("-y", "--disable-interactive",
help=_("disables the interactive mode"),
action="store_true")
parser.add_argument("--import-from",
help=_("import YouTube channels from YouTube's subscription export "
"(available at https://www.youtube.com/subscription_manager)"),
metavar="PATH",
type=argparse.FileType("r"))
parser.add_argument("--export-to",
help=_("export YouTube channels in opml format"),
metavar="PATH",
type=argparse.FileType("wb"))
parser.add_argument("--cleanup",
help=_("removes old videos from the database and shrinks the size of the "
"database file"),
def import_channels(file: TextIO) -> None:
print(_("Importing..."))
try:
ytcc_core.import_channels(file)
subscriptions = _("Subscriptions")
print()
print(subscriptions)
print("=" * len(subscriptions))
print_channels()
except core.InvalidSubscriptionFileError:
print(_("The given file is not valid YouTube export file"))
def download_video(video: Video, audio_only: bool = False) -> None:
print(_('Downloading "{video.title}" by "{video.channel.displayname}"...').format(video=video))
success = ytcc_core.download_video(video=video, path=DOWNLOAD_PATH, audio_only=audio_only)
if not success:
print(_("An Error occured while downloading the video"))