Compare commits
3 Commits
7797c47195
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
af5dc3b865
|
|||
|
bde3e58618
|
|||
|
70127c6918
|
56
README
56
README
@@ -4,42 +4,66 @@ viewing and interacting with YouTube videos.
|
||||
Dependencies:
|
||||
- curl(1)
|
||||
- jq(1)
|
||||
- mpv(1)
|
||||
- yt-dlp(1)
|
||||
|
||||
Variables:
|
||||
Environment 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
|
||||
- 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:
|
||||
yt add | archive | cache | clone | music | pick | play | queue | verify
|
||||
yt add | archive | cache | clone | list | localsearch | new | pick | play | queue | search | sync | verify
|
||||
|
||||
add uri file
|
||||
add uri playlist
|
||||
- Adds a video by URI to a playlist
|
||||
|
||||
archive uri...
|
||||
- Archives a video on the Wayback Machine
|
||||
- Archives videos on the Wayback Machine
|
||||
|
||||
cache uri...
|
||||
- Caches a video title
|
||||
cache video...
|
||||
- Caches video titles
|
||||
|
||||
clone uri file
|
||||
clone uri [playlist]
|
||||
- Clones a YouTube playlist to a file
|
||||
|
||||
music uri...
|
||||
- Downloads a video as audio, splitting it by chapter
|
||||
list
|
||||
- lists local playlists
|
||||
|
||||
pick file...
|
||||
localsearch
|
||||
- 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
|
||||
|
||||
play uri...
|
||||
- Plays a video, caching its title first
|
||||
- Plays videos, caching their titles first
|
||||
|
||||
queue file...
|
||||
- Queues a playlist
|
||||
queue playlist...
|
||||
- Queues playlists
|
||||
|
||||
verify file...
|
||||
search term [count]
|
||||
- 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
|
||||
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
|
||||
|
||||
81
yt
81
yt
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (c) 2023 Emma Tebibyte <emma@tebibyte.media>
|
||||
# Copyright (c) 2023, 2025 Emma Tebibyte <emma@tebibyte.media>
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it under
|
||||
@@ -30,12 +30,24 @@ test -n "$YT_PL_DIR" \
|
||||
test -d "$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
|
||||
P="$(printf '%s\n' "$YT_PL_DIR" | sed 's;\/;\\/;g')"
|
||||
|
||||
argv0="$0"
|
||||
com="$1"
|
||||
u='add | archive | clone | list | new | pick | play | search | sync | verify'
|
||||
u='add | archive | clone | list | localsearch | new | pick | play | search | sync | verify'
|
||||
FMT='%(title)s – %(channel)s (%(duration>%H:%M:%S)s) [%(webpage_url)s]'
|
||||
WBAPI='https://archive.org/wayback/available?url='
|
||||
|
||||
@@ -105,7 +117,7 @@ clone() { # clones a YouTube playlist to a file
|
||||
n=1
|
||||
|
||||
while test -z "$title"; do
|
||||
title="$(yt-dlp -s -I "$n" --print '%(playlist)s' "$1" || true)"
|
||||
title="$(yt-dlp -s -I "$n" --print '%(playlist)s' "$1" 2>/dev/null || true)"
|
||||
n="$((n + 1))"
|
||||
done
|
||||
|
||||
@@ -133,20 +145,18 @@ lines() {
|
||||
|
||||
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)"
|
||||
|
||||
test -z "$choices" || pick "$choices"
|
||||
}
|
||||
|
||||
localsearch() {
|
||||
test -n "$1" && usage 'localsearch'
|
||||
$YTPICK <"$cachefile"
|
||||
}
|
||||
|
||||
menu() {
|
||||
playlist="$(ls "$YT_PL_DIR" | sed 's/\.m3u//g' | sed -n '/[^.old]/p' | $YTPICK)"
|
||||
playlist="$(ls "$YT_PL_DIR" | sed 's/\.m3u//g' | sed -n '/[^.old]/p' \
|
||||
| $YTPICK)"
|
||||
|
||||
while test -d "$YT_PL_DIR/$playlist"; do
|
||||
dir="$playlist"
|
||||
@@ -174,12 +184,6 @@ new() {
|
||||
pick() { # Pick a video to play from a playlist of videos
|
||||
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
|
||||
file="$YT_PL_DIR/$1.m3u"
|
||||
|
||||
@@ -210,12 +214,6 @@ pick() { # Pick a video to play from a playlist of videos
|
||||
play() { # play a video after caching its title
|
||||
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 "$@" &
|
||||
"$PLAYER" "$@"
|
||||
}
|
||||
@@ -223,12 +221,6 @@ play() { # play a video after caching its title
|
||||
queue() {
|
||||
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
|
||||
"$PLAYER" "$YT_PL_DIR/$1.m3u"
|
||||
shift
|
||||
@@ -238,13 +230,7 @@ queue() {
|
||||
search() {
|
||||
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 -isq --flat-playlist --print "$FMT" "ytsearch$2:$1")"
|
||||
|
||||
cache "$(printf '%s\n' "$results" | sed -e 's/.*\[//g' -e 's/\]/ /g' \
|
||||
| tr -d '\n')" &
|
||||
@@ -261,9 +247,6 @@ search() {
|
||||
"copy")
|
||||
wl-copy "$selection"
|
||||
;;
|
||||
"music")
|
||||
music "$selection"
|
||||
;;
|
||||
"play")
|
||||
play "$selection"
|
||||
;;
|
||||
@@ -274,18 +257,6 @@ search() {
|
||||
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() {
|
||||
if test -z "$1"
|
||||
then
|
||||
@@ -327,7 +298,7 @@ verify() { # replaces videos with archived versions if they are not available
|
||||
|
||||
printf "%s: %s: Verifying playlist.\n" "$argv0" "$1" 1>&2
|
||||
|
||||
for video in $(lines "$1"); do
|
||||
for video in $(lines "$1"); do {
|
||||
if test -n "$(yt-dlp -s "$video" 2>&1 \
|
||||
| grep -i -e 'video unavailable' -e 'private video' -e 'been removed')"
|
||||
then
|
||||
@@ -360,7 +331,7 @@ verify() { # replaces videos with archived versions if they are not available
|
||||
cache "$video" &
|
||||
archive "$video" &
|
||||
fi
|
||||
done
|
||||
} & done
|
||||
|
||||
shift
|
||||
done
|
||||
@@ -380,4 +351,6 @@ done
|
||||
|
||||
test -n "$com" && shift || usage "$u"
|
||||
|
||||
printf '%s\n' "$u" | grep "$com" >/dev/null || usage "$u"
|
||||
|
||||
"$com" "$@"
|
||||
|
||||
Reference in New Issue
Block a user