mirror of
https://github.com/LukeSmithxyz/voidrice.git
synced 2026-03-20 01:37:45 +01:00
Drastically Improve Tutorialvids
The script performs the following tasks:
- Checks if a local cache file containing YouTube video titles and URLs exists.
- If the file does not exist, it fetches video titles and URLs using yt-dlp and saves them to the local cache file.
- Prompts the user whether to update the database (local cache file) using dmenu.
- If the user chooses to update the database, the script fetches the latest video titles and URLs and updates the cache file.
- Displays the video titles in dmenu for the user to select.
- Once a video is selected, the script plays the video using the mpv video player.
Detailed Explanation of Commands:
- CHANNEL_URL="https://www.youtube.com/c/CHANNEL_NAME/videos": Sets the YouTube channel URL to be fetched.
- DATA_FILE="$HOME/.cache/yt_channel_data.tsv": Sets the file path for storing the fetched video titles and URLs.
- [ ! -f "$DATA_FILE" ] && yt-dlp -j --flat-playlist --skip-download "$CHANNEL_URL" | jq -r '[.title, .id] | @tsv' > "$DATA_FILE": Checks if the cache file exists. If not, it uses yt-dlp to fetch the video titles and URLs in JSON format, then pipes the JSON to jq to extract the title and URL, formats them as tab-separated values (TSV), and saves the output to the cache file.
- [ "$(echo -e "No\nYes" | dmenu -i -l 2 -p "Update?")" == "Yes" ] && yt-dlp -j --flat-playlist --skip-download "$CHANNEL_URL" | jq -r '[.title, .id] | @tsv' > "$DATA_FILE": Asks the user if they want to update the database using dmenu. If the user selects "Yes", the script fetches the latest video titles and URLs and updates the cache file.
- video_info=$(cat "$DATA_FILE"): Reads the contents of the cache file and stores them in the video_info variable.
- selected_title=$(echo "$video_info" | cut -f1 | dmenu -i -l 20 -p "Video:"): Displays the video titles in dmenu for the user to select and stores the selected title in the selected_title variable.
- [ -n "$selected_title" ] && mpv "https://www.youtube.com/watch?v=$(echo "$video_info" | grep -Fw "$selected_title" | cut -f2)": If a title is selected, it finds the corresponding URL from the video_info variable and plays the video using the mpv video player.
Justification for the script:
- Highly Minimalistic: The script is concise and straightforward, making it easy to understand and maintain.
- Caching: The script stores the fetched video titles and URLs in a local cache file, reducing the need to fetch data repeatedly, which saves time and bandwidth.
- User-friendly: The script uses dmenu to provide a simple and intuitive interface for the user to interact with, allowing them to update the database and select videos with ease.
- Versatility: The script works with any YouTube channel by simply changing the CHANNEL_URL variable.
- Modular: The script is organized into separate tasks, which can be easily modified or extended to accommodate additional features or requirements.
This commit is contained in:
parent
77fd62b9f3
commit
42a76893c2
@ -1,26 +1,14 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# This gives the user a list of videos they can select and watch without a
|
||||
# browser. If you want to check a tutorial video, it makes it easy. I'll
|
||||
# add/remove videos from this list as I go on.
|
||||
CHANNEL_URL="https://www.youtube.com/@LukeSmithxyz/videos"
|
||||
DATA_FILE="$HOME/.cache/lukesmithyt.tsv"
|
||||
|
||||
vidlist="
|
||||
dwm (window manager) https://videos.lukesmith.xyz/videos/watch/f6b78db7-b368-4647-bc64-28c08fff1988
|
||||
dwmblocks (status bar) https://videos.lukesmith.xyz/w/mmxHMbqZZEr5FManB57Yy1
|
||||
pacman (installing/managing programs) https://videos.lukesmith.xyz/videos/watch/8e7cadb9-0fed-47ce-a2a8-6635fa48614b
|
||||
sxiv (image viewer) https://videos.lukesmith.xyz/videos/watch/ad4c8d85-90c3-4f3d-a1f3-89129e64a3c2
|
||||
st (terminal) https://videos.lukesmith.xyz/videos/watch/efddd39d-bac5-4599-b572-177beb4ce6e8
|
||||
i3 (old window manager) https://videos.lukesmith.xyz/videos/watch/b861525c-7ada-40ee-a2bb-b5e1ffe0f48b
|
||||
neomutt (email) https://videos.lukesmith.xyz/videos/watch/83122e83-52d9-4278-ae1a-7d1beeb50c8e
|
||||
ncmpcpp (music player) https://videos.lukesmith.xyz/videos/watch/b5ac6f0d-a220-4433-88e3-e98fc791dc0a
|
||||
newsboat (RSS reader) https://videos.lukesmith.xyz/videos/watch/bd2c3fff-40fa-47ea-aa98-5b1ec0c903b6
|
||||
lf (file manager) https://videos.lukesmith.xyz/w/rKeHsF5ZHDNDbR1buUKB1c
|
||||
zathura (pdf viewer) https://videos.lukesmith.xyz/videos/watch/c780f75a-11f6-48a9-a191-d079ebc36ea4
|
||||
gpg keys https://videos.lukesmith.xyz/videos/watch/040f5530-4830-4583-9ddc-2080b421531b
|
||||
calcurse (calendar) https://videos.lukesmith.xyz/videos/watch/4b937e8b-7654-46e3-8d01-79392ec5b3d1
|
||||
urlview https://videos.lukesmith.xyz/videos/watch/31a4918f-633b-4bd6-b08e-956ac75d0324
|
||||
colorschemes with pywal https://videos.lukesmith.xyz/videos/watch/1b476003-61b2-4609-ac4b-820c3d128643
|
||||
vi mode in shell https://videos.lukesmith.xyz/videos/watch/228aa50c-836f-456f-9f0d-a45157fe4313
|
||||
pass (password manager) https://videos.lukesmith.xyz/videos/watch/432fc942-5e28-4682-9beb-f5cb237a1dd6
|
||||
"
|
||||
echo "$vidlist" | grep -P "^$(echo "$vidlist" | grep "https:" | sed 's/\t.*//g' | dmenu -i -p "Learn about what? (ESC to cancel)" -l 20 | awk '{print $1}')\s" | sed 's/.*\t//' | xargs -r mpv
|
||||
[ ! -f "$DATA_FILE" ] && yt-dlp -j --flat-playlist --skip-download "$CHANNEL_URL" | jq -r '[.title, .id] | @tsv' > "$DATA_FILE"
|
||||
|
||||
[ "$(echo -e "No\nYes" | dmenu -i -l 2 -p "Update?")" == "Yes" ] && yt-dlp -j --flat-playlist --skip-download "$CHANNEL_URL" | jq -r '[.title, .id] | @tsv' > "$DATA_FILE"
|
||||
|
||||
video_info=$(cat "$DATA_FILE")
|
||||
|
||||
selected_title=$(echo "$video_info" | cut -f1 | dmenu -i -l 20 -p "Video:")
|
||||
|
||||
[ -n "$selected_title" ] && mpv "https://www.youtube.com/watch?v=$(echo "$video_info" | grep -Fw "$selected_title" | cut -f2)"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user