From 1fff38e4e6d9b906e430dd41b70c192d81bced57 Mon Sep 17 00:00:00 2001 From: Jenga Phoenix Date: Fri, 15 Mar 2019 22:55:15 -0500 Subject: [PATCH] Filter '|' characters out of video titles. --- README.txt | 161 ++++++++-- TODO.txt | 44 --- yt | 141 +++++++++ yt-desc | 44 --- yt-search | 250 --------------- ytlib.sh | 869 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1142 insertions(+), 367 deletions(-) delete mode 100644 TODO.txt create mode 100644 yt delete mode 100755 yt-desc delete mode 100755 yt-search create mode 100644 ytlib.sh diff --git a/README.txt b/README.txt index 4d980b9..1970d4b 100644 --- a/README.txt +++ b/README.txt @@ -1,50 +1,153 @@ =============================================================================== -SHELLTUBE Shell scripts for easy YT-browsing +SHELLTUBE Browse YT with a hood on =============================================================================== -shelltube will be a collection of (pretty POSIX) shell scripts to -browse YouTube quickly, and entirely without captive UIs. -Right now, there's only one script, yt-search +shelltube is a simples shell-script that lets you browse Youtube-- +searching for playlists, videos, channels, showing their metadata +(including items on playlsits and channels, etc) all from the terminal. -shelltube is written in pure shell; its only dependencies -are any modern shell (pdksh, bash, zsh), lynx, and curl/wget/ftp. -Your terminal should accept ANSI color-codes, too~ +It YouTube quickly, and entirely without a captive UI. -Before, shelltube was a set of scripts that culimated in a wrapper -script for browsing Youtube (like mpsyt). You could even download -videos from YT in pure shell! But, now, all videos require JS execution -to download (as far as I can tell), so it stopped working. +shelltube is written in pure shell; its only dependencies are any +modern shell (pdksh, bash, zsh), lynx, and curl/wget/ftp. -Now I'm refocusing a bit, ditching the wrapper script (begone, captive UIs, -ye spectre of ole!), and starting from scratch. :) +Your terminal should accept ANSI color-codes, and be >79chars wide, +for best experience~ +shelltube isn't for downloading videos-- it's for *browsing* for them. +Use youtube-dl or something for that, that's not my job. :P + + +---------------------------------------- +INSTALLATION +---------------------------------------- +Just place "ytlib.sh" in either the CWD, ./lib/ytlib.sh, /usr/lib/, or +/usr/local/lib/ + +Then put `gendl` and `yt` in your $PATH. /usr/local/bin/ is nice (IMO), +or ~/bin/. + +Profit! + + +---------------------------------------- +EXAMPLES +---------------------------------------- + yt video --search "wixoss op 1" + yt v -s "wixoss op 1" + + yt playlist --search "my hero academia ops" + yt p -s "my hero academia ops" + + yt playlist --title "PLY4D6ucZdLWC_yM3R_A1Hj9fAXZO_rSeK" + yt p -t "PLY4D6ucZdLWC_yM3R_A1Hj9fAXZO_rSeK" + + yt playlist --list "PLY4D6ucZdLWC_yM3R_A1Hj9fAXZO_rSeK" + yt p -l "PLY4D6ucZdLWC_yM3R_A1Hj9fAXZO_rSeK" + + yt video --author "https://youtube.com/watch?v=yu0HjPzFYnY" + yt v -a "https://youtube.com/watch?v=yu0HjPzFYnY" + + yt video --desc "https://youtube.com/watch?v=yu0HjPzFYnY" + yt v -d "https://youtube.com/watch?v=yu0HjPzFYnY" + + yt video --date "https://youtube.com/watch?v=yu0HjPzFYnY" + yt v -D "https://youtube.com/watch?v=yu0HjPzFYnY" ---------------------------------------- USAGE ---------------------------------------- -YT-SEARCH +YT -------------------- -yt-search lists videos matching a certain search query. - USAGE: yt-search [-csmb] query +`yt` is the shelltube script-- it's executed with a subcommand [arguments] +system, like `apt` or `git`. -Each option [-csmb] represents a different format-method. - -b big TITLE \n DURATION | VIEWS | URL - -m medium TITLE | DURATION | URL - -s small TITLE | URL - -c compact TITLE | ID + USAGE: yt subcommand action [arguments] -Big takes up two lines, while the rest only use one. -If you're piping output, you might wanna usa -m, -s, or -c. +The subcommands are: + * (v)ideo + * (p)laylist + +They refer to actions related to videos and playlists, respectively. + +Every subcommand and action thereof supports "-h" and "--help". -YT-DESC + +YT VIDEO -------------------- -yt-desc prints the description of a YT video. - USAGE: yt-desc url/id +`yt video` is for anything related to videos-- here it is: -The only argument it takes is the URL/ID of the video. -This script requires `lynx`. + USAGE: yt (v)ideo [action] + +Here are the actions: + + SHORT LONG ARGUMENTS + ---------------------------------------------- + -s --search [-csmb] search_query + -t --title url/id + -d --desc url/id + -v --views url/id + -a --author [-nu] url/id + -D --date url/id + +The only actions with weird arguments are --search and --author: + * normally, --author returns the channel URL and name on two + seperate lines + * "--author -n" returns only the name + * "--author -u" returns only the URL + + * normally, --search prints results in the "big" format (title on + one line, other metadata on second line) + * "--search -c" for "compact" format, etc. + * "-c", "-s", "-m", "-b", for "compact", "small", "medium", and "big", + respectively + + +YT PLAYLIST +-------------------- +`yt playlist` is for anything related to playlists-- here it is: + + USAGE: yt (p)laylist [action] + +Here are the actions: + + SHORT LONG ARGUMENTS + ---------------------------------------------- + -s --search [-csmb] search_query + -l --list [-csmb] url/id + -t --title url/id + -v --views url/id + -a --author [-nu] url/id + -D --date url/id + +The only actions with weird arguments are --search, --list and --author: + * --author acts just like "video --author" + * --search acts just like "video --search" + * --list acts just like --search, with [-csmb] + + +YT CHANNEL +-------------------- +`yt channel` is for anything related to channels-- here it is: + + USAGE: yt (c)hannel [action] + +Here are the actions: + + SHORT LONG ARGUMENTS + ---------------------------------------------- + -s --search [-csmb] search_query + -l --list [-csmb] url/id + -t --title url/id + -d --desc url/id + -v --subscribers url/id + -D --date url/id + +The only actions with weird arguments are --search, --list and --author: + * --search acts just like "video --search" + * --list acts just like "playlist --search" GENDL @@ -70,4 +173,4 @@ BORING STUFF ---------------------------------------- License is in COPYING.txt (GNU GPLv3~! <3) Author is Jenga Phoenix -Sauce is at https://git.eunichx.us/shelltube +Sauce is at https://git.eunichx.us/shelltube.git diff --git a/TODO.txt b/TODO.txt deleted file mode 100644 index 6057ea2..0000000 --- a/TODO.txt +++ /dev/null @@ -1,44 +0,0 @@ -At some point in time, this SHOULD be the readme. It isn't right now, obviously. - -=============================================================================== -SHELLTUBE Shell scripts for easy YT-browsing -=============================================================================== -shelltube is a collection of (pretty POSIX) shell scripts to -browse YouTube quickly, and entirely without captive UIs. - -shellTube is written in pure shell; its only dependencies -are any modern shell (pdksh, bash, zsh) and curl/wget/ftp. -Your terminal should accept ANSI color-codes, too~ - - - ----------------------------------------- -USAGE ----------------------------------------- -There are three different scripts that make up shelltube: - * yt-search - * yt-channel - * yt-meta - -In all three scripts: - 'index' means what page of results you're on-- - 'results' means how many of them will be displayed. - -yt-search lists videos matching a certain search query. - USAGE: yt-search [-i index] [-r results] query - - -yt-channel lists the videos of a given channel. - USAGE: yt-channel [-i index] [-r results] URL/ID/name - -yt-meta lists the metadata of a given video - USAGE: yt-meta URL/ID - - - ----------------------------------------- -BORING STUFF ----------------------------------------- -License is in COPYING.txt (GNU GPLv3~! <3) -Author is Jenga Phoenix -Sauce is at https://git.eunichx.us/shelltube diff --git a/yt b/yt new file mode 100644 index 0000000..912a800 --- /dev/null +++ b/yt @@ -0,0 +1,141 @@ +#!/bin/sh +######################################## +# name: yt +# lisc: gnu gplv3 +# main: jadedctrl +# desc: browse youtube from the terminal +######################################## + +# ... there's got to be a better way to +# source this. +if test -e ytlib.sh; then + . ./ytlib.sh +elif test -e lib/ytlib.sh; then + . ./lib/ytlib.sh +elif test -e ../lib/ytlib.sh; then + . ../lib/ytlib.sh +elif test -e /usr/local/lib/ytlib.sh; then + . /usr/local/lib/ytlib.sh +elif test -e /usr/lib/ytlib.sh; then + . /usr/lib/ytlib.sh +else + echo "ytlib.sh not found." + exit 5 +fi + +# -------------------------------------- + +# Show usage message of shelltube itself +function yt_usage { + echo "usage: yt command subcommand [arguments]" + echo " yt (v)ideo [...]" + echo " yt (p)laylist [...]" + exit 2 +} + +# -------------------------------------- + +if test -z "$1"; then + yt_usage +fi + +# -------------------------------------- + +# Show usage message of the video subcommand +function video_usage { + echo "usage: yt video --(s)earch [...]" + echo " yt video --(t)itle [...]" + echo " yt video --(d)esc [...]" + echo " yt video --(a)uthor [...]" + echo " yt video --(v)iews [...]" + echo " yt video --(D)ate [...]" + + exit 2 +} + +# Pass on commands to video subcommand +function video_invocation { + local command="$1" + local arguments="$(echo "$@" | awk '{$1=""; print}')" + + if test -z "$command"; then + video_usage + elif test "$(length "$arguments")" -eq 0; then + arguments="-h" + fi + + case "$command" in + "--search") video_search_invocation $arguments;; + "-s") video_search_invocation $arguments;; + "-d") video_desc_invocation $arguments;; + "--desc") video_desc_invocation $arguments;; + "-D") video_uploaded_invocation $arguments;; + "--date") video_uploaded_invocation $arguments;; + "--views") video_views_invocation $arguments;; + "-v") video_views_invocation $arguments;; + "--author") video_author_invocation $arguments;; + "-a") video_author_invocation $arguments;; + "--title") video_title_invocation $arguments;; + "-t") video_title_invocation $arguments;; + "--help") video_usage;; + "-h") video_usage;; + esac +} + +# -------------------------------------- + +# Show playlist usage message +function playlist_usage { + echo "usage: yt playlist --(s)earch [...]" + echo " yt playlist --(l)ist [...]" + echo " yt playlist --(t)itle [...]" + echo " yt playlsit --(a)uthor [...]" + echo " yt playlist --(v)iews [...]" + echo " yt playlist --(D)ate [...]" + exit 2 +} + +# Pass on commands to the playlist subcommand +function playlist_invocation { + local command="$1" + local arguments="$(echo "$@" | awk '{$1=""; print}')" + + if test -z "$command"; then + playlist_usage + elif test "$(length "$arguments")" -eq 0; then + arguments="-h" + fi + + case "$command" in + "--search") playlist_search_invocation $arguments;; + "-s") playlist_search_invocation $arguments;; + "--views") playlist_views_invocation $arguments;; + "-v") playlist_views_invocation $arguments;; + "--author") playlist_author_invocation $arguments;; + "-a") playlist_author_invocation $arguments;; + "--date") playlist_uploaded_invocation $arguments;; + "-D") playlist_uploaded_invocation $arguments;; + "--title") playlist_title_invocation $arguments;; + "-t") playlist_title_invocation $arguments;; + "--list") playlist_list_invocation $arguments;; + "-l") playlist_list_invocation $arguments;; + "--help") playlist_usage;; + "-h") playlist_usage;; + esac +} + + + +# -------------------------------------- +# actual invocation + +command="$1" +arguments="$(echo "$@" | awk '{$1=""; print}')" +case "$command" in + *video) video_invocation $arguments;; + *v) video_invocation $arguments;; + *channel) channel_invocation $arguments;; + *c) channel_invocation $arguments;; + *playlist) playlist_invocation $arguments;; + *p) playlist_invocation $arguments;; +esac diff --git a/yt-desc b/yt-desc deleted file mode 100755 index ff216f6..0000000 --- a/yt-desc +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh -############################## -# name: yt-desc -# lisc: gnu gplv3 -# main: jadedctrl -# desc: print desc of yt video -############################## - -# Usage: yt-desc "$url/id" - -# STRING --> STRING -# Get the description of a YT video, from HTML. -function video_desc { - local html="$1" - - echo "$html" \ - | grep "action-panel-details" \ - | sed 's/.*

//' \ - | sed 's%

.*%%' \ - | lynx -stdin -dump \ - | sed 's/^ //' -} - -# -------------------------------------- -# invocation - -function usage { - echo "usage: yt-desc url/id" - exit 2 -} - -# -------------------------------------- - -if test -z "$1"; then - usage -elif echo "$1" | grep "youtube" > /dev/null; then - URL="$1" -else - URL="https://www.youtube.com/watch?v=${1}" -fi - -# -------------------------------------- - -video_desc "$(gendl "$URL")" diff --git a/yt-search b/yt-search deleted file mode 100755 index 2dc1cf8..0000000 --- a/yt-search +++ /dev/null @@ -1,250 +0,0 @@ -#!/bin/sh -############################## -# name: yt-search -# lisc: gnu gplv3 -# main: jadedctrl -# desc: search youtube simply. -############################## - -# Usage: yt-search [-csmb] "$search_string" - -# -------------------------------------- -# a bit of math... - -# NUMBER NUMBER --> NUMBER -# Well, subtraction. Y'know... -function subtract { - local operated=$1 - local operatee=$2 - echo "${1}-${2}" | bc -} - - - -# -------------------------------------- -# ... now some string manip... - -# NIL --> STRING -# Print an ANSI "unbold" escape string. -function unbold { - printf "$(tput sgr0)" -} - -# STRING --> STRING -# Print an ANSI "bold" escape string. -function bold { - printf "$(tput bold)" -} - -# STRING --> NUMBER -# Return the length of a string -function char_length { - subtract $(echo $1 | wc -c) 1 -} - -# STRING NUMBER [STRING] --> STRING -# pad string $1 out to the minimum length $2 with padding $3 (default: "0") -function min_string_length { - local string="$1" - local length=$2 - if test -z "$3"; then - local padding="0" - else - local padding="$3" - fi - local new="$string" - if test $(char_length $1) -eq $2; then - echo $1 - else - while test $(char_length $new) -lt $2; do - new="${new}${padding}" - done - echo $new - fi -} - -# STRING NUMBER --> STRING -# get the first $2 characters in string $1 -function char_get { - local number=$2 - local string="$1" - string="$(min_string_length "$string" $number " ")" - echo "$string" \ - | grep -o "^$(min_string_length "." $number ".")" -} - - - -# -------------------------------------- -# ... now for the real deal~! - -# STRING --> STRING -# Pass the raw search HTML, get raw video result-lines -function result_lines { - local search_html="$1" - echo "$search_html" \ - | grep " STRING -# Return the video ID of a result_line. -function result_id { - local result_line="$1" - echo "$result_line" \ - | sed 's%.* STRING -# Return the title of a result-line. -function result_title { - local result_line="$1" - echo "$result_line" \ - | sed 's%.*" title="%%' \ - | sed 's%".*%%' -} - -function result_name { - local result_line="$1" - local title="$(result_title "$result_line")" - echo "$(bold)${title}$(unbold)" -} - - -# STRING --> STRING -# Return the duration of a result-line. -function result_duration { - local result_line="$1" - echo "$result_line" \ - | sed 's%.*> - Duration: %%' \ - | sed 's%\..*%%' -} - -# STRING --> STRING -# Return the .yt-lockup-meta-info