summaryrefslogblamecommitdiffstats
path: root/skripti/365_prenesi_omejene_vsebine.sh
blob: 510b0c1984825700e9ab3eeb20607e240c1c96dd (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                                                                      













                                                                                                                                                                   

                       
                                                                                         
                                                                                               








                                                                                                                      
                                                                                                             


                     
                                                                                             


                        

                                                                

                                
#!/bin/bash
# program poženi enkrat na dan (cronjob) v direktoriju za arhiviranje
# v datoteko zadnji shrani ID zadnje preverjene vsebine
# ko preveri vso vsebino od zadnje preverjene vsebine, se zapre
# ko naleti na vsebino, ki poteče, jo prenese
# če datoteka zadnji ne obstaja, vzame ID zadnjega dnevnika
set -euo pipefail
page=`curl --fail-with-body https://365.rtvslo.si/oddaja/dnevnik/92` # outputa preveč shita za set -x
set -x
find . -size -12M -type f -name '*.mp4' | while read file
do # grep for specific audio codec ... if sample rate is 44100 and (tv broadcast is at 48000) and smaller than 12M, it's most likely the dummy/pravicepotekle video
	samplerate=`ffprobe "$file" 2>&1 | grep 0x6134706D | grep -Eo '[0-9]+ Hz' | cut -d\  -f1`
	id=`grep -Eo "\[[0-9]+\]\.mp" <<<"$file" | grep -o '[0-9]*'`
	if [ $samplerate -eq 48000 ]
	then
		continue
	fi
	if [ $samplerate -eq 44100 ]
	then
		yt-dlp --no-continue http://365.rtvslo.si/arhiv/oddaja/$id # retry fu*ked up downloads
		continue
	fi
	echo -e "Subject: unknown samplerate in 365.sh\n\nVideo file: $file\nsamplerate: $samplerate\n" | sendmail root
done
rm -f Error\ \[*\].mp4 
dnevnik_id=`grep href=./arhiv/dnevnik <<<"$page" | cut -d\" -f2 | cut -d/ -f4 | head -n1`
client_id=`grep 'client-id="' <<<"$page" | head -n1 | sed -E 's/^.*client-id="([^"]*)".*$/\1/'`
if [ ! -f zadnji ]
then
	echo $dnevnik_id > zadnji
fi
id_oddaje=`cat zadnji`
while :
do
	id_oddaje=$(($id_oddaje+1))
	api_response=`curl --fail-with-body https://api.rtvslo.si/ava/getRecordingDrm/$id_oddaje?client_id=$client_id`
	if [ "`jq --raw-output .response.title <<<$api_response`" = Error ] && [ $dnevnik_id -lt $id_oddaje ]
	then
		break
	fi
	if [ "`jq --raw-output .response.expirationDate <<<$api_response | head -c1`" = "3" ]
	then
		continue
	fi
	# echo $api_response > $id_oddaje.json
	yt-dlp http://365.rtvslo.si/arhiv/oddaja/$id_oddaje || :
	echo $id_oddaje > zadnji
done