Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drastically Improve Tutorialvids #1315

Closed
wants to merge 1 commit into from
Closed

Conversation

emrakyz
Copy link
Contributor

@emrakyz emrakyz commented Apr 26, 2023

This script can be combined with: #1320

Video Example Below (30 sec)

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.
  • Right now, Luke Smith has 450 videos on YouTube, so any of them can be chosen rather than some of them.
  • Requires: mpv | yt-dlp | dmenu | cut | grep | echo | jq

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.

Video Example:

tutorialvids.mp4

Detailed Explanation of Commands:

  • CHANNEL_URL="https://www.youtube.com/@LukeSmithxyz/videos": Sets the YouTube channel URL to be fetched.
  • DATA_FILE="$HOME/.cache/lukesmithyt.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.

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.
@emrakyz emrakyz closed this Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant