Post #424015
2026-02-22 20:33 UTC
Replies (24)
-
@osanna@thebrainbin.org 2026-02-23 06:27
awesome! I never would have thought to make something like that.
-
@hoppolito@mander.xyz 2026-02-22 22:15
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!
-
@urhovaldeko@lemmy.world 2026-02-23 07:26
Stop right now. This will all end in tears. You’ll become a developer and spend the rest of your life fixing bugs. You can still get out.
-
@MagnificentSteiner@lemmy.zip 2026-02-22 21:14
You'll probably like this youtube channel then :) https://www.youtube.com/@BreadOnPenguins
-
@JamonBear@sh.itjust.works 2026-02-23 17:28
You all forgot to add the best yt-dlp option: `--sponsorblock-remove all`
-
@Carl@hexbear.net 2026-02-23 02:07
It's a slippery slope. Soon you'll be using Vim and ordering thighsocks on the Internet.
-
@myrmidex@belgae.social 2026-02-22 20:57
One of us! One of us!
-
@matrixrunner@lemmy.world 2026-02-22 20:40
Hell yeah
-
@BananaTrifleViolin@lemmy.world 2026-02-22 23:38
That's great! Here's a few tips to take it a bit further; the world is your oyster! Open your .bashrc file (e.g. /home/yourusername/.bashrc) and add the following: `alias get="/path/to/your/bash/file"` Now open a terminal and type **get**, and it'll launch the script. No clicking needed, it'll run anytime from any terminal! And if you do use the alias then you can use another refinement, you can drop the echo: instead of $a, you can use **$1** and remove the echo & read as you no longer need them: `#! /usr/bin/bash yt-dlp -x $1 ` Now for example you can type in a terminal: `get http://url.to.video/ ` And yt-dlp will do it's stuff. $1 passes the first parameter after starting the script as a variable to it. You can use the keyboard shortcut **Control+shift+v** to paste a URL into the terminal, no mouse needed; just remember to add a space after typing **get**
-
@TechnoCat@piefed.social 2026-02-23 01:24
Here is a script I wrote: ```fish ~/bin 0s > cat vget #!/usr/bin/env fish yt-dlp --embed-metadata --write-subs --embed-subs --write-thumbnail --prefer-free-formats -f "[height<=1080]" $argv ```
-
@NorthWestWind@lemmy.world 2026-02-23 01:41
Guess we're sharing scripts now. I have a script that downloads playlists as MP3s and keep an archive. ```sh #!/usr/bin/env sh browser_cookies="firefox:1cvnyph7.YouTube TV" download() { url="https://www.youtube.com/playlist?list=%241" dir=$2 archive_name=$3 yt-dlp -x --audio-format mp3 --embed-thumbnail --embed-metadata --cookies-from-browser "$browser_cookies" --download-archive "archives/$archive_name.txt" -P "$dir" -o "%(title)s.%(ext)s" "$url" } download PLPzniwWWCSjVQteWPqVvyu8SQsrStVYwZ high-quality-rips/ rips download PLPzniwWWCSjWZj3-DAOh8ZKrsVReP_Ksm good-playlist/ picks ```
-
@GarbadgeGoober@feddit.org 2026-02-23 07:08
Amazing. Injust switched a year ago and now I finally discovered bash scripts. It is so mich easier, I also automated some manual tasks with Python scripts to name my PDFs, never would have done that with windows. And the best part of it, it's actually fun and I want to even do more. As always I have to thank DJT, for make me switch. 🤣
-
@chunes@lemmy.world 2026-02-23 05:31
You've got me beat. I just have a text file with some common usage examples in it.
-
@cupcakezealot@piefed.blahaj.zone 2026-02-23 15:31
this isn't perfect but i made one when i wanted to fetch a video for a specific resolution (because i prefer 480) ```bash ytgrab() { local id="$1" local res="${2:-480}" # default to 480 local url="https://www.youtube.com/watch?v=%24id" # fetch formats local fmt fmt=$(yt-dlp -F --cookies-from-browser vivaldi "$url") # printing the format output echo "$fmt" # pick video format matching the requested resolution local vfmt vfmt=$(echo "$fmt" | awk -v r="${res}p" '$0 ~ r && /video/ {print $1}' | head -n1) # pick best m4a audio local afmt afmt=$(echo "$fmt" | awk '/m4a/ && /audio/ {print $1}' | head -n1) # safety check if [ -z "$vfmt" ] || [ -z "$afmt" ]; then echo "Could not find matching formats (video ${res}p or m4a audio)." return 1 fi echo fetching: yt-dlp -f ${vfmt}+${afmt} --cookies-from-browser vivaldi --write-subs --no-write-auto-subs --sub-lang "en.*" $url yt-dlp -f "${vfmt}+${afmt}" --write-subs --cookies-from-browser vivaldi --no-write-auto-subs --sub-lang "en.*" "$url" } ```
-
@JTskulk@lemmy.world 2026-02-24 01:07
No offense, but I'm seeing a lot of useless scripts here. You can simply put these option in yt-dlp.conf and then just run yt-dlp "url".
-
@CrabAndBroom@lemmy.ml 2026-02-25 17:23
Nice! I did mine as an alias: `alias yt='yt-dlp --remote-components ejs:github -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4"'` And then just `yt [URL]` downloads the thing.
-
@EccTM@lemmy.ml 2026-02-22 22:52
I have a similar scriptlet that I use to open YouTube URLs in mpv, using [just](https://github.com/casey/just) and [wl-clipboard](https://github.com/bugaevc/wl-clipboard)... I just copy the URL and press my G1 key (it has a keybind of `just yt-paste` attached) which launches the yt-paste snippet below, reads the url from the clipboard, parses it and passes it to mpv. ```bash # 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 fi ```
-
@DarkSpectrum@lemmy.world 2026-02-24 01:13
I self host Pinchflat and have set it up to monitor one of my own yt playlists. Then if I want to download anything on mobile or desktop I just save it to that playlist and it's done.
-
@NewDawnOwl@lemmy.world 2026-02-23 04:25
I love things like this, makes it so easy to learn when it's a really simple to understand and explicit implementation of a high level feature (read input, pass to command)
-
@FEIN@lemmy.world 2026-02-22 22:17
hell yeah
-
@kittenroar@beehaw.org 2026-02-23 16:44
You could make it an alias and shorten the number of keystrokes I prefer keeping my aliases in ~/.bash_aliases, which is sourced in my ~/.bashrc, ie . ~/.bash_aliases Then you would just need to source your bashrc to load it the first time.
-
@texture@lemmy.world 2026-02-23 10:05
this is neat, thanks!
-
@HuePony@lemmy.ml 2026-02-23 19:03
I simply using local LLM for it
-
@draco_aeneus@mander.xyz 2026-02-23 06:52
I think you might have a career as an accomplished entymologist ahead of you with so much success finding bugs!