summaryrefslogtreecommitdiffstats
path: root/skripti/365_prenesi_omejene_vsebine.sh
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-06-08 14:53:59 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2024-06-08 14:53:59 +0200
commitb815858d23f9710557f497a430cfd0cadb1ac82f (patch)
treea8fba9b1867881c50a8c522db7bed097deffd770 /skripti/365_prenesi_omejene_vsebine.sh
parente (diff)
downloadr-b815858d23f9710557f497a430cfd0cadb1ac82f.tar
r-b815858d23f9710557f497a430cfd0cadb1ac82f.tar.gz
r-b815858d23f9710557f497a430cfd0cadb1ac82f.tar.bz2
r-b815858d23f9710557f497a430cfd0cadb1ac82f.tar.lz
r-b815858d23f9710557f497a430cfd0cadb1ac82f.tar.xz
r-b815858d23f9710557f497a430cfd0cadb1ac82f.tar.zst
r-b815858d23f9710557f497a430cfd0cadb1ac82f.zip
Diffstat (limited to 'skripti/365_prenesi_omejene_vsebine.sh')
-rwxr-xr-xskripti/365_prenesi_omejene_vsebine.sh35
1 files changed, 31 insertions, 4 deletions
diff --git a/skripti/365_prenesi_omejene_vsebine.sh b/skripti/365_prenesi_omejene_vsebine.sh
index 510b0c1..16f527d 100755
--- a/skripti/365_prenesi_omejene_vsebine.sh
+++ b/skripti/365_prenesi_omejene_vsebine.sh
@@ -7,7 +7,26 @@
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
+if mkdir lock
+then
+ echo $$ > lock/pid
+else
+ if [ -d /proc/`cat lock/pid` ]
+ then
+ echo ANOTHER INSTANCE IS ALREADY RUNNING
+ echo if you are sure that this is not the case:
+ echo rm -r `pwd`/lock
+ exit 1
+ fi
+fi
+echo $$ > lock/pid
+p=`rev <<<$0 | cut -d/ -f1 | rev`
+t=`mktemp -p "" $p.XXX`
+trap "rm $t; rm -r lock" EXIT
+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/'`
+find . -size -12M -type f -name '*.mp4' > $t
+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]*'`
@@ -15,16 +34,24 @@ do # grep for specific audio codec ... if sample rate is 44100 and (tv broadcast
then
continue
fi
+ api_response=`curl --fail-with-body https://api.rtvslo.si/ava/getRecordingDrm/$id?client_id=$client_id`
+ if [ "`jq --raw-output .response.expirationDate <<<$api_response | head -c1`" = "3" ] || [ $((`date +%s`-86400*3-`date --date "$(jq --raw-output .response.expirationDate <<<$api_response)" +%s`)) -gt 0 ]
+ then
+ rm "$file" # sike, zgleda ne poteče! oziroma sike, je že potekel
+ continue
+ fi
if [ $samplerate -eq 44100 ]
then
yt-dlp --no-continue http://365.rtvslo.si/arhiv/oddaja/$id # retry fu*ked up downloads
+ if [ `ls *\[$id\].mp4 | wc -l` -gt 1 ]
+ then
+ rm "$file" # kdaj se zgodi, da RTV spremeni ime oddaje, tedaj imam staro ime, ki ima shranjen dummy posnetek 7,6 MiB, ki neprestano triggera reload ...
+ fi
continue
fi
echo -e "Subject: unknown samplerate in 365.sh\n\nVideo file: $file\nsamplerate: $samplerate\n" | sendmail root
-done
+done < $t
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