#!/bin/bash/ #################### #### START CONFIG #### finalDest=/path/of/sovigall/videos/ tempDest=/path/of/sovigall/tmp/ pageCache=/path/of/sovigall/pagecache/ threads=1 # nb cpu core - 1 convertingTool=/usr/bin/ffmpeg mimeMagic=/etc/mime.types #### END CONFIG #### #################### cd $tempDest nbProcessLauch=$(ps -ef | grep -v grep | grep youtube-dl | wc -l) nbEncodeLauch=$(ps -ef | grep -v grep | grep "$convertingTool" | wc -l) if [ "$nbProcessLauch" -ne 0 ] || [ "$nbEncodeLauch" -ne 0 ] then exit fi for file in $tempDest*.hash do if [ -f $file ]; then while read ddl urlHash url destination do if [ "$ddl" -eq 0 ] then youtube-dl -c --write-thumbnail --write-info-json --prefer-free-formats --no-check-certificate -f "[height <=?720]" -o "$urlHash.raw" "$url" if [ ! -f $urlHash.*.jpg ] then eval $convertingTool -i $urlHash.raw -vframes 1 -an -ss 3 $urlHash.jpg fi convert "$urlHash.jpg" -resize 260 "$urlHash.thumb.jpg" mimeFile=$(file --mime-type -b "$urlHash.raw") if [ "$mimeFile" != "video/webm" ] then createDate=$(stat -c %y $urlHash.raw 2>&1 | awk '{print$1}' | sed 's/[\-]//g') eval $convertingTool -i $urlHash.raw -threads $threads -cpu-used 0 -c:v libvpx -crf 18 -b:v 700K -c:a libvorbis -qscale:a 4 -metadata creation_time="$createDate" $urlHash.webm else mv $urlHash.raw $urlHash.webm fi else wget -c -O $urlHash.webm $url #exit mimeFile=$(file --mime-type -b "$urlHash.webm") if [[ "$mimeFile" != "video/webm" ]] then eval $convertingTool -i $urlHash.webm -threads $threads -cpu-used 0 -c:v libvpx -crf 18 -b:v 700K -c:a libvorbis -qscale:a 4 -metadata creation_time="$createDate" $urlHash.webm fi eval $convertingTool -i $urlHash.webm -vframes 1 -an -ss 3 $urlHash.jpg convert "$urlHash.jpg" -resize 260 "$urlHash.thumb.jpg" sizeOfVideo=$(eval $convertingTool -i "$urlHash.webm" 2>&1 | grep "Stream #0:0" | awk '{print $6}' | tr -d ,) duration=$(eval $convertingTool -i "$urlHash.webm" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,) createDate=$(stat -c %y $urlHash.raw 2>&1 | awk '{print$1}' | sed 's/[\-]//g') echo '{' > $urlHash.info.json echo "\"url\"":"\"$url\"," >> $urlHash.info.json echo "\"format\"": "\"22 - $sizeOfVideo\"," >> $urlHash.info.json echo "\"duration\"": "\"22 - $duration\"," >> $urlHash.info.json echo "\"upload_date\"":"\"$createDate"\" >> $urlHash.info.json echo '}' >> $urlHash.info.json fi if [ ! -f $urlHash.*.part ] then if [ -f "$urlHash.webm" ] then rm $urlHash.raw sleep 2 rm $urlHash.hash sleep 2 mv $urlHash* $destination fi else mv $file $file.error fi done < $file rm $pageCache*.html fi done