summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-12-12 00:29:36 +0100
committersijanec <sijanecantonluka@gmail.com>2020-12-12 00:29:36 +0100
commit28a090346c752a453d00cf0ada7123d20d5d703e (patch)
treea3e09dcd1c6bd602b4d3a9fda6179c5b4e3e8d78
parentinitial "release" (diff)
downloadrtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar
rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar.gz
rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar.bz2
rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar.lz
rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar.xz
rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar.zst
rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.zip
-rw-r--r--README.md9
-rwxr-xr-xrtv4d-dlbin31224 -> 35272 bytes
-rw-r--r--rtv4d-dl.c83
-rw-r--r--tcp.c21
4 files changed, 70 insertions, 43 deletions
diff --git a/README.md b/README.md
index c171023..af6d471 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@ z uporabo programa se strinjate z naslednjimi stavki:
## funkcije
* prenašanje videoposnetkov iz arhiva kot odklenjene videodatoteke
+* [**novo!**] z različico 0.0.1 tudi prenašanje avdioposnetkov!
## možnosti uporabe programa
* prenos oddaje: `rtv4d-dl oddaja <URL/ID oddaje> [izhodna datoteka]`
@@ -22,12 +23,12 @@ z uporabo programa se strinjate z naslednjimi stavki:
- primer: `rtv4d-dl slicica-oddaja 89614963 89614963.jpg`
# dodatne informacije:
-* pisanje v STDOUT: kot pot datoteke napišite `/dev/stdout` (samo POSIX)
-* program se poveže na 4D strežnik 4d.rtvslo.si, spremenite izv. kodo za drugega
+* pisanje v STDOUT: kot pot datoteke napišite `/dev/stdout`-POSIX ali `CON`-MS
+* program se poveže na \*.rtvslo.si, spremenite izvorno kodo za drugo infrastru.
# trenutna izdaja programa:
-* program je bil nazadnje ročno testiran 9. decembra 2020 in takrat je DELOVAL.
-* različica: 0.0.0
+* program je bil nazadnje ročno testiran 11. decembra 2020 in takrat je DELOVAL.
+* različica: 0.0.1
# o
* program je spisan 100% v C programskem jeziku
diff --git a/rtv4d-dl b/rtv4d-dl
index 67d1b41..a1a1ba4 100755
--- a/rtv4d-dl
+++ b/rtv4d-dl
Binary files differ
diff --git a/rtv4d-dl.c b/rtv4d-dl.c
index aab20a6..83c053c 100644
--- a/rtv4d-dl.c
+++ b/rtv4d-dl.c
@@ -40,7 +40,7 @@
do { if ( RTV_NAPISI_ ##kaj ) fprintf(stderr, \
"[" #kaj "] %s@%s:" NIZ(__LINE__) " " frmt "\n", \
__func__, __FILE__, ##__VA_ARGS__ ); } while(0);
-#define RTV_USER_AGENT "Mozilla/5.0 equivalent (rtv4d-dl; C " \
+#define RTV_USER_AGENT "Mozilla/5.0 equivalent (rtv4d-dl " RTV_VER "; C " \
NIZ(__STDC_VERSION__) " GCC " __VERSION__ "; " __DATE__ " " __TIME__ "; " \
__FILE__ ":" NIZ(__LINE__) ")"
#define RTV_HTTP_GET \
@@ -48,7 +48,7 @@
"\r\nAccept: */*\r\nX-Requested-With: tcp.c (" __FILE__ ":" NIZ(__LINE__) \
")\r\nConnection: close\r\n\r\n"
#define RTV_HTTP_TIMEOUT 69 /* sekund */
-#define RTV_NE_BO_POSLAL "ToJeMogočeBackdoor!"
+#define RTV_NE_BO_POSLAL NULL /* "ToJeMogočeBackdoor!" */ /* bere več znakov */
#define RTV_API_META_URL "http://api.rtvslo.si/ava/getRecordingDrm/" \
"%u?client_id=" RTV_CLIENT_ID
#define RTV_API_META_URL_SIZEOF 128 /* vključno z nul znakom */
@@ -58,6 +58,7 @@
#define RTV_JWT_SIZEOF 43+1
#define RTV_PREDVAJALNIK_URL "http://4d.rtvslo.si/arhiv/v/%u"
#define RTV_PREDVAJALNIK_URL_SIZEOF 32+1 + 12
+#define RTV_VER "0.0.1"
struct meta_oddaja {
size_t naslov_sizeof;
@@ -83,7 +84,7 @@ struct meta_oddaja {
size_t predvajano_sizeof;
char * predvajano; /* 2010-12-03 23:20:10 */
/* unsigned long long int kontrolna_vrednost; */
- unsigned long long int velikost; /* število bajtov posnetka */
+ /* unsigned long long int velikost; */ /* število bajtov posnetka */
char get_meta_url[RTV_API_META_URL_SIZEOF]; /* http://api.rtvslo.si/ava/... */
char get_media_url[RTV_API_MEDIA_URL_SIZEOF]; /* http://api.rtvslo.si/av... */
char predvajalnik_url[RTV_PREDVAJALNIK_URL_SIZEOF]; /* http://4d.rtvslo.... */
@@ -146,7 +147,7 @@ int http_get (/* const */ char * u, FILE * r) { /* url ostane enak */
return 1;
}
if (strncmp(u, "http://", 7) != 0) {
- RTV_NAPISI(NAPAKA, "URL protokol ni HTTP oziroma URL ni pravilen");
+ RTV_NAPISI(NAPAKA, "URL ni podprt: %s", u);
return 2;
}
k = strchr(RTV_URL_HOST, '/');
@@ -240,13 +241,14 @@ int rtv_meta_izpolni(struct meta_oddaja * m) {
size_t sizeloc;
size_t i, j;
char * metakeys[] = {"\"title\"", "\"showId\"", "\"genre\"", \
- "\"showDescription\"", "\"duration\"", "\"jwt\"", "\"showName\"", \
- "\"source\"", "\"publishDate\"", "\"mediaType\"", "\"orig\"", \
- "\"broadcastDate\"", /* sedaj pa za getMedia query */ "\"http\"" };
+ "\"description\"", "\"showDescription\"", "\"duration\"", "\"jwt\"", \
+ "\"showName\"", "\"source\"", "\"publishDate\"", "\"mediaType\"", \
+ "\"orig\"", "\"broadcastDate\"", /* getMedia query: */ "\"http\"", \
+ "\"https\"" };
char * cp;
-#define RTV_META_IZPOLNI_METAKEYS_SIZEOF 12 /* hkrati offset za getMedia */
+#define RTV_META_IZPOLNI_METAKEYS_SIZEOF 13 /* hkrati offset za getMedia */
#define RTV_META_IZPOLNI_METAKEYS_GETMEDIA_FINAL \
- (RTV_META_IZPOLNI_METAKEYS_SIZEOF)+1 /* zadnji+1 za getMedia */
+ (RTV_META_IZPOLNI_METAKEYS_SIZEOF+1)+1 /* zadnji+1 za getMedia */
#define RTV_META_IZPOLNI_VALUE (odg+i+strlen(metakeys[j])+2)
#define RTV_META_IZPOLNI_VALUE_INTERNAL RTV_META_IZPOLNI_VALUE
snprintf(m->get_meta_url, RTV_API_META_URL_SIZEOF, RTV_API_META_URL, m->id);
@@ -278,16 +280,16 @@ int rtv_meta_izpolni(struct meta_oddaja * m) {
#define RTV_META_IZPOLNI_I(imem, format, tip) /* za številke */ \
m->imem = strto##format(RTV_META_IZPOLNI_VALUE_INTERNAL, NULL, 10);
#define RTV_META_IZPOLNI(imem, oblika, format, splitter, tip) \
- cp = strchr(RTV_META_IZPOLNI_VALUE_INTERNAL, splitter); \
+ do { cp = strchr(RTV_META_IZPOLNI_VALUE_INTERNAL, splitter); \
if (cp == NULL) { \
RTV_NAPISI(OPOZORILO, "Napaka pri iskanju podatka " #imem); \
- strcpy(m->imem, "Napaka pri pridobivanju."); \
+ /* strcpy(m->imem, "Napaka pri pridobivanju."); */ /* ni vse s*/ \
} else { \
oblika(imem, format, tip) \
RTV_NAPISI(HROSC, "Shranil metapodatek " #imem ": %" #format, \
m->imem); \
- }
-#pragma GCC diagnostic ignored "-Wint-conversion" /* macro dela strcpy na str */
+ } } while (0)
+/* #pragma GCC diagnostic ignored "-Wint-conversion" */ /* surpressaš opozor. */
RTV_META_IZPOLNI(naslov, RTV_META_IZPOLNI_V, s, '"', char);
break;
case 1: /* showId */
@@ -297,45 +299,56 @@ int rtv_meta_izpolni(struct meta_oddaja * m) {
RTV_META_IZPOLNI(zanri, RTV_META_IZPOLNI_V, s, ']', char);
memmove(m->zanri, (m->zanri)+1, strlen(m->zanri)+1);
break;
- case 3: /* showDescription */
+ case 3: /* description */
RTV_META_IZPOLNI(opis, RTV_META_IZPOLNI_V, s, '"', char);
break;
- case 4: /* duration */
+ case 4: /* showDescription */
+ if (m->opis[0] == '\0') { /* če je prejšnji spodletel */
+ RTV_META_IZPOLNI(opis, RTV_META_IZPOLNI_V, s, '"', char);
+ }
+ break;
+ case 5: /* duration */
#undef RTV_META_IZPOLNI_VALUE_INTERNAL
#define RTV_META_IZPOLNI_VALUE_INTERNAL RTV_META_IZPOLNI_VALUE-1
RTV_META_IZPOLNI(dolzina, RTV_META_IZPOLNI_I, u, '"', unsigned int);
#undef RTV_META_IZPOLNI_VALUE_INTERNAL
#define RTV_META_IZPOLNI_VALUE_INTERNAL RTV_META_IZPOLNI_VALUE
break;
- case 5: /* jwt */
+ case 6: /* jwt */
RTV_META_IZPOLNI(jwt, RTV_META_IZPOLNI_V, s, '"', char);
if (RTV_JWT_SIZEOF != m->jwt_sizeof) {
RTV_NAPISI(OPOZORILO, "Shranil nepričakovano dolg JWT! Je vdor?");
}
break;
- case 6: /* showName */
+ case 7: /* showName */
RTV_META_IZPOLNI(tip_oddaje_ime, RTV_META_IZPOLNI_V, s, '"', char);
break;
- case 7: /* source */
+ case 8: /* source */
RTV_META_IZPOLNI(program, RTV_META_IZPOLNI_V, s, '"', char);
break;
- case 8: /* publishDate */
+ case 9: /* publishDate */
RTV_META_IZPOLNI(objavljeno, RTV_META_IZPOLNI_V, s, '"', char);
break;
- case 9: /* mediaType */
- if (RTV_META_IZPOLNI_VALUE[0] == 'v') {
- m->tip_posnetka = RTV_VIDEO_TIP;
- } else {
- m->tip_posnetka = RTV_NEPOZNAN_TIP;
+ case 10: /* mediaType */
+ switch (RTV_META_IZPOLNI_VALUE[0]) {
+ case 'v':
+ m->tip_posnetka = RTV_VIDEO_TIP;
+ break;
+ case 'a':
+ m->tip_posnetka = RTV_AUDIO_TIP;
+ break;
+ default:
+ m->tip_posnetka = RTV_NEPOZNAN_TIP;
+ break;
}
break;
- case 10: /* orig */ /* sličica */
+ case 11: /* orig */ /* sličica */
RTV_META_IZPOLNI(slicica, RTV_META_IZPOLNI_V, s, '"', char);
break;
- case 11: /* broadcastDate */
+ case 12: /* broadcastDate */
RTV_META_IZPOLNI(predvajano, RTV_META_IZPOLNI_V, s, '"', char);
break;
-#pragma GCC diagnostic warning "-Wint-conversion" /* smo prej izključili */
+/* #pragma GCC diagnostic warning "-Wint-conversion" */ /* undo */
default:
RTV_NAPISI(OPOZORILO, "Doseg nedefinirane kode!");
}
@@ -359,6 +372,15 @@ int rtv_meta_izpolni(struct meta_oddaja * m) {
case 0: /* http */ /* videofile */
RTV_META_IZPOLNI(posnetek_url, RTV_META_IZPOLNI_V, s, '"', char);
break;
+ case 1: /* https */
+ if (m->posnetek_url[0] == '\0') {
+ RTV_META_IZPOLNI(posnetek_url, RTV_META_IZPOLNI_V, s, '"', char);
+ fprintf(stderr, "test: %s\n", m->posnetek_url);
+ memmove((m->posnetek_url)+4, (m->posnetek_url)+5,
+ strlen((m->posnetek_url)+5)+1);
+ RTV_NAPISI(HROSC, "Popravil HTTPS URL na HTTP");
+ }
+ break;
default:
RTV_NAPISI(OPOZORILO, "Doseg nedefinirane kode!");
}
@@ -444,12 +466,13 @@ int main (int argc, char ** argv) {
fprintf(fd, "id: %u\nnaslov: %s\ntip_oddaje_id: %u\nzanri: %s\nopis: %s\n"
"dolzina: %u\njwt: %s\ntip_oddaje_ime: %s\nprogram: %s\n"
"objavljeno: %s\ntip_posnetka: %s\nslicica: %s\npredvajano: %s\n"
- "velikost: %llu\nget_meta_url: %s\nget_media_url: %s\n"
+ /* "velikost: %llu\n" */ "get_meta_url: %s\nget_media_url: %s\n"
"predvajalnik_url: %s\nposnetek_url: %s\n", m->id, m->naslov,
m->tip_oddaje_id, m->zanri, m->opis, m->dolzina, m->jwt,
m->tip_oddaje_ime, m->program, m->objavljeno,
- m->tip_posnetka == RTV_VIDEO_TIP ? "RTV_VIDEO_TIP":"RTV_NEPOZNAN_TIP",
- m->slicica, m->predvajano, m->velikost, m->get_meta_url,
+ m->tip_posnetka == RTV_VIDEO_TIP ? "RTV_VIDEO_TIP" : \
+ m->tip_posnetka == RTV_AUDIO_TIP ? "RTV_AUDIO_TIP":"RTV_NEPOZNAN_TIP",
+ m->slicica, m->predvajano, /* m->velikost, */ m->get_meta_url,
m->get_media_url, m->predvajalnik_url, m->posnetek_url);
fclose(fd);
break;
diff --git a/tcp.c b/tcp.c
index d30e7b5..93558f3 100644
--- a/tcp.c
+++ b/tcp.c
@@ -14,6 +14,7 @@
#include <string.h>
#include <sys/time.h>
#define ERR_INET_ADDR "0.9.9.0"
+#define TCPC_READ_BUF 1024
union ip_conv {
unsigned char c[4];
struct in_addr in;
@@ -86,9 +87,9 @@ int read_until(int conn_fd, FILE * out, unsigned int timeout, const char * ma,
unsigned int match = 0;
struct timeval start, stop;
gettimeofday(&start, NULL);
- char c[2] = {'\0', '\0'};
+ char c[TCPC_READ_BUF+1];
while (1) {
- ret = read(conn_fd, c, 1);
+ ret = read(conn_fd, c, ma ? 1 : TCPC_READ_BUF);
if (ret == -1) {
if (errno == EWOULDBLOCK) {
} else {
@@ -99,18 +100,20 @@ int read_until(int conn_fd, FILE * out, unsigned int timeout, const char * ma,
fprintf(stderr, "%s@" __FILE__ ":%d read(): server closed connection\n", __func__, __LINE__);
return 0;
} else {
- fputc(c[0], out);
+ fwrite(c, ret, 1, out);
max_bytes--;
if (max_bytes <= 0) {
return 0;
}
- if (ma[match] == c[0]) {
- match++;
- if (match == strlen(ma)) {
- return 0;
+ if (ma != NULL) {
+ if (ma[match] == c[0]) {
+ match++;
+ if (match == strlen(ma)) {
+ return 0;
+ }
+ } else {
+ match = 0;
}
- } else {
- match = 0;
}
}
gettimeofday(&stop, NULL);