#!/usr/bin/env sh # state variables : "${__is_submenu:=0}" "${__is_fzf_preview:=0}" # versioning system: # major.minor.bugs YTFZF_VERSION="git-2077.0857c74" #ENVIRONMENT VARIABLES {{{ : "${YTFZF_CONFIG_DIR:=${XDG_CONFIG_HOME:-$HOME/.config}/ytfzf}" : "${YTFZF_CONFIG_FILE:=$YTFZF_CONFIG_DIR/conf.sh}" : "${YTFZF_SUBSCRIPTIONS_FILE:=$YTFZF_CONFIG_DIR/subscriptions}" : "${YTFZF_THUMBNAIL_VIEWERS_DIR:=$YTFZF_CONFIG_DIR/thumbnail-viewers}" : "${YTFZF_SORT_NAMES_DIR:=$YTFZF_CONFIG_DIR/sort-names}" : "${YTFZF_CUSTOM_INTERFACES_DIR:=$YTFZF_CONFIG_DIR/interfaces}" : "${YTFZF_URL_HANDLERS_DIR:=$YTFZF_CONFIG_DIR/url-handlers}" : "${YTFZF_CUSTOM_THUMBNAILS_DIR:=$YTFZF_CONFIG_DIR/thumbnails}" : "${YTFZF_EXTENSIONS_DIR:=$YTFZF_CONFIG_DIR/extensions}" : "${YTFZF_CUSTOM_SCRAPERS_DIR:=$YTFZF_CONFIG_DIR/scrapers}" : "${YTFZF_SYSTEM_ADDON_DIR:=/usr/local/share/ytfzf/addons}" : "${YTFZF_TEMP_DIR:="${TMPDIR:-/tmp}"/ytfzf-$(id -u)}" : "${YTFZF_LOGFILE:=}" if [ "$YTFZF_LOGFILE" ] && { [ "$__is_fzf_preview" -eq 1 ] || [ "$__is_submenu" -eq 1 ]; }; then printf "[%s]\n==============\nSubmenu: %d\nFzf Preview: %d\n==============\n" "$(date)" "$__is_submenu" "$__is_fzf_preview" >>"${YTFZF_LOGFILE}" elif [ "${YTFZF_LOGFILE}" ]; then : >"${YTFZF_LOGFILE}" fi ! [ -d "$YTFZF_TEMP_DIR" ] && mkdir -p "${YTFZF_TEMP_DIR}" export YTFZF_PID=$$ #}}} ############################ # DEBUGGING # ############################ # There are only a couple tooling methods that I know of for debugging (other than printing stuff everywhere) # set log_level to 3, and set YTFZF_LOGFILE=./some-file.log # set -x may also be used. ############################ # CODE STYLE # ############################ ################## # VARIABLE NAMES # ################## # Starts with __ if it is a state variable thatt is allowed to be accessed globally. # for example: __is_submenu is a state variable that keeps track of whether or not itt is a submenu # another example: __scrape_count is the current scrape number # Environment variables should be all caps, do not use full caps for constansts # Const variable should start with c_ or const_ # Configuration variables should not start with any prefix, and should have a --long-opt equivelent with as close of a name as posisble to the variable # example: the search_source variable has the long opt equivelent of --search-source # Private variables should start with an _ # A major exception to this is the _search variable, which is global, and should not be used as a local variable. ################## # FUNCTION NAMES # ################## # Private functions should start with an _ # All other functions that should be accessed globally should not start with an _ # A major exception to this is _get_request which is a global function # interface functions MUST start with interface_ in order to work properly # scraper functions MUST start with scrape_ in order to work properly ############################ # ERRORS # ############################ # 0: success # 1: general error # 2: invalid -opt or command argument, invalid argument for opt, configuration error # eg: ytfzf -c terminal (invalid scrape) # 3: missing dependency # 4: scraping error # 5: empty search # *: Likely a curl error ############################ # CODE # ############################ # colors {{{ c_red="\033[1;31m" c_green="\033[1;32m" c_yellow="\033[1;33m" c_blue="\033[1;34m" c_magenta="\033[1;35m" c_cyan="\033[1;36m" c_reset="\033[0m" c_bold="\033[1m" #}}} : "${check_vars_exists:=${YTFZF_CHECK_VARS_EXISTS:-1}}" # __ytfzf__ extension {{{ print_help___ytfzf__() { #the [2A will clear the \n---__ytfzf__--- garbage (in supported terminals) printf "\033[2A%s" \ "Usage: ytfzf [OPTIONS...] The search-query can also be read from stdin GENERAL OPTIONS: -h Show this help text --version Get the current version --version-all Get the current version of ytfzf, and required dependencies UTILITY OPTIONS: --channel-link= Gets the uuid of a youtube channel from a link. PLAYING OPTIONS: -d Download the selected video(s) -m Only play audio -f Select a video format before playing --format-selection= Type can either be normal, or simple --format-sort= The sort used in ytdl for -f. --video-pref= The ytdl video preference. --audio-pref= The ytdl audio preference. --ytdl-pref= The combined ytdl video and audio preference. -u The program to use for handling urls (deafult: multimedia_player) -L Show the link of selected video(s) -I Instead of playing the selected video(s), get information about them. Options can be separated with a comma, eg: L,R Options for info: L: print the link of the video VJ: print the json of the video J: print the json of all videos shown in the search R: print the data of the selected videos, as appears in the menu F: print the selected video format --info-wait When -I or -L is used, wait for user input before continuing --info-action= The action to do when --info-wait is 1. action can be one of q: exit Q: exit (bypass -l) '': play video --detach Detach the url handler from the terminal --notify-playing Sends a notification when a video is selected. --url-handler-opts= Pass the given opts to the url handler. --ytdl-opts= Pass the opts to ytdl when downloading --ytdl-path= The path to youtube-dl MENU OPTIONS: -l Reopen the menu when the video stops playing -t Show thumbnails -T The program to use for displaying thumbnails. see ytfzf(1) for a list of viewers. --async-thumbnails Download thumbnails asynchronously. --skip-thumb-download Skips the process of downloading thumbnails --thumbnail-quality= Select quality of thumbnails, can be: maxres maxresdefault sddefault high (default) medium default start middle end -i The interface to use (default: text) -D Alias for -i ext -a Automatically select the first video -r Automatically select a random video -A Select all videos -S Automatically selects a specific video based on a given sed address -n