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
you are viewing a single comment's thread
view the rest of the comments
[–] 7 points 8 months ago* (last edited 8 months ago) (6 children)

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

  • source
  • hideshow 6 child comments
  • [–] 2 points 8 months ago* (last edited 8 months ago) (4 children)

    What does your ~/.bashrc look like? My last change was modifying a playlist command

    spoiler: I explain my last change to my ~/.bashrc file

    playlist https://www.youtube.com/@YouTube/videos
    

    or

    playlist /home/username/Videos
    

    or just from any directory with files

    playlist
    

    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.

    playlist() {
            param=""
    
            # If the first parameter has a length more than 1 character
            if [ ${#1} -gt 1 ]; then
                    param="${@}"
            else
                    param="."
            fi
    
            screen mpv $param --shuffle --ytdl-raw-options-add=cookies-from-browser=firefox --loop-playlist=inf --no-keepaspect-window --no-auto-window-resize
    }
    

    other functions and aliases in my ~/.bashrc

    alias code=codium
    alias files=nautilus
    alias explorer=nautilus
    alias rust="/path/to/.cargo/bin/evcxr"
    alias sniffnet="export ICED_BACKEND=tiny-skia; /path/to/.cargo/bin/sniffnet"
    alias http-server='/path/to/.cargo/bin/miniserve'
    alias iphone='uxplay'
    alias airplay='uxplay'
    alias watch='screen mpv --ytdl-raw-options-add=remote-components=ejs:github --ytdl-raw-options-add=cookies-from-browser=firefox --no-keepaspect-window '
    alias twitch='watch'
    alias timeshift-launcher="pkexec env WAYLAND_DISPLAY='$WAYLAND_DISPLAY' XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR' /usr/bin/timeshift-launcher"
    alias update="sudo apt update && sudo apt upgrade -y && sudo flatpak update -y && sudo snap refresh"
    alias resize="path/to/resize/videos/resize.sh"
    
    playlist() {
            param=""
    
            # If the first parameter has a length more than 1 character
            if [ ${#1} -gt 1 ]; then
                    param="${@}"
            else
                    param="."
            fi
    
            screen mpv $param --shuffle --ytdl-raw-options-add=cookies-from-browser=firefox --loop-playlist=inf --no-keepaspect-window --no-auto-window-resize
    }
    
    gif() { ffmpeg -i $1 -f yuv4mpegpipe - | gifski -o $2 ${@:3} -;}
    

  • source
  • parent
  • hideshow 4 child comments
  • [–] 1 point 8 months ago (3 children)

    I wonder if we have the same resize.sh

  • source
  • parent
  • hideshow 3 child comments
  • [–] 1 point 8 months ago (2 children)

    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

    resize video.mp4 10
    

    Which then resizes the video to 10 megabytes if possible.

    resize.sh code

    file=$1
    target_size_mb=$2  # target size in MB
    target_size=$(( $target_size_mb * 1000 * 1000 * 8 )) # target size in bits
    length=`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file"`
    length_round_up=$(( ${length%.*} + 1 ))
    total_bitrate=$(( $target_size / $length_round_up ))
    audio_bitrate=$(( 128 * 1000 )) # 128k bit rate
    video_bitrate=$(( $total_bitrate - $audio_bitrate ))
    ffmpeg -i "$file" -b:v $video_bitrate -maxrate:v $video_bitrate -bufsize:v $(( $target_size / 20 )) -b:a $audio_bitrate "${file}-${target_size_mb}mb.mp4"
    

    I'll probably replace it eventually.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 8 months ago* (1 child)

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

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 8 months ago

    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

    ffmpeg -i  in.mp4 -vf "scale=600:-1" -an out.mp4
    

    It does get complicated though, when scaling many videos and images, I've used something like the following in the past

    find .  -exec ffmpeg -i {} -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1:color=black" {}.mp4 \;
    

    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.

    bitrate="$(awk "BEGIN {print int($2 * 1024 * 1024 * 8 / $(ffprobe \
        -v error \
        -show_entries format=duration \
        -of default=noprint_wrappers=1:nokey=1 \
        "$1" \
    ) / 1000)}")k"
    ffmpeg \
        -y \
        -i "$1" \
        -c:v libx264 \
        -preset medium \
        -b:v $bitrate \
        -pass 1 \
        -an \
        -f mp4 \
        /dev/null \
    && \
    ffmpeg \
        -i "$1" \
        -c:v libx264 \
        -preset medium \
        -b:v $bitrate \
        -pass 2 \
        -an \
        "${1%.*}-$2mB.mp4"
    

  • source
  • parent