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

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

[titan] tithek optimize

File size: 7.0 KB
Line 
1#ifndef PUTLOCKER_H
2#define PUTLOCKER_H
3
4char* putlocker(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* hash = NULL;
13        char* hashstr = NULL;
14        char* hashlen = NULL;
15        char* ip = NULL;
16        char* phpsessid = NULL;
17        char* serverid = NULL;
18        char* usender = NULL;
19        char* line = NULL;
20        char* lines = NULL;     
21        char* cmd = NULL;
22        char* streamlink = NULL;
23        char* streamlink1 = NULL;
24
25        unlink("/tmp/tithek/get");
26        unlink("/tmp/tithek/x9");
27
28        if(host == NULL || file == NULL) return NULL;
29
30        tmphost = ostrcat("www.", host, 0, 0);
31        tmpfile = ostrcat("/file/", file, 0, 0);
32        debug(99, "tmphost: %s", tmphost);
33        ip = get_ip(tmphost);
34        debug(99, "ip: %s", ip);
35        debug(99, "tmpfile: %s", tmpfile);
36
37        send = ostrcat(send, "GET /file/", 1, 0);
38        send = ostrcat(send, file, 1, 0);
39        send = ostrcat(send, " HTTP/1.1\r\nHost: www.", 1, 0); 
40        send = ostrcat(send, host, 1, 0);
41        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);       
42       
43        debug(99, "tmphost: %s", tmphost);
44        debug(99, "tmpfile: %s", tmpfile);
45        debug(99, "send: %s", send);
46
47        gethttpreal(tmphost, tmpfile, 80, "/tmp/tithek/get", NULL, NULL, 0, send, NULL, 5000, 1);
48        sleep(1);
49        free(send); send = NULL;
50       
51        if(!file_exist("/tmp/tithek/get"))
52        {
53                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);
54                goto end;
55        }
56        if(debuglevel == 99) system("cp -a /tmp/tithek/get /tmp/putlocker1_tmpstr_get");
57
58        char* header = NULL;
59        header = command("cat /tmp/tithek/get");
60       
61        phpsessid = getxmlentry(header, "PHPSESSID=");
62        debug(99, "phpsessid: %s", phpsessid);
63        serverid = getxmlentry(header, "SERVERID=");
64        debug(99, "serverid: %s", serverid);
65        usender = getxmlentry(header, "usender=");
66        debug(99, "usender: %s", usender);
67        free(header), header = NULL;
68
69        line = string_newline(command("cat /tmp/tithek/get | grep 'Set-Cookie:' -n | tail -n1| cut -d':' -f1"));
70        cmd = ostrcat(cmd, "cat /tmp/tithek/get | wc -l", 1, 0);
71        lines = string_newline(command(cmd));
72        free(cmd); cmd = NULL;
73        debug(99, "line: %s", line);
74        debug(99, "lines: %s", lines);
75
76        if(lines == NULL || line == NULL) goto end;     
77       
78        int sline = atoi(lines) - atoi(line) - 1;
79        debug(99, "sline: %d", sline);
80        debug(99, "sline: %s", oitoa(sline));
81
82        cmd = ostrcat(cmd, "cat /tmp/tithek/get | tail -n", 1, 0);
83        cmd = ostrcat(cmd, oitoa(sline), 1, 0);
84        cmd = ostrcat(cmd, " | sed '1,1d' | zcat", 1, 0);
85        debug(99, "cmd: %s", cmd);     
86        tmpstr = command(cmd);
87        free(cmd); cmd = NULL;
88        free(lines); lines = NULL;
89        titheklog(debuglevel, "/tmp/putlocker2_tmpstr_zcat", NULL, tmpstr);
90
91        //get hash from tmpstr
92        char* pos = ostrstr(tmpstr, "<input type=\"hidden\" value=");
93        hashstr = getxmlentry(pos, "value=");
94        free(tmpstr); tmpstr = NULL;
95        debug(99, "hashstr: %s", hashstr);
96        if(hashstr == NULL) goto end;
97
98        hash = ostrcat(hash, "hash=", 1, 0);   
99        hash = ostrcat(hash, hashstr, 1, 0);
100        hash = ostrcat(hash, "&confirm=Continue+as+Free+User", 1, 0);
101        debug(99, "hash: %s", hash);
102
103        hashlen = oitoa(strlen(hash));
104        debug(99, "hashlen: %s", hashlen);
105
106        //create send string
107        send = ostrcat(send, "POST /file/", 1, 0);
108        send = ostrcat(send, file, 1, 0);
109        send = ostrcat(send, " HTTP/1.1\r\nContent-Length: ", 1, 0);
110        send = ostrcat(send, hashlen, 1, 0);
111        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: www.", 1, 0);
112        send = ostrcat(send, host, 1, 0);
113        send = ostrcat(send, "\r\nCookie: usender=", 1, 0);
114        send = ostrcat(send, usender, 1, 0);
115        send = ostrcat(send, " SERVERID=", 1, 0);
116        send = ostrcat(send, serverid, 1, 0);
117        send = ostrcat(send, " PHPSESSID=", 1, 0);
118        send = ostrcat(send, phpsessid, 1, 0);
119        send = ostrcat(send, "\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n", 1, 0);
120        send = ostrcat(send, hash, 1, 0);
121        debug(99, "send: %s", send);
122
123        sleep(7);
124        //send and receive answer
125        gethttpreal(tmphost, tmpfile, 80, "/tmp/tithek/x9", NULL, NULL, 0, send, NULL, 5000, 0);
126        sleep(1);
127        if(debuglevel == 99) system("cp -a /tmp/tithek/x9 /tmp/putlocker3_tmpstr_post");
128
129        free(send); send = NULL;
130        tmpstr = command("cat /tmp/tithek/x9 | sed '1,1d' | zcat");
131        titheklog(debuglevel, "/tmp/putlocker4_tmpstr_post_zcat", NULL, tmpstr);
132       
133        if(ostrstr(tmpstr, "warning_message") != NULL)
134        {
135                tmpstr = string_resub("<div class='warning_message'>", "</div>", tmpstr, 0);
136                tmpstr = strstrip(tmpstr);
137                if(tmpstr == NULL || strlen(tmpstr) == 0)
138                        tmpstr = ostrcat(_("The page is temporarily unavailable"), tmpstr, 0, 1);
139                textbox(_("Message"), _(tmpstr) , _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1200, 200, 0, 0);
140                goto end;
141        }
142        if(phpsessid == NULL || serverid == NULL) goto end;                     
143
144        //get streamlink
145        if(ostrstr(tmpstr, "playlist:") != NULL)
146                streamlink = getxmlentry(tmpstr, "playlist: '");
147        else
148        {
149                streamlink = string_resub("/get_file.php", "\">Download File</a>", tmpstr, 0); 
150                streamlink1 = ostrcat("http://www.", host, 0, 0);
151                streamlink1 = ostrcat(streamlink1, "/get_file.php", 1, 0);
152                streamlink1 = ostrcat(streamlink1, streamlink, 1, 0);
153                debug(99, "stream downloadlink");
154                goto end;
155        }
156
157        debug(99, "streamlink: %s", streamlink);
158
159        if(streamlink != NULL)
160        {
161                char* pos = strchr(streamlink, '\'');
162                if(pos != NULL) pos[0] = '\0';
163        }
164        free(tmpstr); tmpstr = NULL;
165        if(streamlink == NULL) goto end;
166
167        //create send string
168        send = ostrcat(send, "GET ", 1, 0);
169        send = ostrcat(send, streamlink, 1, 0);
170        send = ostrcat(send, " HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: www.", 1, 0);
171        send = ostrcat(send, host, 1, 0);
172        send = ostrcat(send, "\r\nCookie: SERVERID=", 1, 0);
173        send = ostrcat(send, serverid, 1, 0);
174        send = ostrcat(send, "PHPSESSID=", 1, 0);
175        send = ostrcat(send, phpsessid, 1, 0);
176        send = ostrcat(send, "\r\nConnection: close\r\nUser-Agent: Python-urllib/2.6\r\n\r\n", 1, 0);
177
178        sleep(5);
179       
180        //send and receive answer
181        tmpstr = gethttpreal(tmphost, tmpfile, 80, NULL, NULL, NULL, 0, send, NULL, 5000, 0);
182        free(send); send = NULL;
183
184        titheklog(debuglevel, "/tmp/putlocker5_tmpstr_get", NULL, tmpstr);
185
186//Streaming version of this file is currently not available. You can download it below.
187
188        //get streamlink1
189        streamlink1 = getxmlentry(tmpstr, "url=");
190        titheklog(debuglevel, "/tmp/putlocker5_streamlink", NULL, streamlink1);
191
192        free(tmpstr); tmpstr = NULL;
193
194end:
195        free(tmphost); tmphost = NULL;
196        free(tmpfile); tmpfile = NULL;
197        free(tmpstr); tmpstr = NULL;
198        free(send); send = NULL;
199        free(hash); hash = NULL;
200        free(hashstr); hashstr = NULL;
201        free(hashlen); hashlen = NULL; 
202        free(ip); ip = NULL;
203        free(phpsessid); phpsessid = NULL;
204        free(serverid); serverid = NULL;
205        free(usender); usender = NULL;
206        free(streamlink); streamlink = NULL;
207
208        return streamlink1;
209}
210
211#endif
Note: See TracBrowser for help on using the repository browser.