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

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

[titan] tithek optimize

File size: 5.0 KB
RevLine 
[19637]1#ifndef VIDSTREAM_H
2#define VIDSTREAM_H
3
4char* vidstream(char* host, char* file)
5{
6        debug(99, "in host: %s file: %s", host, file);
[24238]7        int debuglevel = getconfigint("debuglevel", NULL);
[19637]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* 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
25        if(host == NULL || file == NULL) return NULL;
26
27        tmphost = ostrcat("www.", host, 0, 0);
28        tmpfile = ostrcat("/file/", file, 0, 0);
29        debug(99, "tmphost: %s", tmphost);
30        ip = get_ip(tmphost);
31        debug(99, "ip: %s", ip);
32        debug(99, "tmpfile: %s", tmpfile);
33        debug(99, "file: %s", file);
34
35        send = ostrcat(send, "GET /", 1, 0);
36        send = ostrcat(send, file, 1, 0);
37        send = ostrcat(send, " HTTP/1.1\r\nHost: ", 1, 0);     
38        send = ostrcat(send, host, 1, 0);
39        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);       
40        debug(99, "tmphost: %s", tmphost);
41        debug(99, "tmpfile: %s", tmpfile);
42        debug(99, "send: %s", send);
[19841]43        tmpstr = gethttpreal(tmphost, tmpfile, 80, NULL, NULL, NULL, 0, send, NULL, 5000, 1);
[19637]44
[24238]45        titheklog(debuglevel, "/tmp/vidstream1_tmpstr", NULL, tmpstr);
[19878]46
[19637]47        sleep(1);
48
[19794]49        if(ostrstr(tmpstr, "<b>File Not Found</b>") != NULL)
50        {
51                tmpstr = string_resub("<Center>", "</Center>", tmpstr, 1);
52                string_deltags(tmpstr);
53                tmpstr = string_replace("Terms", "\nTerms", tmpstr, 1);
[21018]54                tmpstr = strstrip(tmpstr);
55                if(tmpstr == NULL || strlen(tmpstr) == 0)
56                        tmpstr = ostrcat(_("The page is temporarily unavailable"), tmpstr, 0, 1);
[19794]57                textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1200, 400, 0, 0);
58                goto end;
59        }
60               
[19637]61        //get hash from tmpstr
62        char* pos1 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"fname\" value=");
63        fname = getxmlentry(pos1, "value=");
64        debug(99, "fname: %s", fname);
65        if(fname == NULL) goto end;
66
67        char* pos2 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"id\" value=");
68        id = getxmlentry(pos2, "value=");
69        debug(99, "id: %s", id);
70        if(id == NULL) goto end;
71
72        char* pos3 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"op\" value=");
73        op = getxmlentry(pos3, "value=");
74
75        char* pos4 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"hash\" value=");
76        hashline = getxmlentry(pos4, "value=");
77
78        char* pos5 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"referer\" value=");
79        referer = getxmlentry(pos5, "value=");
80
81        char* pos6 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"imhuman\" value=");
82        imhuman = getxmlentry(pos6, "value=");
83
84        char* pos7 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"usr_login\" value=");
85        usr_login = getxmlentry(pos7, "value=");
86       
87        free(tmpstr); tmpstr = NULL;
88        debug(99, "op: %s", op);
89        if(op == NULL) goto end;
90
91        hash = ostrcat(hash, "hash=", 1, 0);
92        hash = ostrcat(hash, hashline, 1, 0);
93        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);
94        hash = ostrcat(hash, "&usr_login=", 1, 0);     
95        hash = ostrcat(hash, usr_login, 1, 0);
96        hash = ostrcat(hash, "&referer=", 1, 0);
97        hash = ostrcat(hash, referer, 1, 0);
98        hash = ostrcat(hash, "&fname=", 1, 0);
99        hash = ostrcat(hash, fname, 1, 0);
100        hash = ostrcat(hash, "&id=", 1, 0);     
101        hash = ostrcat(hash, id, 1, 0);
102        hash = ostrcat(hash, "&op=download1", 1, 0);
103//      hash = ostrcat(hash, op, 1, 0);
104        debug(99, "hash: %s", hash);
105        hashlen = oitoa(strlen(hash));
106
107        //create send string
108        free(send), send = NULL;
109
110        send = ostrcat(send, "POST /", 1, 0);
111        send = ostrcat(send, file, 1, 0);
112        send = ostrcat(send, " HTTP/1.1\r\nContent-Length: ", 1, 0);
113        send = ostrcat(send, hashlen, 1, 0);
114        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);
115        send = ostrcat(send, host, 1, 0);
116        send = ostrcat(send, "\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n", 1, 0);
117        send = ostrcat(send, hash, 1, 0);
118        debug(99, "send: %s", send);
119
120        free(tmpstr), tmpstr = NULL;
[19841]121        tmpstr = gethttpreal(tmphost, tmpfile, 80, NULL, NULL, NULL, 0, send, NULL, 5000, 1);
[19637]122       
[24238]123        titheklog(debuglevel, "/tmp/vidstream2_tmpstr_post", NULL, tmpstr);
[19637]124
125        sleep(1);
126        streamlink = string_resub("file: \"", "\",", tmpstr, 0);
127
[24238]128        titheklog(debuglevel, "/tmp/vidstream3_streamlink", NULL, streamlink);
[19879]129
[19637]130end:
131
132        free(hash), hash = NULL;
133        free(hashlen), hashlen = NULL;
134        free(op), op = NULL;
135        free(id), id = NULL;
136        free(fname), fname = NULL;
137               
138        free(tmphost); tmphost = NULL;
139        free(tmpfile); tmpfile = NULL;
140        free(tmpstr); tmpstr = NULL;
141        free(send); send = NULL;
142        free(ip); ip = NULL;
143
144        return streamlink;
145}
146
147#endif
Note: See TracBrowser for help on using the repository browser.