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

Last change on this file since 19880 was 19880, checked in by obi, 10 years ago

fix

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