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

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

[titan] tithek optimize

File size: 11.0 KB
Line 
1#ifndef XVIDSTAGE_H
2#define XVIDSTAGE_H
3
4char* xvidstage(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* ip = NULL;
13        char* streamlink = NULL;
14
15        char* cookie = NULL;           
16        char* id = NULL;
17        char* fname = NULL;
18        char* op = NULL;
19        char* hash = NULL;
20        char* hashline = NULL;
21        char* hashlen = NULL;
22        char* referer = NULL;
23        char* usr_login = NULL;
24        char* imhuman = NULL;
25        char* post = NULL;
26
27        char* b36code = NULL;
28        char* base = NULL;
29        char* search = NULL;
30
31        char* tmpstr2 = NULL;
32        char* tmpstr3 = NULL;
33        char* charlist = NULL;
34
35        unlink("/tmp/tithek/get");
36        unlink("/tmp/tithek/post");
37
38        if(host == NULL || file == NULL) return NULL;
39
40        tmphost = ostrcat("www.", host, 0, 0);
41        tmpfile = ostrcat("/file/", file, 0, 0);
42        debug(99, "tmphost: %s", tmphost);
43        ip = get_ip(tmphost);
44        debug(99, "ip: %s", ip);
45        debug(99, "tmpfile: %s", tmpfile);
46        debug(99, "file: %s", file);
47
48        send = ostrcat(send, "GET /", 1, 0);
49        send = ostrcat(send, file, 1, 0);
50        send = ostrcat(send, " HTTP/1.1\r\nHost: www.", 1, 0); 
51        send = ostrcat(send, host, 1, 0);
52        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);       
53        debug(99, "tmphost: %s", tmphost);
54        debug(99, "tmpfile: %s", tmpfile);
55        debug(99, "send: %s", send);
56
57        char* line = NULL;
58        char* lines = NULL;
59        char* cmd = NULL;
60        gethttpreal(tmphost, tmpfile, 80, "/tmp/tithek/get", NULL, NULL, 0, send, NULL, 5000, 1);
61        sleep(1);
62        free(send); send = NULL;
63        if(!file_exist("/tmp/tithek/get"))
64        {
65                textbox(_("Message"), _("This file doesn't exist, or has been removed") , _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1200, 200, 0, 0);
66                goto end;
67        }
68
69        if(debuglevel == 99) system("cp -a /tmp/tithek/get /tmp/xvidstage1_tmpstr_get");
70
71        tmpstr = command("cat /tmp/tithek/get");
72        cookie = string_resub("Set-Cookie: afc=", ";", tmpstr, 0);     
73        debug(99, "cookie: %s", cookie);
74       
75        titheklog(debuglevel, "/tmp/xvidstage2_tmpstr", NULL, tmpstr);
76
77        free(tmpstr), tmpstr = NULL;
78
79        line = string_newline(command("cat /tmp/tithek/get | grep 'Set-Cookie:' -n | tail -n1| cut -d':' -f1"));
80        cmd = ostrcat(cmd, "cat /tmp/tithek/get | wc -l", 1, 0);
81        lines = string_newline(command(cmd));
82        free(cmd); cmd = NULL;
83        debug(99, "line: %s", line);
84        debug(99, "lines: %s", lines);
85
86        if(lines == NULL || line == NULL) goto end;     
87       
88        int sline = atoi(lines) - atoi(line) - 4;
89        debug(99, "sline: %d", sline);
90        debug(99, "sline: %s", oitoa(sline));
91
92        cmd = ostrcat(cmd, "cat /tmp/tithek/get | tail -n", 1, 0);
93        cmd = ostrcat(cmd, oitoa(sline), 1, 0);
94        cmd = ostrcat(cmd, " | sed '1,1d' | zcat", 1, 0);
95        debug(99, "cmd: %s", cmd);     
96        tmpstr = command(cmd);
97        free(cmd); cmd = NULL;
98        free(lines); lines = NULL;
99
100        titheklog(debuglevel, "/tmp/xvidstage3_tmpstr_zcat", NULL, tmpstr);
101
102        sleep(1);
103
104        //get hash from tmpstr
105        char* pos1 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"fname\" value=");
106        fname = getxmlentry(pos1, "value=");
107        debug(99, "fname: %s", fname);
108//      if(fname == NULL) goto end;
109
110        char* pos2 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"id\" value=");
111        id = getxmlentry(pos2, "value=");
112        debug(99, "id: %s", id);
113        if(id == NULL) goto end;
114
115        char* pos3 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"op\" value=");
116        op = getxmlentry(pos3, "value=");
117
118        char* pos4 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"rand\" value=");
119        hashline = getxmlentry(pos4, "value=");
120
121        char* pos5 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"referer\" value=");
122        referer = getxmlentry(pos5, "value=");
123
124        char* pos6 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"imhuman\" value=");
125        imhuman = getxmlentry(pos6, "value=");
126
127        char* pos7 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"usr_login\" value=");
128        usr_login = getxmlentry(pos7, "value=");
129       
130        free(tmpstr); tmpstr = NULL;
131        debug(99, "op: %s", op);
132        if(op == NULL) goto end;
133
134        hash = ostrcat(hash, "hash=", 1, 0);
135        hash = ostrcat(hash, hashline, 1, 0);
136        hash = ostrcat(hash, "&imhuman=Proceed+to+video%22+id%3D%22btn_download&k=Search...%22+size%3D16+onfocus%3D%22%24%28this%29.val%28%27%27%29.css%28%27color%27%2C%27%23333%27%29%3B%22+onblur%3D%22if%28%24%28this%29.val%28%29%3D%3D%27%27%29%24%28this%29.val%28%27Search...%27%29.css%28%27color%27%2C%27%27%29%22+id%3D%22search_top", 1, 0);
137        hash = ostrcat(hash, "&usr_login=", 1, 0);     
138        hash = ostrcat(hash, usr_login, 1, 0);
139        hash = ostrcat(hash, "&referer=", 1, 0);
140        hash = ostrcat(hash, referer, 1, 0);
141        hash = ostrcat(hash, "&fname=", 1, 0);
142        hash = ostrcat(hash, fname, 1, 0);
143        hash = ostrcat(hash, "&id=", 1, 0);     
144        hash = ostrcat(hash, id, 1, 0);
145        hash = ostrcat(hash, "&op=download1", 1, 0);
146//      hash = ostrcat(hash, op, 1, 0);
147        debug(99, "hash: %s", hash);
148        hashlen = oitoa(strlen(hash));
149
150        //create send string
151        free(send), send = NULL;
152
153        send = ostrcat(send, "POST /", 1, 0);
154        send = ostrcat(send, file, 1, 0);
155        send = ostrcat(send, " HTTP/1.1\r\nContent-Length: ", 1, 0);
156        send = ostrcat(send, hashlen, 1, 0);
157        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);
158        send = ostrcat(send, host, 1, 0);
159        send = ostrcat(send, "\r\nCookie: afc=", 1, 0);
160        send = ostrcat(send, cookie, 1, 0);
161        send = ostrcat(send, "\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n", 1, 0);
162        send = ostrcat(send, hash, 1, 0);
163        debug(99, "send: %s", send);
164
165        free(tmpstr), tmpstr = NULL;
166
167        //send and receive answer
168//      post = gethttpreal(tmphost, tmpfile, 80, NULL, NULL, NULL, 0, send, NULL, 5000, 0);
169//      writesys("/var/usr/local/share/titan/plugins/tithek/xvidstage_post1", post, 0);
170///
171        gethttpreal(tmphost, tmpfile, 80, "/tmp/tithek/post", NULL, NULL, 0, send, NULL, 5000, 0);
172
173        if(!file_exist("/tmp/tithek/post"))
174        {
175                textbox(_("Message"), _("This file doesn't exist, or has been removed") , _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1200, 200, 0, 0);
176                goto end;
177        }
178
179        if(debuglevel == 99) system("cp -a /tmp/tithek/post /tmp/xvidstage4_tmpstr_post");     
180
181        cmd = ostrcat(cmd, "cat /tmp/tithek/post | zcat", 1, 0);
182        debug(99, "cmd: %s", cmd);
183        post = command(cmd);
184        titheklog(debuglevel, "/tmp/xvidstage5_tmpstr_post1_zcat", NULL, post);
185        free(cmd); cmd = NULL;
186
187        free(tmpstr),tmpstr = NULL;
188        tmpstr = string_resub(";return p}('", ");'", post, 0);
189        titheklog(debuglevel, "/tmp/xvidstage6_tmpstr_post1_zcat_resub", NULL, tmpstr);
190       
191        post = string_replace_all(tmpstr, "", post, 1);
192        post = string_replace_all(";return p}(');'", "", post, 1);
193        titheklog(debuglevel, "/tmp/xvidstage7_tmpstr_post2", NULL, post);
194
195        free(tmpstr),tmpstr = NULL;
196        free(b36code),b36code = NULL;
197        tmpstr = string_resub(";return p}('", ");'", post, 0);
198        titheklog(debuglevel, "/tmp/xvidstage8_tmpstr_post2_resub", NULL, tmpstr);
199
200        b36code = oregex(".*;',[0-9]{2,2},[0-9]{2,2},'(.*)'.split.*", post);
201       
202        b36code = string_replace_all("||", "| |", b36code, 1);
203        titheklog(debuglevel, "/tmp/xvidstage9_tmpstr_post2_resub_b36code2", NULL, b36code);
204       
205        struct splitstr* ret1 = NULL;
206        int count = 0;
207        int i = 0;
208        ret1 = strsplit(b36code, "|", &count);
209
210        charlist = ostrcat(charlist, "\"", 1, 0);
211        charlist = ostrcat(charlist, "|", 1, 0);
212        charlist = ostrcat(charlist, "'", 1, 0);
213        charlist = ostrcat(charlist, "|", 1, 0);
214        charlist = ostrcat(charlist, ".", 1, 0);
215        charlist = ostrcat(charlist, "|", 1, 0);
216        charlist = ostrcat(charlist, ";", 1, 0);
217        charlist = ostrcat(charlist, "|", 1, 0);
218        charlist = ostrcat(charlist, ":", 1, 0);
219        charlist = ostrcat(charlist, "|", 1, 0);
220        charlist = ostrcat(charlist, "=", 1, 0);
221        charlist = ostrcat(charlist, "|", 1, 0);
222        charlist = ostrcat(charlist, ",", 1, 0);
223        charlist = ostrcat(charlist, "|", 1, 0);
224        charlist = ostrcat(charlist, " ", 1, 0);
225        charlist = ostrcat(charlist, "|", 1, 0);
226        charlist = ostrcat(charlist, "\\", 1, 0);
227        charlist = ostrcat(charlist, "|", 1, 0);
228        charlist = ostrcat(charlist, "/", 1, 0);
229        charlist = ostrcat(charlist, "|", 1, 0);
230        charlist = ostrcat(charlist, "(", 1, 0);
231        charlist = ostrcat(charlist, "|", 1, 0);
232        charlist = ostrcat(charlist, ")", 1, 0);
233
234        for(i = 0; i < count; i++)
235        {
236                if(ostrstr((&ret1[i])->part, " ") != NULL)
237                {
238                        printf("continue\n");
239                        continue;
240                }
241                char* x = oltostr(i, 36);
242
243                struct splitstr* ret2 = NULL;
244                int count2 = 0;
245                int i2 = 0;
246                tmpstr2 = ostrcat(charlist, NULL, 0, 0);
247                ret2 = strsplit(tmpstr2, "|", &count2);
248                for(i2 = 0; i2 < count2; i2++)
249                {
250                        struct splitstr* ret3 = NULL;
251                        int count3 = 0;
252                        int i3 = 0;
253                        tmpstr3 = ostrcat(charlist, NULL, 0, 0);
254                        ret3 = strsplit(tmpstr3, "|", &count3);
255                        for(i3 = 0; i3 < count3; i3++)
256                        {
257                                debug(99, "-----------------------------------------------");
258                                debug(99, "replace %s%s%s <> %s%s%s",(&ret2[i2])->part, x, (&ret3[i3])->part, (&ret2[i2])->part, (&ret1[i])->part, (&ret3[i3])->part);
259
260                                base = ostrcat(base, (&ret2[i2])->part, 1, 0);
261                                base = ostrcat(base, x, 1, 0);
262                                base = ostrcat(base, (&ret3[i3])->part, 1, 0);         
263                                search = ostrcat(search, (&ret2[i2])->part, 1, 0);
264                                search = ostrcat(search, (&ret1[i])->part, 1, 0);
265                                search = ostrcat(search, (&ret3[i3])->part, 1, 0);
266                                tmpstr = string_replace_all(base, search, tmpstr, 1);
267                                free(base), base = NULL;
268                                free(search), search = NULL;
269                        }
270                        free(ret3), ret3 = NULL;
271                        free(tmpstr3), tmpstr3 = NULL;
272                }
273                free(ret2), ret2 = NULL;
274                free(tmpstr2), tmpstr2 = NULL;
275                free(x);
276        }
277        free(ret1), ret1 = NULL;
278        free(b36code), b36code = NULL;
279        free(post), post = NULL;
280        free(charlist), charlist = NULL;
281
282        titheklog(debuglevel, "/tmp/xvidstage10_tmpstr_last", NULL, tmpstr);
283
284        streamlink = oregex(".*file.*(http:.*video.flv).*image.*", tmpstr);
285        if(streamlink == NULL)
286                streamlink = oregex(".*file.*(http:.*video.mp4).*image.*", tmpstr);                             
287
288        if(streamlink == NULL)
289                streamlink = oregex(".*file.*(http:.*video.mkv).*image.*", tmpstr);
290
291        if(streamlink == NULL)
292                streamlink = oregex(".*file.*(http:.*video.avi).*image.*", tmpstr);
293
294        if(streamlink == NULL)
295                streamlink = oregex(".*src=.*(http:.*video.mp4).*\".*", tmpstr);
296
297        if(streamlink == NULL)
298                streamlink = oregex(".*src=.*(http:.*video.mkv).*\".*", tmpstr);
299
300        if(streamlink == NULL)
301                streamlink = oregex(".*src=.*(http:.*video.avi).*\".*", tmpstr);
302               
303        if(streamlink == NULL)
304                streamlink = oregex(".*value=.*(http:.*video.mp4).*\".*", tmpstr);                             
305
306        if(streamlink == NULL)
307                streamlink = oregex(".*value=.*(http:.*video.mkv).*\".*", tmpstr);
308
309        if(streamlink == NULL)
310                streamlink = oregex(".*value=.*(http:.*video.avi).*\".*", tmpstr);                     
311
312        titheklog(debuglevel, "/tmp/xvidstage11_streamlink", NULL, streamlink);
313
314        free(tmpstr); tmpstr = NULL;
315
316end:
317
318        free(cookie); cookie = NULL;
319        free(hash), hash = NULL;
320        free(hashlen), hashlen = NULL;
321        free(op), op = NULL;
322        free(id), id = NULL;
323        free(fname), fname = NULL;
324               
325        free(tmphost); tmphost = NULL;
326        free(tmpfile); tmpfile = NULL;
327        free(tmpstr); tmpstr = NULL;
328        free(send); send = NULL;
329        free(ip); ip = NULL;
330
331        return streamlink;
332}
333
334#endif
Note: See TracBrowser for help on using the repository browser.