Compare commits
No commits in common. "bde3e58618e3f7cad21eecfcb347637e169ecba2" and "7797c47195b6c2298da26132edc426ad508a8440" have entirely different histories.
bde3e58618
...
7797c47195
56
README
56
README
@ -4,66 +4,42 @@ viewing and interacting with YouTube videos.
|
|||||||
Dependencies:
|
Dependencies:
|
||||||
- curl(1)
|
- curl(1)
|
||||||
- jq(1)
|
- jq(1)
|
||||||
|
- mpv(1)
|
||||||
- yt-dlp(1)
|
- yt-dlp(1)
|
||||||
|
|
||||||
Environment Variables:
|
Variables:
|
||||||
$DEBUG
|
|
||||||
- Set this variable to get debug output to stderr
|
|
||||||
|
|
||||||
$PLAYER
|
|
||||||
- Set this variable to a video player that can utilize yt-dlp to playback
|
|
||||||
videos from YouTube
|
|
||||||
|
|
||||||
$YTPICK
|
$YTPICK
|
||||||
- Set this variable to a dmenu-compatible picker for use with the pick
|
- Set this variable to a dmenu-compatible picker for use with the pick
|
||||||
subcommand
|
subcommand.
|
||||||
|
|
||||||
$YT_PL_DIR
|
|
||||||
- Set this variable to the directory where playlists should be stored; defaults
|
|
||||||
to $XDG_DATA_HOME/yt
|
|
||||||
|
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
yt add | archive | cache | clone | list | localsearch | new | pick | play | queue | search | sync | verify
|
yt add | archive | cache | clone | music | pick | play | queue | verify
|
||||||
|
|
||||||
add uri playlist
|
add uri file
|
||||||
- Adds a video by URI to a playlist
|
- Adds a video by URI to a playlist
|
||||||
|
|
||||||
archive uri...
|
archive uri...
|
||||||
- Archives videos on the Wayback Machine
|
- Archives a video on the Wayback Machine
|
||||||
|
|
||||||
cache video...
|
cache uri...
|
||||||
- Caches video titles
|
- Caches a video title
|
||||||
|
|
||||||
clone uri [playlist]
|
clone uri file
|
||||||
- Clones a YouTube playlist to a file
|
- Clones a YouTube playlist to a file
|
||||||
|
|
||||||
list
|
music uri...
|
||||||
- lists local playlists
|
- Downloads a video as audio, splitting it by chapter
|
||||||
|
|
||||||
localsearch
|
pick file...
|
||||||
- uses $YTPICK to search for videos from the local cache
|
|
||||||
|
|
||||||
new playlist...
|
|
||||||
- creates new playlists
|
|
||||||
|
|
||||||
pick playlist...
|
|
||||||
- Opens $PICKER to a list of videos in a file
|
- Opens $PICKER to a list of videos in a file
|
||||||
|
|
||||||
play uri...
|
play uri...
|
||||||
- Plays videos, caching their titles first
|
- Plays a video, caching its title first
|
||||||
|
|
||||||
queue playlist...
|
queue file...
|
||||||
- Queues playlists
|
- Queues a playlist
|
||||||
|
|
||||||
search term [count]
|
verify file...
|
||||||
- Searches YouTube for term and returns count results
|
|
||||||
|
|
||||||
sync [playlist]
|
|
||||||
- If a playlist is specified, sync that playlist with its remote YouTube
|
|
||||||
counterpart; otherwise, sync all playlists with remotes
|
|
||||||
|
|
||||||
verify playlist...
|
|
||||||
- Verifies that all the videos in a playlist are existent on YouTube, and if
|
- Verifies that all the videos in a playlist are existent on YouTube, and if
|
||||||
they aren’t, attempts to replace the URI with one from the Wayback Machine. If
|
they aren’t, attempts to replace the URI with one from the Wayback Machine. If
|
||||||
the video isn’t available on the Wayback Machine, it comments the video link. It
|
the video isn’t available on the Wayback Machine, it comments the video link. It
|
||||||
|
70
yt
70
yt
@ -30,24 +30,12 @@ test -n "$YT_PL_DIR" \
|
|||||||
test -d "$YT_PL_DIR" \
|
test -d "$YT_PL_DIR" \
|
||||||
|| mkdir -p "$YT_PL_DIR"
|
|| mkdir -p "$YT_PL_DIR"
|
||||||
|
|
||||||
if test -z "$YTPICK"; then
|
|
||||||
printf "%s: Please set \$YTPICK to your preferred picking tool." \
|
|
||||||
"$argv0" 1>&2
|
|
||||||
exit 78 # sysexits.h(3) EX_CONFIG
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test -z "$PLAYER"; then
|
|
||||||
printf "%s: Please set \$PLAYER to your preferred video player." \
|
|
||||||
"$argv0" 1>&2
|
|
||||||
exit 78 # sysexits.h(3) EX_CONFIG
|
|
||||||
fi
|
|
||||||
|
|
||||||
# formatted $YT_PL_DIR for use with sed
|
# formatted $YT_PL_DIR for use with sed
|
||||||
P="$(printf '%s\n' "$YT_PL_DIR" | sed 's;\/;\\/;g')"
|
P="$(printf '%s\n' "$YT_PL_DIR" | sed 's;\/;\\/;g')"
|
||||||
|
|
||||||
argv0="$0"
|
argv0="$0"
|
||||||
com="$1"
|
com="$1"
|
||||||
u='add | archive | clone | list | localsearch | new | pick | play | search | sync | verify'
|
u='add | archive | clone | list | new | pick | play | search | sync | verify'
|
||||||
FMT='%(title)s – %(channel)s (%(duration>%H:%M:%S)s) [%(webpage_url)s]'
|
FMT='%(title)s – %(channel)s (%(duration>%H:%M:%S)s) [%(webpage_url)s]'
|
||||||
WBAPI='https://archive.org/wayback/available?url='
|
WBAPI='https://archive.org/wayback/available?url='
|
||||||
|
|
||||||
@ -117,7 +105,7 @@ clone() { # clones a YouTube playlist to a file
|
|||||||
n=1
|
n=1
|
||||||
|
|
||||||
while test -z "$title"; do
|
while test -z "$title"; do
|
||||||
title="$(yt-dlp -s -I "$n" --print '%(playlist)s' "$1" 2>/dev/null || true)"
|
title="$(yt-dlp -s -I "$n" --print '%(playlist)s' "$1" || true)"
|
||||||
n="$((n + 1))"
|
n="$((n + 1))"
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -145,18 +133,20 @@ lines() {
|
|||||||
|
|
||||||
list() {
|
list() {
|
||||||
test -n "$1" && usage 'list'
|
test -n "$1" && usage 'list'
|
||||||
|
|
||||||
|
if test -z "$YTPICK"; then
|
||||||
|
printf "%s: Please set \$YTPICK to your preferred picking tool." \
|
||||||
|
"$argv0" 1>&2
|
||||||
|
exit 78 # sysexits.h(3) EX_CONFIG
|
||||||
|
fi
|
||||||
|
|
||||||
choices="$(menu)"
|
choices="$(menu)"
|
||||||
|
|
||||||
test -z "$choices" || pick "$choices"
|
test -z "$choices" || pick "$choices"
|
||||||
}
|
}
|
||||||
|
|
||||||
localsearch() {
|
|
||||||
test -n "$1" && usage 'localsearch'
|
|
||||||
$YTPICK <"$cachefile"
|
|
||||||
}
|
|
||||||
|
|
||||||
menu() {
|
menu() {
|
||||||
playlist="$(ls "$YT_PL_DIR" | sed 's/\.m3u//g' | sed -n '/[^.old]/p' \
|
playlist="$(ls "$YT_PL_DIR" | sed 's/\.m3u//g' | sed -n '/[^.old]/p' | $YTPICK)"
|
||||||
| $YTPICK)"
|
|
||||||
|
|
||||||
while test -d "$YT_PL_DIR/$playlist"; do
|
while test -d "$YT_PL_DIR/$playlist"; do
|
||||||
dir="$playlist"
|
dir="$playlist"
|
||||||
@ -184,6 +174,12 @@ new() {
|
|||||||
pick() { # Pick a video to play from a playlist of videos
|
pick() { # Pick a video to play from a playlist of videos
|
||||||
test -z "$1" && usage 'pick playlist...'
|
test -z "$1" && usage 'pick playlist...'
|
||||||
|
|
||||||
|
if test -z "$YTPICK"; then
|
||||||
|
printf "%s: Please set \$YTPICK to your preferred picking tool." \
|
||||||
|
"$argv0" 1>&2
|
||||||
|
exit 78 # sysexits.h(3) EX_CONFIG
|
||||||
|
fi
|
||||||
|
|
||||||
if test -f "$YT_PL_DIR/$1.m3u"; then
|
if test -f "$YT_PL_DIR/$1.m3u"; then
|
||||||
file="$YT_PL_DIR/$1.m3u"
|
file="$YT_PL_DIR/$1.m3u"
|
||||||
|
|
||||||
@ -214,6 +210,12 @@ pick() { # Pick a video to play from a playlist of videos
|
|||||||
play() { # play a video after caching its title
|
play() { # play a video after caching its title
|
||||||
test -z "$1" && usage 'play uri...'
|
test -z "$1" && usage 'play uri...'
|
||||||
|
|
||||||
|
if test -z "$PLAYER"; then
|
||||||
|
printf "%s: Please set \$PLAYER to your preferred video player." \
|
||||||
|
"$argv0" 1>&2
|
||||||
|
exit 78 # sysexits.h(3) EX_CONFIG
|
||||||
|
fi
|
||||||
|
|
||||||
cache "$@" &
|
cache "$@" &
|
||||||
"$PLAYER" "$@"
|
"$PLAYER" "$@"
|
||||||
}
|
}
|
||||||
@ -221,6 +223,12 @@ play() { # play a video after caching its title
|
|||||||
queue() {
|
queue() {
|
||||||
test -z "$1" && usage 'queue playlist...'
|
test -z "$1" && usage 'queue playlist...'
|
||||||
|
|
||||||
|
if test -z "$PLAYER"; then
|
||||||
|
printf "%s: Please set \$PLAYER to your preferred video player." \
|
||||||
|
"$argv0" 1>&2
|
||||||
|
exit 78 # sysexits.h(3) EX_CONFIG
|
||||||
|
fi
|
||||||
|
|
||||||
while test -f "$YT_PL_DIR/$1.m3u"; do
|
while test -f "$YT_PL_DIR/$1.m3u"; do
|
||||||
"$PLAYER" "$YT_PL_DIR/$1.m3u"
|
"$PLAYER" "$YT_PL_DIR/$1.m3u"
|
||||||
shift
|
shift
|
||||||
@ -230,6 +238,12 @@ queue() {
|
|||||||
search() {
|
search() {
|
||||||
test -z "$1" && usage 'search term [count]'
|
test -z "$1" && usage 'search term [count]'
|
||||||
|
|
||||||
|
if test -z "$YTPICK"; then
|
||||||
|
printf "%s: Please set \$YTPICK to your preferred picking tool." \
|
||||||
|
"$argv0" 1>&2
|
||||||
|
exit 78 # sysexits.h(3) EX_CONFIG
|
||||||
|
fi
|
||||||
|
|
||||||
results="$(yt-dlp "ytsearch$2:$1" --print "$FMT")"
|
results="$(yt-dlp "ytsearch$2:$1" --print "$FMT")"
|
||||||
|
|
||||||
cache "$(printf '%s\n' "$results" | sed -e 's/.*\[//g' -e 's/\]/ /g' \
|
cache "$(printf '%s\n' "$results" | sed -e 's/.*\[//g' -e 's/\]/ /g' \
|
||||||
@ -260,6 +274,18 @@ search() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchlocal() {
|
||||||
|
test -n "$1" && usage 'searchlocal'
|
||||||
|
|
||||||
|
if test -z "$YTPICK"; then
|
||||||
|
printf "%s: Please set \$YTPICK to your preferred picking tool." \
|
||||||
|
"$argv0" 1>&2
|
||||||
|
exit 78 # sysexits.h(3) EX_CONFIG
|
||||||
|
fi
|
||||||
|
|
||||||
|
$YTPICK <"$cachefile"
|
||||||
|
}
|
||||||
|
|
||||||
sync() {
|
sync() {
|
||||||
if test -z "$1"
|
if test -z "$1"
|
||||||
then
|
then
|
||||||
@ -354,6 +380,4 @@ done
|
|||||||
|
|
||||||
test -n "$com" && shift || usage "$u"
|
test -n "$com" && shift || usage "$u"
|
||||||
|
|
||||||
printf '%s\n' "$u" | grep "$com" >/dev/null || usage "$u"
|
|
||||||
|
|
||||||
"$com" "$@"
|
"$com" "$@"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user