summaryrefslogtreecommitdiffstats
path: root/rtv4d-dl.c
diff options
context:
space:
mode:
authorsijanec <anton@sijanec.eu>2020-12-28 01:43:37 +0100
committersijanec <anton@sijanec.eu>2020-12-28 01:43:37 +0100
commit70921ad87145ba42ca7c3a1b2153ebea1aad4933 (patch)
tree611586f3dcc995bc55549c91b4e1725e1ae64f9a /rtv4d-dl.c
parentnaredil download v preteklost (diff)
downloadrtv4d-dl-70921ad87145ba42ca7c3a1b2153ebea1aad4933.tar
rtv4d-dl-70921ad87145ba42ca7c3a1b2153ebea1aad4933.tar.gz
rtv4d-dl-70921ad87145ba42ca7c3a1b2153ebea1aad4933.tar.bz2
rtv4d-dl-70921ad87145ba42ca7c3a1b2153ebea1aad4933.tar.lz
rtv4d-dl-70921ad87145ba42ca7c3a1b2153ebea1aad4933.tar.xz
rtv4d-dl-70921ad87145ba42ca7c3a1b2153ebea1aad4933.tar.zst
rtv4d-dl-70921ad87145ba42ca7c3a1b2153ebea1aad4933.zip
Diffstat (limited to 'rtv4d-dl.c')
-rw-r--r--rtv4d-dl.c75
1 files changed, 69 insertions, 6 deletions
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 <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
+#include <time.h>
#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]; /* <id>.txt / <id>.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!",