summaryrefslogtreecommitdiffstats
path: root/skripti
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xskripti/365_prenesi_omejene_vsebine.sh32
-rwxr-xr-xskripti/live_hls_archiver.py24
2 files changed, 56 insertions, 0 deletions
diff --git a/skripti/365_prenesi_omejene_vsebine.sh b/skripti/365_prenesi_omejene_vsebine.sh
new file mode 100755
index 0000000..bdc003c
--- /dev/null
+++ b/skripti/365_prenesi_omejene_vsebine.sh
@@ -0,0 +1,32 @@
+#!/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
+dnevnik_id=`grep href=./arhiv/dnevnik <<<"$page" | cut -d\" -f2 | cut -d/ -f4 | head -n1`
+client_id=`grep client-id <<<"$page" | cut -d\" -f2 | head -n1`
+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 ]
+ then
+ break
+ fi
+ if [ "`jq --raw-output .response.expirationDate <<<$api_response`" = "3001-01-01 00:00:00" ]
+ then
+ continue
+ fi
+ echo $api_response > $id_oddaje.json
+ yt-dlp http://365.rtvslo.si/arhiv/oddaja/$id_oddaje
+ echo $id_oddaje > zadnji
+done
diff --git a/skripti/live_hls_archiver.py b/skripti/live_hls_archiver.py
new file mode 100755
index 0000000..f3d1498
--- /dev/null
+++ b/skripti/live_hls_archiver.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python3
+# skript je napisan za rtv stream in pričakuje na argv[1] tak hls, kot ga dobimo na http://z.4a.si/rtv.php?kanal=tv.slo1
+# shranjuje v trenutni direktorij
+from sys import argv
+from time import sleep
+from os import path, rename
+import requests
+import m3u8
+def main():
+ while True:
+ playlist = m3u8.loads(requests.get(argv[1]).text, uri=argv[1])
+ for segment in playlist.segments:
+ filename = segment.program_date_time.isoformat() + "." + next(reversed(segment.uri.split("?")[0].split(".")));
+ if not path.exists(filename):
+ print("prenašam " + filename)
+ temp_filename = "temp_"+argv[0].replace("/", "")
+ open(temp_filename, "wb").write(requests.get(segment.uri).content)
+ rename(temp_filename, filename)
+ try:
+ sleep(playlist.target_duration)
+ except TypeError:
+ sleep(1)
+if __name__ == "__main__":
+ main()