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
  • DarkSpectrum@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    7 hours ago

    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.

  • JTskulk@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    7 hours ago

    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”.

  • urhovaldeko@lemmy.world
    link
    fedilink
    arrow-up
    44
    ·
    1 day ago

    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.

    • RavenofDespair@lemmy.mlOP
      link
      fedilink
      arrow-up
      5
      ·
      17 hours ago

      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.

  • katy ✨@piefed.blahaj.zone
    link
    fedilink
    English
    arrow-up
    3
    ·
    16 hours ago

    this isn’t perfect but i made one when i wanted to fetch a video for a specific resolution (because i prefer 480)

    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"  
    }  
    
      • katy ✨@piefed.blahaj.zone
        link
        fedilink
        English
        arrow-up
        1
        ·
        9 hours ago

        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)

  • hoppolito@mander.xyz
    link
    fedilink
    English
    arrow-up
    64
    ·
    1 day ago

    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!

    • RavenofDespair@lemmy.mlOP
      link
      fedilink
      arrow-up
      2
      ·
      17 hours ago

      Thanks might make it bigger now. The “$a” very helpful as I might copy url from web pages which may cause a error.

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      8
      ·
      edit-2
      1 day ago

      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.

      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…

      • 18107@aussie.zone
        link
        fedilink
        English
        arrow-up
        16
        ·
        1 day ago

        I once wrote a 2 line, 10 word script that had 9 bugs in it. I’m not overly proud of that one.

        • draco_aeneus@mander.xyz
          link
          fedilink
          arrow-up
          5
          ·
          1 day ago

          I think you might have a career as an accomplished entymologist ahead of you with so much success finding bugs!

  • kittenroar@beehaw.org
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    15 hours ago

    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.

  • GarbadgeGoober@feddit.org
    link
    fedilink
    arrow-up
    6
    ·
    1 day ago

    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. 🤣

    • RavenofDespair@lemmy.mlOP
      link
      fedilink
      arrow-up
      3
      ·
      16 hours ago

      No worries on vim after being unable to exit and having to Google the answer. thighsocks do look very nice will add it to list of girly things I like to do cooking, sewing, origami and romance comics.

  • TechnoCat@piefed.social
    link
    fedilink
    English
    arrow-up
    8
    ·
    1 day ago

    Here is a script I wrote:

    ~/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  
    
      • TechnoCat@piefed.social
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        5 hours ago

        You’re correct!

               --write-thumbnail  
                      Write thumbnail image to disk  
        

        There is also this option:

               --embed-thumbnail  
                      Embed thumbnail in the video as cover art  
        
  • chunes@lemmy.world
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    1 day ago

    You’ve got me beat. I just have a text file with some common usage examples in it.

      • aqua@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        7 hours ago

        Check out atuin, when you press arrow up in the terminal it shows a history list that is also searchable.

  • NorthWestWind@lemmy.world
    link
    fedilink
    arrow-up
    7
    ·
    1 day ago

    Guess we’re sharing scripts now. I have a script that downloads playlists as MP3s and keep an archive.

    #!/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