aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriceyrazor <iceyfoxservers@gmail.com>2025-01-31 19:51:56 -0600
committericeyrazor <iceyfoxservers@gmail.com>2025-01-31 19:51:56 -0600
commitca584b8fd8b43bd83e2c16e17310195e7fe21eb8 (patch)
tree51dc4917315bc142a335bc9dcda4ac46b6a621fc
init
-rw-r--r--.gitignore2
-rw-r--r--LICENSE21
-rw-r--r--README.md36
-rwxr-xr-xchannelname.sh18
-rwxr-xr-xfetch.sh51
-rwxr-xr-xget_yt2.sh21
-rwxr-xr-xpreview.sh5
-rwxr-xr-xwatch.sh6
-rw-r--r--youtube_stuffs.db.defbin0 -> 8192 bytes
9 files changed, 160 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8e5cdf5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*youtube_stuffs.db
+thumbnails/**
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d54d7cc
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2025 iceyrazor
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..33d9bb1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,36 @@
+# youtube playlist cli
+A simplish set of bash scripts to have a locally stored youtube playlist using fzf and sqlite3 with thumbnails
+
+Technically you can modify this to store anything other than just yt videos
+
+# download.
+Just download this repo and rename youtube_stuffs.db.def to youtube_stuffs.db
+
+# requirements
+- bash
+- fzf
+- sqlite3
+- sed
+- youtube-dl
+
+## optional requirements
+- chafa # for image previews
+- a terminal that works with chafa. i use wezterm
+
+# Usage
+- have a playlist or video thats either unlisted or public.
+- run ``fetch.sh "youtube url/playlist url" "playlist name"``.
+that should pretty much do everything.
+- check download_err.txt for download errors. Videos that are marked as nsfw and require sign in will NOT be added to the list and require manual intervention
+- then ``get_yt2.sh.``.
+if you want thumbnails ``get_yt2.sh 1``.
+- if you want too then delete download.txt and download_err.txt and thumberr.txt
+
+# config
+- In ``get_yt2.sh`` there is the preview lines and columns. Idk if I can autodetect this because something something fzf doesn't do something something
+- If you want to change anything else you would have to change the script. Feel free to make your own config system
+
+
+
+# todo
+- auto detect detect last item in list when and before adding new item so thumbnails doesn't start at 1. Or async it or something idk
diff --git a/channelname.sh b/channelname.sh
new file mode 100755
index 0000000..4f98ff6
--- /dev/null
+++ b/channelname.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+# if a item on the db doesnt have a channel name. it will fetch it
+i=1
+max=$(( $(sqlite3 ./youtube_stuffs.db 'select rowid from ytlist order by rowid desc limit 1;') ))
+while :; do
+ urlid="$(sqlite3 ./youtube_stuffs.db 'select id from ytlist where rowid='$i';')"
+ channelname="$(sqlite3 ./youtube_stuffs.db 'select channel from ytlist where rowid='$i';')"
+ if [ -z "$channelname" ]; then
+ setchannel=$(youtube-dl --get-filename -o "%(channel)s" "https://youtube.com/watch/?v=$urlid" | sed "s/'/''/g")
+ sqlite3 ./youtube_stuffs.db "update ytlist set channel='$setchannel' where rowid=$i;"
+ printf "$i::$urlid\n"
+ fi
+
+ ((i=$i+1))
+ if (( $i >= $max + 1 )); then
+ break
+ fi
+done
diff --git a/fetch.sh b/fetch.sh
new file mode 100755
index 0000000..b7cd255
--- /dev/null
+++ b/fetch.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+# arg1 is the url and arg2 is the playlist name
+# if arg1 is not defined. just fetch thumbnails
+
+# cant do whats below because i need to replace all ' within a subset of 'string' with '' to escape it.
+
+# youtube-dl --get-filename -o "insert into ytlist values('%(title)s','%(channel)s','%(id)s','shorts','');" "https://www.youtube.com/playlist?list=PLwpvCCyacwS9Us6F1_UUUre1Py9p4ex4J" 2> out2.txt #| sed "s/'/''/g" #| sqlite3 ./youtube_stuffs.db
+
+cd "$(dirname "$0")"
+file="./download.txt"
+
+if [ "$1" ]; then
+ [ -z "$2" ] && echo playlist not defined. continue? && read -p "continue? (press any key)"
+ youtube-dl --get-filename -o "%(title)s----%(id)s----%(channel)s" "$1" > "$file" 2> download_err.txt
+ printf "\n\n"
+
+ i=1
+ max=$(( $(wc -l "$file" | sed 's/ .*//g') ))
+ while :; do
+ printf "insert into ytlist values('$(head -n $i $file | tail -n 1 | sed "s/'/''/g" | sed "s/----/','/g" )','$2','')" | sqlite3 ./youtube_stuffs.db
+ printf "insert: $i\n"
+ ((i=$i+1))
+ if (( $i >= $max + 1 )); then
+ break
+ fi
+ done
+ echo ----PLAYLIST DONE
+ read -p "continue? (Y,n)" input
+ [ "$input" == "n" ] && exit 1;
+ [ "$input" == "N" ] && exit 1;
+fi
+
+
+echo ----Downloading Thumbnails
+i=1
+max=$(( $(sqlite3 ./youtube_stuffs.db 'select rowid from ytlist order by rowid desc limit 1;') ))
+while :; do
+ urlid="$(sqlite3 ./youtube_stuffs.db 'select id from ytlist where rowid='$i';')"
+ if [ -z "$(ls -l thumbnails | grep ".$urlid")" ]; then
+ printf "$i::$urlid\n"
+ thumbnailurl="$(youtube-dl --get-thumbnail "https://youtube.com/watch?v=$urlid" 2> thumberr.txt)"
+ ext="$(printf "$thumbnailurl" | sed 's/.*\.//g' | sed 's/?.*//')"
+ wget "$thumbnailurl" -O "thumbnails/$urlid.$ext"
+ fi
+
+ ((i=$i+1))
+ if (( $i >= $max + 1 )); then
+ break
+ fi
+done
diff --git a/get_yt2.sh b/get_yt2.sh
new file mode 100755
index 0000000..cbcdb4f
--- /dev/null
+++ b/get_yt2.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+FZF_PREVIEW_LINES=20
+FZF_PREVIEW_COLUMN=3
+
+
+cd "$(dirname "$0")"
+has_chafa=$1
+! command -v chafa >/dev/null && has_chafa=0
+
+if [ "$has_chafa" == "1" ]; then
+item="$(sqlite3 ./youtube_stuffs.db "select rowid,* from ytlist" | \
+ fzf --preview "./preview.sh {} | xargs chafa --clear -f iterm -s ${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}" \
+ | sed 's/|.*//g')"
+else
+item="$(sqlite3 ./youtube_stuffs.db "select rowid,* from ytlist" | \
+ fzf \
+ | sed 's/|.*//g')"
+fi
+
+url=$(sqlite3 ./youtube_stuffs.db "select id from ytlist where rowid=$item")
+printf "https://youtube.com/watch?v=$url" | xclip -selection clipboard
diff --git a/preview.sh b/preview.sh
new file mode 100755
index 0000000..54db33b
--- /dev/null
+++ b/preview.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+rowid="$(echo $1 | sed 's/|.*//g')"
+thumbnail="$(ls thumbnails/ | grep "$(sqlite3 ./youtube_stuffs.db "select id from ytlist where rowid=$rowid;").*" )"
+printf "thumbnails/$thumbnail"
diff --git a/watch.sh b/watch.sh
new file mode 100755
index 0000000..2b0b318
--- /dev/null
+++ b/watch.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+while :; do
+ clear
+ sqlite3 --markdown ./youtube_stuffs.db 'select * from ytlist order by rowid desc limit 30;'
+ sleep 3s
+done
diff --git a/youtube_stuffs.db.def b/youtube_stuffs.db.def
new file mode 100644
index 0000000..d373d2f
--- /dev/null
+++ b/youtube_stuffs.db.def
Binary files differ