made my first bash file to make yt-dlp easier
submitted by
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:
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!
Oh man, this reminds me of the joke that any program that’s more complex than Hello World has bugs – and folks still don’t even agree how to spell “Hello, World!”.
Of course, Bash is a particular minefield in this regard…
I once wrote a 2 line, 10 word script that had 9 bugs in it. I’m not overly proud of that one.
I think you might have a career as an accomplished entymologist ahead of you with so much success finding bugs!
Thanks might make it bigger now. The “$a” very helpful as I might copy url from web pages which may cause a error.
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.
I like fixing things but getting paid to do it is the hard part. I also want to give back to Linux community even if it is small.
You all forgot to add the best yt-dlp option:
--sponsorblock-remove allthank you
You’ll probably like this youtube channel then :)
https://www.youtube.com/@BreadOnPenguins
Or this one: https://www.youtube.com/channel/UCMN0a7GHQnC6H74SmCGSmdw
Thanks looks good
One of us! One of us!
Hell yeah
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 $1Now 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
The op script is meant to be opened in the GUI in a terminal then the URL gets pasted in there. It took me a second to see it.
What does your ~/.bashrc look like? My last change was modifying a
playlistcommandspoiler: I explain my last change to my ~/.bashrc file
or
or just from any directory with files
And then takes all the videos found at the url or at the path (including within folders), adds them to a playlist, shuffles them, and plays them from mpv.
other functions and aliases in my ~/.bashrc
I wonder if we have the same resize.sh
The version I have was copied from stackoverflow. It doesn’t work very well, it makes a rough estimate to get the video file size under the set value. As an example
Which then resizes the video to 10 megabytes if possible.
resize.sh code
I’ll probably replace it eventually.
Definitely not the same lol
Mine uses ffmpeg to change the resolution, it doesn’t so much care about file sizes.
It could be a one-liner if you only ever feed it a single file to manipulate..
I might add one for scaling. I just don’t use it as frequently as trying to meet a file size limit. The scaling is also much easier to remember
It does get complicated though, when scaling many videos and images, I’ve used something like the following in the past
Those were the only two that showed up when I typed
history | grep scale.after commenting, I also added a new video file resizer.
It works significantly better than the one I previously posted. It’s also copied from stackoverflow.
Here is a script I wrote:
does –write-thumbnail save a jpg with the video? or is it something else?
You’re correct!
There is also this option:
makes note of this since it will make tagging a lot easier and also cataloging for jellyfin
Guess we’re sharing scripts now. I have a script that downloads playlists as MP3s and keep an archive.
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. 🤣
DJT, best Linux promoter of 2025 :P
this isn’t perfect but i made one when i wanted to fetch a video for a specific resolution (because i prefer 480)
Just curious, but why 480?
usually i just like older videos but in this case i was saving a bunch of wcw vault videos to my jellyfin library and i prefer 480 since it was as close to tv as can be (also i’ve never been a fan of hd and tv after 2000 because i felt that’s when it went downhill)
You’ve got me beat. I just have a text file with some common usage examples in it.
I do the same, for the commands I forget. Joplin is also handy for making longer notes.
Check out atuin, when you press arrow up in the terminal it shows a history list that is also searchable.
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)
hell yeah
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.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”.
I made this for easy use so no typing or terminal. some people like to do thing differently and that’s ok
When you
read a, you’re typing in terminal. I made a clipboard action so I just copy an URL to the clipboard, execute actions, and then choose whether to play it or download it on my other machine.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.
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.Well done, I never could use bash much but can’t deny its useful
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
Then you would just need to source your bashrc to load it the first time.
this is neat, thanks!
awesome! I never would have thought to make something like that.
I simply using local LLM for it