Add graceful exit handling for Ctrl+C interrupts
This commit is contained in:
parent
cb1a201107
commit
a2e8042f27
@ -6,6 +6,7 @@ YouTube CLI - A command-line interface for browsing and downloading YouTube vide
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
@ -1004,8 +1005,16 @@ class YouTubeCLI:
|
|||||||
console.print(f"[red]Error during playlist download: {str(e)}[/red]")
|
console.print(f"[red]Error during playlist download: {str(e)}[/red]")
|
||||||
|
|
||||||
|
|
||||||
|
def signal_handler(sig, frame):
|
||||||
|
"""Handle Ctrl+C gracefully."""
|
||||||
|
console.print("\n[yellow]Operation cancelled by user.[/yellow]")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main entry point for the YouTube CLI application."""
|
"""Main entry point for the YouTube CLI application."""
|
||||||
|
# Register signal handler for Ctrl+C
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="YouTube CLI - Browse and download videos from YouTube"
|
description="YouTube CLI - Browse and download videos from YouTube"
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user