icitry / YoutubeCLI

Apache License 2.0
237 stars 20 forks source link

YoutubeCLI

Link to the YouTube video

All of us have probably experienced the horrors beyond human comprehension that come with a classic Youtube session, so what do you say if, by taking this nigh infinite potential of the platform, while getting rid of all the fluff, we use it in the way it’s always been intended – running the entire thing from your terminal, no fancy useless UI, no fancy useless features and even no fancy useless graphics.

By combining the powers of the official Youtube API, the ever-dependable Python and the ingenuity (ahem) of yours truly, I try to get the entirety of the Youtube experience running in a terminal, in such a way that no matter the environment, you'll get to experience the platform in its most adequate form.

Setting up

To setup the execution environment:

cd path/to/root
python -m venv env
pip install -r requirements.txt

To be able to use the Google Auth side of things, you need to create and download your client secret config file.

  1. Create a new project in your Google Cloud Console.
  2. Enable Youtube Data API v3 and setup OAuth, making sure to select the correct scopes: https://www.googleapis.com/auth/youtube.force-ssl.
  3. Download the credentials file to the auth directory and make sure it's named client_secret.json.

Usage:

usage: main.py [-h] [--scaling-factor SCALING_FACTOR] [--char-ratio CHAR_RATIO] [--max-width MAX_WIDTH]
               [--video-url VIDEO_URL] [--subtitles] [--subtitles-lang SUBTITLES_LANG] [--colors] [--high-accuracy]
               [--invert-colors]

optional arguments:
  -h, --help            show this help message and exit
  --scaling-factor SCALING_FACTOR, -f SCALING_FACTOR
                        Scaling factor relative to the CLI dimensions.
  --char-ratio CHAR_RATIO, -r CHAR_RATIO
                        CLI characters aspect ratio.
  --max-width MAX_WIDTH, -w MAX_WIDTH
                        Max video frame width in chars. Aspect ratio is fixed so it determines entire video size.
                        Negative means uncapped, default behavior.
  --video-url VIDEO_URL, -u VIDEO_URL
                        URL for a video to be played directly on start.
  --subtitles, -s       Flag that signals to enable video subtitles. If no matches are found, it attempts to load
                        auto-generated captions.
  --subtitles-lang SUBTITLES_LANG, -l SUBTITLES_LANG
                        The preferred language for the subtitles.
  --colors, -c          Use colors when rendering. *Warning: Performance-heavy.
  --high-accuracy, -a   High accuracy rendering. Will use Unicode characters instead of base ASCII for rendering
                        images.
  --invert-colors, -i   If flag is present, colors will be inverted. To be used if background is lighter than
                        characters.

Keyboard mappings:

*Notes:

  1. Regarding Color rendering of the frames, currently it has been set to accept the base ANSI-8 primary colors, but new entries can be added to the ANSIConstants.COLORS dictionary, following the established structure. The color matching algorithm (should) work with any number of input colors, although the more colors to choose from, the slower the execution.
  2. I have opted not to include audio support due to the on-the-fly nature of the project, as it would over-complicate and slow-down the execution considerably due to potential syncing issues.