Skip to content

Instantly share code, notes, and snippets.

@ushiocheng
Created January 18, 2023 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ushiocheng/ac77d5b78d5afa3cd696faa08a51f609 to your computer and use it in GitHub Desktop.
Save ushiocheng/ac77d5b78d5afa3cd696faa08a51f609 to your computer and use it in GitHub Desktop.
#!/bin/sh
# ------------- Script INFOs -------------
# Script Name: download-videos.sh
# Create Date: 2021-02-25
# Version #: 1.2
# Author: github@ushio-cheng
# Description: - Accept 2 parameter <path to a list of video links> [path to output video]
# - Downloads all videos in the list by spawning screen session
# - Will retry if youtube-dl failed
# Remark: - This is sketchy but simple way to download a list of stuff
# - configure youtube-dl to use aria to avoid downloading the
# same video segment multiple times
# ----------------------------------------
function mainScript() {
workerUID=0
if [ ! $1 ]
then
echo "ERROR: videolist file not provided"
exit
fi
for line in $(cat $1)
do
spawnDownloadWorker "$2" "$(basename -s .txt $1)-$workerUID" $line
workerUID=$(( $workerUID + 1 ));
done
}
# spawn workers
# param1: work dir
# param2: workerName
# param3: assignedUrl
spawnDownloadWorker () {
if [ $1 ]
then
cd $1
fi
workerTaskUID=$(uuidgen)
echo "while ! youtube-dl --recode-video mp4 -o \"[%(id)s] %(title)s.%(ext)s\" "$3";" >> $workerTaskUID.sh
echo "do sleep 3;done" >> $workerTaskUID.sh # wait 3s before try again
echo "rm $workerTaskUID.sh" >> $workerTaskUID.sh
screen -dmLS "$2" sh $workerTaskUID.sh
}
# Run
mainScript $1 $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment