source: titan/plugins/tithek/streamcloud.h @ 24238

Last change on this file since 24238 was 24238, checked in by nit, 10 years ago

[titan] tithek optimize

File size: 4.8 KB
Line 
1#ifndef STREAMCLOAD_H
2#define STREAMCLOAD_H
3
4char* streamcloud(char* host, char* file)
5{
6        debug(99, "in host: %s file: %s", host, file);
7        int debuglevel = getconfigint("debuglevel", NULL);
8        char* tmphost = NULL;
9        char* tmpfile = NULL;
10        char* tmpstr = NULL;
11        char* send = NULL;
12        char* id = NULL;
13        char* fname = NULL;
14        char* op = NULL;
15        char* hash = NULL;
16        char* hashline = NULL;
17        char* hashlen = NULL;
18        char* referer = NULL;
19        char* usr_login = NULL;
20        char* imhuman = NULL;   
21        char* ip = NULL;
22        char* cookie = NULL;
23        char* cmd = NULL;
24        char* streamlink = NULL;
25
26        if(host == NULL || file == NULL) return NULL;
27
28        tmphost = ostrcat(tmphost, host, 1, 0);
29        tmpfile = ostrcat("/", file, 0, 0);
30       
31        debug(99, "tmphost: %s", tmphost);
32        ip = get_ip(tmphost);
33        debug(99, "ip: %s", ip);
34        debug(99, "tmpfile: %s", tmpfile);
35
36        send = ostrcat(send, "GET /", 1, 0);
37        send = ostrcat(send, file, 1, 0);
38        send = ostrcat(send, " HTTP/1.1\r\nHost: ", 1, 0);
39        send = ostrcat(send, host, 1, 0);
40        send = ostrcat(send, "\r\nUser-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.99 Safari/535.1\r\nConnection: close\r\nAccept-Encoding: gzip\r\n\r\n", 1, 0);
41        debug(99, "send: %s", send);
42
43        tmpstr = gethttpreal(tmphost, tmpfile, 80, NULL, NULL, NULL, 0, send, NULL, 5000, 1);
44
45        if(getconfigint("debuglevel", NULL) == 99)
46                writesys("/tmp/streamcould1_tmpstr", tmpstr, 0);
47/*
48        old code       
49        cmd = ostrcat(cmd, "echo -e \"", 1, 0);
50        cmd = ostrcat(cmd, send, 1, 0);
51        cmd = ostrcat(cmd, "\" | /var/usr/local/share/titan/plugins/tithek/netcat ", 1, 0);
52        cmd = ostrcat(cmd, host, 1, 0);
53        cmd = ostrcat(cmd, " 80", 1, 0);
54        debug(99, "cmd: %s", cmd);
55        free(tmpstr), tmpstr = NULL;
56        tmpstr = command(cmd);
57*/
58        cookie = string_resub("Set-Cookie: afc=", ";", tmpstr, 0);     
59        debug(99, "cookie: %s", cookie);
60 
61        sleep(20);
62
63        //get hash from tmpstr
64        char* pos1 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"fname\" value=");
65        fname = getxmlentry(pos1, "value=");
66        debug(99, "fname: %s", fname);
67        if(fname == NULL) goto end;
68
69        char* pos2 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"id\" value=");
70        id = getxmlentry(pos2, "value=");
71        debug(99, "id: %s", id);
72        if(id == NULL) goto end;
73
74        char* pos3 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"op\" value=");
75        op = getxmlentry(pos3, "value=");
76
77        char* pos4 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"hash\" value=");
78        hashline = getxmlentry(pos4, "value=");
79
80        char* pos5 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"referer\" value=");
81        referer = getxmlentry(pos5, "value=");
82
83        char* pos6 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"imhuman\" value=");
84        imhuman = getxmlentry(pos6, "value=");
85
86        char* pos7 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"usr_login\" value=");
87        usr_login = getxmlentry(pos7, "value=");
88       
89        free(tmpstr); tmpstr = NULL;
90        debug(99, "op: %s", op);
91        if(op == NULL) goto end;
92
93        hash = ostrcat(hash, "hash=", 1, 0);
94        hash = ostrcat(hash, hashline, 1, 0);
95        hash = ostrcat(hash, "&imhuman=Weiter+zum+Video", 1, 0);
96        hash = ostrcat(hash, "&usr_login=", 1, 0);     
97        hash = ostrcat(hash, usr_login, 1, 0);
98        hash = ostrcat(hash, "&referer=", 1, 0);
99        hash = ostrcat(hash, referer, 1, 0);
100        hash = ostrcat(hash, "&fname=", 1, 0);
101        hash = ostrcat(hash, fname, 1, 0);
102        hash = ostrcat(hash, "&id=", 1, 0);     
103        hash = ostrcat(hash, id, 1, 0);
104        hash = ostrcat(hash, "&op=", 1, 0);
105        hash = ostrcat(hash, op, 1, 0);
106        debug(99, "hash: %s", hash);
107        hashlen = oitoa(strlen(hash));
108
109        //create send string
110        free(send), send = NULL;
111
112        send = ostrcat(send, "POST /", 1, 0);
113        send = ostrcat(send, file, 1, 0);
114        send = ostrcat(send, " HTTP/1.1\r\nContent-Length: ", 1, 0);
115        send = ostrcat(send, hashlen, 1, 0);
116        send = ostrcat(send, "\r\nAccept-Encoding: gzip\r\nConnection: close\r\nUser-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.99 Safari/535.1\r\nHost: ", 1, 0);
117        send = ostrcat(send, host, 1, 0);
118        send = ostrcat(send, "\r\nCookie: afc=", 1, 0);
119        send = ostrcat(send, cookie, 1, 0);
120        send = ostrcat(send, "\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n", 1, 0);
121        send = ostrcat(send, hash, 1, 0);
122        debug(99, "send: %s", send);
123
124        free(tmpstr), tmpstr = NULL;
125        tmpstr = gethttpreal(tmphost, tmpfile, 80, NULL, NULL, NULL, 0, send, NULL, 5000, 0);
126        titheklog(debuglevel, "/tmp/streamcould2_tmpstr_post", NULL, tmpstr);
127
128//      streamlink = oregex(".*file: \".*(http:.*video.mp4).*\".*", tmpstr);
129        streamlink = string_resub("file: \"", "\"", tmpstr, 0);
130        titheklog(debuglevel, "/tmp/streamcould3_streamlink", NULL, streamlink);
131
132        free(tmpstr); tmpstr = NULL;
133
134end:
135
136        free(tmphost); tmphost = NULL;
137        free(tmpfile); tmpfile = NULL;
138        free(tmpstr); tmpstr = NULL;
139        free(send); send = NULL;
140        free(hash), hash = NULL;
141        free(hashlen), hashlen = NULL;
142        free(op), op = NULL;
143        free(id), id = NULL;
144        free(fname), fname = NULL;
145        free(ip); ip = NULL;
146        free(cookie); cookie = NULL;
147        free(cmd); cmd = NULL; 
148        return streamlink;
149}
150
151#endif
Note: See TracBrowser for help on using the repository browser.