Haiku scripting

[Edited to use yt-dlp instead of the discontinued youtube-dl]

This is a script that I’ve been using for a while now to download video clips. It uses yt-dlp for the list of supported_sites and wget for all others.
Make it executable, put it on the Desktop, then just copy the clip URL to the clipboard and double-click the script.

If your network connection is fast enough, give it a few seconds to buffer and watch the clip with MediaPlayer while it downloads. (This is pretty much what Ubertuber does, only this script works much more reliably… :stuck_out_tongue: )

    #!/bin/sh

    # The script takes the contents of the clipboard and downloads it
    # with either yt-dlp or - if not a supported site - wget
    #
    # Usage:	0 a) install yt-dlp from HaikuDepot
    #			0 b) make script executable and put it on the Desktop
    #			1) copy a clip URL
    #			2) double click script to download to Desktop

    supported_sites="youtube youtu.be vimeo"
    destination=~/Desktop
    clip=$(clipboard -p)

    cd $destination

    # Use youtube-dl if the clip comes from a supported site
    for item in $supported_sites ; do
    	if [[ $clip == *"$item"* ]] ; then
    	# get the clip's filename
    		filename=$(yt-dlp --restrict-filenames --no-part \
    			--no-cache-dir --get-filename "$clip")
    	# download clip in best quality
    		yt-dlp --continue --restrict-filenames --no-part \
    			--no-cache-dir "$clip"
    	# add the clip's URL as attribute
    		addattr META:url "$clip" "$filename"
    	# identify file type
    	# 	mimeset -F "$filename"
    		exit
    	fi
    done

    # Use wget for anything else
    filename=$(basename "$clip")
    wget "$clip"
    addattr META:url "$clip" "$filename"
    # mimeset -F "$filename"

The META:url attribute stores the download URL for reference. TIP: To display it in a Tracker window, you can temporarily copy a Bookmark file into the clip’s folder, and activate the URL attribute from the Tracker window’s menu.

I commented out the mimeset lines, because then I recognize the unwatched clips by their generic icon. :slight_smile:

7 Likes