chvids

get youtube channels videos in your terminal
git clone git://git.kocotian.pl/chvids.git
Log | Files | Refs | README | LICENSE

commit c086466c00bf3e0080d079a8da90014994365f1a
Author: Kacper Kocot <kocotian@kocotian.pl>
Date:   Sun,  8 Nov 2020 10:55:02 +0100

initial commit

Diffstat:
AREADME.md | 1+
Achannels | 43+++++++++++++++++++++++++++++++++++++++++++
Achvids | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Achvids.1 | 49+++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 155 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1 @@ +# chvids diff --git a/channels b/channels @@ -0,0 +1,43 @@ +#!/bin/sh +URLS="$(grep "youtube\\.com/feeds" ~/.config/newsboat/urls)" +CHANNELCOUNT="$(echo "$URLS" | wc -l)" + +help() +{ + echo "help: + h = this help + q = quit + l = list channels + s = select channel" +} + +list() +{ + CHANNELS="got \033[1;33m$CHANNELCOUNT \033[0mchannels"; NUMBER=1 + echo "$URLS" | while read LINE + do + CHANNELS="$CHANNELS\n\033[1;33m$NUMBER. \033[1;97m$(echo "${LINE##* }" | sed "s/\ *\"~//g;s/\"$//g")" + [ "$NUMBER" = "$CHANNELCOUNT" ] && (echo "$CHANNELS" | less) + NUMBER=$(($NUMBER + 1)) + done +} + +select() +{ + echo -n "\033[1;34m:: \033[0mgive channel number (h for help) \033[1;34m>> \033[0m" + read CHNO + [ "$CHNO" = "q" ] && return + [ "$CHNO" = "l" ] && list && select && return + [ "$CHNO" = "h" ] && help && select && return + chvids $(echo "$URLS" | sed -n "s/^.*channel_id=//g;s/\\t.*$//g;${CHNO}p") +} + +while true +do + echo -n "\033[1;34m:: \033[0mwhat to do? (h for help) \033[1;34m>> \033[0m" + read WHAT + [ "$WHAT" = "q" ] && break + [ "$WHAT" = "h" ] && help + [ "$WHAT" = "l" ] && list + [ "$WHAT" = "s" ] && select +done diff --git a/chvids b/chvids @@ -0,0 +1,62 @@ +#!/bin/sh + +echo "\033[1;33m:: \033[0mStarted getting data from channel \033[1;33m$1\033[0m..." +VIDS="$(curl -Lsf "https://opentube.kocotian.pl/api/getChannelVideos.php?id=$1")" +VIDCOUNT="$(echo "$VIDS" | wc -l)" +echo "\033[1;32m:: \033[0mDone" + +help() +{ + echo "help: + h = this help + q = quit + l = list videos + p = play video + d = download video" +} + +list() +{ + LIST="channel have \033[1;33m$VIDCOUNT \033[0mvideos"; NUMBER=1 + echo "$VIDS" | while read LINE + do + LIST="$LIST\n\033[1;33m$NUMBER. \033[1;97m${LINE##* }" + [ "$NUMBER" = "$VIDCOUNT" ] && (echo "$LIST" | less) + NUMBER=$(($NUMBER + 1)) + done +} + +play() +{ + echo -n "\033[1;34m:: \033[0mgive video number (h for help) \033[1;34m>> \033[0m" + read VIDNO + [ "$VIDNO" = "q" ] && return + [ "$VIDNO" = "l" ] && list && play && return + [ "$VIDNO" = "h" ] && help && play && return + VID=$(echo "$VIDS" | sed -n ${VIDNO}p) + echo "\033[1;32m:: \033[0mplaying \033[1;33m${VID##* }\033[0m..." + mpv "https://youtu.be/${VID%% *}" +} + +download() +{ + echo -n "\033[1;34m:: \033[0mgive video number (h for help) \033[1;34m>> \033[0m" + read VIDNO + [ "$VIDNO" = "q" ] && return + [ "$VIDNO" = "l" ] && list && download && return + [ "$VIDNO" = "h" ] && help && download && return + VID=$(echo "$VIDS" | sed -n ${VIDNO}p) + echo "\033[1;32m:: \033[0mdownloading \033[1;33m${VID##* }\033[0m..." + youtube-dl --add-metadata -i "https://youtu.be/${VID%% *}" +} + +while true +do + echo -n "\033[1;34m:: \033[0mwhat to do? (h for help) \033[1;34m>> \033[0m" + read WHAT + [ "$WHAT" = "q" ] && break + [ "$WHAT" = "h" ] && help + [ "$WHAT" = "l" ] && list + [ "$WHAT" = "p" ] && play + [ "$WHAT" = "d" ] && download +done diff --git a/chvids.1 b/chvids.1 @@ -0,0 +1,49 @@ +.TH CHVIDS 1 chvids +.SH NAME +chvids \- get youtube channel videos +.SH SYNOPSIS +.B chvids +.RB [CHANNEL_ID] +.SH DESCRIPTION +chvids is a simple POSIX shell script for playing and downloading youtube videos. +.P +Creation genesis is simple - inspired by watching youtube videos from rss in +newsboat from command line. Unfortunately, you cannot see older videos, so +this simple script gets all channel videos. +.SH USAGE +On program start, chvids will fetch all videos and after fetching, +you will get interactive prompt where: +.TP +.B q +quits program or current mode +.TP +.B l +lists all videos +.TP +.B h +displays help +.TP +.B p +change to play mode +.TP +.B d +change to download mode +.SH MODES +.TP +.B play mode +gets video number from user and plays selected video. +.TP +.B download mode +gets video number from user and downloads selected video. +.SH BUGS +chvids uses invidious API (formatted on a server with OpenTube API), +where channel "page" is 60 videos, so in channels with +.B insane +videos count, videos will load +.B really looooong +and some of videos would not load. +.SH COPYRIGHT +Program originally created by Kocotian and licensed under GPLv2. Check included LICENSE file +.SH SEE ALSO +.BR mpv (1), +.BR youtube-dl (1)