From 70921ad87145ba42ca7c3a1b2153ebea1aad4933 Mon Sep 17 00:00:00 2001 From: sijanec Date: Mon, 28 Dec 2020 01:43:37 +0100 Subject: =?UTF-8?q?=C5=BEivo=20=C5=A1e=20vedno=20pokvarjen,=20casi=20jebej?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- a.out | Bin 16712 -> 0 bytes rtv4d-dl | Bin 52624 -> 52776 bytes rtv4d-dl.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 71 insertions(+), 8 deletions(-) delete mode 100755 a.out diff --git a/README.md b/README.md index f7e9f02..0260c12 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ z uporabo programa se strinjate z naslednjimi stavki: - opomba: nekateri metapodatki veljajo omejeno časa (video URL) * prenos sličice oddaje: `rtv4d-dl slicica-oddaja [datoteka]` - primer: `rtv4d-dl slicica-oddaja 89614963 89614963.jpg` -* prenos zadnjih dveh ur prenosa v živo: `rtv4d-dl zivo [2] [3] [4] [5]` - - primer: `rtv4d-dl zivo slo1 slo1 9999999 9999999` (prenese vse) +* prenos zadnjih dveh ur prenosa v živo: `rtv4d-dl živo [2] [3] [4] [5]` + - primer: `rtv4d-dl živo slo1 slo1 9999999 9999999` (prenese vse) - arg. 2 je program, 3 je izhodni direktorij, 4 je število sekund v preteklost, 5 je število sekund v prihodnost * prenos podnapisov oddaje: `rtv4d-dl podnapisi [datoteka]` diff --git a/a.out b/a.out deleted file mode 100755 index c701106..0000000 Binary files a/a.out and /dev/null differ diff --git a/rtv4d-dl b/rtv4d-dl index fb514b0..f3667a4 100755 Binary files a/rtv4d-dl and b/rtv4d-dl differ diff --git a/rtv4d-dl.c b/rtv4d-dl.c index 4b46265..1428a69 100644 --- a/rtv4d-dl.c +++ b/rtv4d-dl.c @@ -9,6 +9,7 @@ #include #include #include +#include #define NIZ_DODATEK(a) #a #define NIZ(a) NIZ_DODATEK(a) #define RTV_CLIENT_ID "82013fb3a531d5414f478747c1aca622" /* enak za vse */ @@ -593,7 +594,10 @@ int main (int argc, char ** argv) { char fn[420]; /* .txt / .mp4 - NE USER INPUT */ char * e; /* char pointer for the memes */ FILE * fd; + FILE * fd2; unsigned int i; + time_t * casi = NULL; + time_t cas; DIR * dir; unsigned short int returnstatus = 0; switch (RTV_NACIN[0]) { @@ -773,25 +777,84 @@ int main (int argc, char ** argv) { returnstatus = 4; } for (i = z->sedanjost; i >= 0; i--) { - snprintf(fn, sizeof(fn), "%s/%u%s", - e, i, strrchr(z->kos_format, '.')); /* printf je NULL safe */ + casi = realloc(casi, sizeof(time_t)*i+1); /* NE GOTO PRED SPROŠČENJEM */ + cas = time(NULL); + casi[i] = cas; + if ((z->prenesenih_kosov_preteklost)*(z->dolzina) >= z->preteklost) { + i++; + RTV_NAPISI(INFO, "končal preteklost: kosov: %u, sekund: %u.", + z->prenesenih_kosov_preteklost, + (z->prenesenih_kosov_preteklost)*(z->dolzina)); + break; + } + snprintf(fn, sizeof(fn), "%s/%u-%lu%s", + e, i, cas, strrchr(z->kos_format, '.')); /* printf je NULL safe */ fd = fopen(fn, "w"); snprintf(fn, sizeof(fn), z->kos_format, i); if (!RTV_HTTP_SUCCESS(http_get(fn, fd))) { /* napaka je verjetno 404 */ - i--; + i++; RTV_NAPISI(INFO, "ni več kosov v preteklosti"); fclose(fd); + snprintf(fn, sizeof(fn), "%s/%u-%lu%s", + e, i, cas, strrchr(z->kos_format, '.')); + unlink(fn); break; } RTV_NAPISI(INFO, "prenesel kos %u iz preteklosti", i); fclose(fd); + z->prenesenih_kosov_preteklost++; } snprintf(fn, sizeof(fn), "%s/seznam_predvajanja.m3u8", e); - fd = fopen(fn, "w"); - fprintf(fd, "# generirano z rtv4d-dl " RTV_VER "\n"); + fd2 = fopen(fn, "w"); + fprintf(fd2, "# generirano z rtv4d-dl " RTV_VER "\n"); for (i = i; i <= z->sedanjost; i++) { - fprintf(fd, "%u%s\n", i, strrchr(z->kos_format, '.')); + fprintf(fd2, "%u-%lu%s\n", i, casi[i], strrchr(z->kos_format, '.')); + } + free(casi); + casi = NULL; + for (i = (z->sedanjost)+1; 1 == 1; i++) { + cas = time(NULL); + if ((z->prenesenih_kosov_prihodnost)*(z->dolzina) >= z->prihodnost) { + i++; + RTV_NAPISI(INFO, "končal prihodnost: kosov: %u, sekund: %u.", + z->prenesenih_kosov_prihodnost, + (z->prenesenih_kosov_prihodnost)*(z->dolzina)); + break; + } + snprintf(fn, sizeof(fn), "%s/%u-%lu%s", + e, i, cas, strrchr(z->kos_format, '.')); + fd = fopen(fn, "w"); + snprintf(fn, sizeof(fn), z->kos_format, i); + returnstatus = http_get(fn, fd); + if (!RTV_HTTP_SUCCESS(returnstatus)) { + if (returnstatus != 404) { + RTV_NAPISI(NAPAKA, "strežnik odvrnil %u namesto 200/404.", + returnstatus); + returnstatus = 1; + fclose(fd2); + fclose(fd); + snprintf(fn, sizeof(fn), "%s/%u-%lu%s", + e, i, cas, strrchr(z->kos_format, '.')); + unlink(fn); + goto returncleanly; + break; + } + RTV_NAPISI(INFO, "kos ne obstaja, čakam %u sekund.", (z->dolzina)-1); + sleep(z->dolzina-1); + snprintf(fn, sizeof(fn), "%s/%u-%lu%s", + e, i, cas, strrchr(z->kos_format, '.')); + fclose(fd); + unlink(fn); + i--; /* ponovno poskusimo ta kos */ + continue; + } + fprintf(fd2, "%u-%lu%s\n", i, cas, strrchr(z->kos_format, '.')); + RTV_NAPISI(INFO, "prenesel kos %u iz prihodnosti", i); + z->prenesenih_kosov_prihodnost++; + fclose(fd); + returnstatus = 0; } + fclose(fd2); break; default: RTV_NAPISI(NAPAKA, "opcija (%c/%u) ne obstaja!", -- cgit v1.2.3