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
  • katy ✨@piefed.blahaj.zone
    link
    fedilink
    English
    arrow-up
    4
    ·
    2 days 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
        ·
        2 days 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)

  • GarbadgeGoober@feddit.org
    link
    fedilink
    arrow-up
    6
    ·
    3 days 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
      ·
      2 days 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.

  • EccTM@lemmy.ml
    link
    fedilink
    English
    arrow-up
    3
    ·
    3 days ago

    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-paste attached) 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
      fi
    
  • TechnoCat@piefed.social
    link
    fedilink
    English
    arrow-up
    8
    ·
    3 days 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  
    
  • NewDawnOwl@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    3 days ago

    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)

  • NorthWestWind@lemmy.world
    link
    fedilink
    arrow-up
    8
    ·
    3 days 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
    
  • DarkSpectrum@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    2 days 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.

  • urhovaldeko@lemmy.world
    link
    fedilink
    arrow-up
    52
    ·
    3 days 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
      11
      ·
      2 days 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.