made it so i just click file and paste YouTube url
Linux is amazing
#! /usr/bin/bash
echo "Enter a url"
read a
yt-dlp -x $a
Very happy you had fun making the little script! One thing that will become important pretty quick if you continue making these scripts is that it’s almost always better to wrap your variables in quotes - so it becomes
yt-dlp -x “$a”. It’s okay here but if you ever paste something that has a space in it, this will keep it together ‘as one’.If you want to expand your knowledge with this, some fruitful paths to go down are the following:
- can you find a way to download multiple urls one after the other if you paste them all at once? (Multiple arguments)
- can you find a way to ask the user for these multiple urls one after the other? (loops)
- and can you find a way to have it ask until you hit enter without a url pasted and only then it starts? (conditionals and test)
The last one is already quite a bit advanced but if you can do that you have enough of the ‘programming’ basics of the shell down to a degree that you can create many little helpers like this with ease.
Of course don’t feel forced to do any of that - if you’re happy with the improvement as-is, that’s all you need to enjoy the fun of Linux!
Well done, I never could use bash much but can’t deny its useful
I have a similar scriptlet that I use to open YouTube URLs in mpv, using just and wl-clipboard… I just copy the URL and press my G1 key (it has a keybind of
just yt-pasteattached) which launches the yt-paste snippet below, reads the url from the clipboard, parses it and passes it to mpv.# Parse the clipboard for YouTube URLs and open them in mpv yt-paste: #!/usr/bin/env bash YOUTUBE_URL_REGEX="^https:\/\/(www\.youtube\.com\/watch\?v=|youtu\.be\/)[a-zA-Z0-9_-]{11}" YOUTUBE_PLAYLIST_URL_REGEX="^https:\/\/(www\.youtube\.com\/playlist\?list=)[a-zA-Z0-9_-]+" YOUTUBE_SHORTS_URL_REGEX="^https:\/\/(www\.youtube\.com\/shorts\/)[a-zA-Z0-9_-]{11}" # Youtube URL if [[ "$(wl-paste)" =~ $YOUTUBE_URL_REGEX ]]; then echo "Opening valid YouTube URL" >&2 notify-send --app-name="YT-Paste" --icon=mpv --transient "Opening YouTube URL" mpv "$(wl-paste)" # Youtube Playlist URL elif [[ "$(wl-paste)" =~ $YOUTUBE_PLAYLIST_URL_REGEX ]]; then echo "Opening valid YouTube Playlist URL" >&2 notify-send --app-name="YT-Paste" --icon=mpv --transient "Opening YouTube Playlist URL" mpv "$(wl-paste)" # Youtube Short URL elif [[ "$(wl-paste)" =~ $YOUTUBE_SHORTS_URL_REGEX ]]; then echo "Opening valid YouTube Shorts URL" >&2 notify-send --app-name="YT-Paste" --icon=mpv --transient "Opening YouTube Shorts URL" mpv "$(wl-paste)" # No Match else echo "Clipboard does not contain a valid YouTube URL" >&2 notify-send --app-name="YT-Paste" --icon=mpv --transient "Whoops!" "Clipboard does not contain a valid YouTube URL" exit 1 fiOne of us! One of us!
You’ll probably like this youtube channel then :)
hell yeah
Hell yeah




