#!/usr/bin/env python3 """ Video Control Script Simple command-line interface for controlling the video player """ import os import sys import argparse import subprocess from pathlib import Path def run_video_player(args): """Run the video player with specified arguments""" script_dir = Path(__file__).parent video_player_script = script_dir / "video_player.py" if not video_player_script.exists(): print(f"Error: video_player.py not found at {video_player_script}") return False # Build command cmd = ["sudo", "python3", str(video_player_script)] if args.random: cmd.append("--random") elif args.channel is not None: cmd.extend(["--channel", str(args.channel)]) elif args.index is not None: cmd.extend(["--index", str(args.index)]) elif args.list_channels: cmd.append("--list-channels") elif args.list_videos: cmd.append("--list-videos") if args.config: cmd.extend(["--config", args.config]) try: print(f"Running: {' '.join(cmd)}") subprocess.run(cmd, check=True) return True except subprocess.CalledProcessError as e: print(f"Error running video player: {e}") return False except KeyboardInterrupt: print("\nInterrupted by user") return False def main(): """Main entry point""" parser = argparse.ArgumentParser( description="Video Control - Simple interface for video player", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=""" Examples: python3 video_control.py --random # Play random video python3 video_control.py --channel 5 # Play channel 5 python3 video_control.py --index 2 # Play video at index 2 python3 video_control.py --list-channels # List channels python3 video_control.py --list-videos # List videos """ ) # Mode arguments (mutually exclusive) mode_group = parser.add_mutually_exclusive_group() mode_group.add_argument( '--random', action='store_true', help='Play a random video' ) mode_group.add_argument( '--channel', type=int, metavar='N', help='Play specific channel number' ) mode_group.add_argument( '--index', type=int, metavar='N', help='Play video at specific index (0-based)' ) mode_group.add_argument( '--list-channels', action='store_true', help='List available channels and exit' ) mode_group.add_argument( '--list-videos', action='store_true', help='List available videos with indices and exit' ) # Configuration arguments parser.add_argument( '--config', type=str, help='Path to configuration file' ) args = parser.parse_args() # Check if at least one mode is specified if not any([args.random, args.channel is not None, args.index is not None, args.list_channels, args.list_videos]): parser.print_help() return # Run video player success = run_video_player(args) sys.exit(0 if success else 1) if __name__ == "__main__": main()