Outils pour utilisateurs

Outils du site


bash:youtube-vp9

Youtube-VP9

Ce script à base de youtube-dl récupère la vidéo au format VP9 et la met dans le répertoire courant.

youtube
#!/bin/bash
 
# Polipo HTTP-SOCKS proxy check
systemctl status polipo | grep 'running'
if [ $? == 0 ]; then
	proxyparam='--proxy "localhost:8118"'
else
	proxyparam=''
fi
 
outdir=$(pwd)
touch "$outdir/$$.lock"
 
# extraction titre, date et URL
url="$1"
title=$(youtube-dl --get-title "$url")
title=$(echo $title | sed 's/?//')
title=$(echo $title | sed 's/#//')
title=$(echo $title | sed 's/\//_/')
title=$(echo $title | sed 's/:/-/')
datestring=$(youtube-dl -qs --get-filename -o '%(upload_date)s' "$url")
datestamp=$(date -d "$datestring" +%s)
echo "Title: $title"
echo "Uploaded: $datestamp  (YYYYMMDD $datestring)"
 
# mise en place du dossier de travail
hashfold=$(echo "$title" | sha1sum)
mkdir -p "/tmp/youtube-dash/$hashfold"
cd "/tmp/youtube-dash/$hashfold"
 
if [ -f "$outdir/$title.webm" ]; then
	echo "*** warning: file already exists ***"
	rm "$outdir/$$.lock"
	exit
fi
 
# récupération flux vidéo 1080p→720p→480p→360p→240p
youtube-dl -f 248/247/244/243/242 $proxyparam -o "/tmp/youtube-dash/$hashfold/1" "$url"
# récupération flux audio 128k
youtube-dl -f 171 $proxyparam -o "/tmp/youtube-dash/$hashfold/2" "$url"
 
if [ -f "/tmp/youtube-dash/$hashfold/1" ]; then
	# composition du fichier et timestampage, transfert vers dossier courant et nettoyage
	ffmpeg -i "1" -i "2" -c:v copy -c:a copy "$title.webm"
	touch -d "@$datestamp" "$title.webm"
	mv "$title.webm" "$outdir/$title.webm"
else
	echo "*** file not downloaded: couldn't connect, or no such format ? ****"
fi
 
rm -r "/tmp/youtube-dash/$hashfold"
rm "$outdir/$$.lock"
bash/youtube-vp9.txt · Dernière modification: 2014/10/24 09:14 par mitsu