source: titan/plugins/tithek/myvideo.h @ 28696

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

[tithek] fix myvideo rtmpe streams

File size: 10.4 KB
Line 
1#ifndef MYVIDEO_H
2#define MYVIDEO_H
3
4// flag 1 = getstreamurl
5
6char* myvideo(char* input, char* url, char* name, int flag)
7{
8        debug(99, "link(%d): %s", flag, input);
9        int debuglevel = getconfigint("debuglevel", NULL);
10        char* ip = NULL, *pos = NULL, *path = NULL, *pageUrl = NULL, *playpath = NULL, *video_id = NULL, *source = NULL, *streamurl = NULL, *tmpstr_uni = NULL, *b64 = NULL, *key = NULL, *newurl = NULL, *link = NULL, *tmpstr = NULL, *tmppath = NULL, *error = NULL;
11
12        if(flag == 1)
13        {
14                int count = 0;
15                struct splitstr* ret1 = NULL;
16                ret1 = strsplit(input, ";", &count);
17                if(ret1 != NULL && count >= 4)
18                {
19                        link = ostrcat(ret1[0].part, NULL, 0, 0);
20                        pageUrl = ostrcat(pageUrl, ret1[1].part, 1, 0);
21                        playpath = ostrcat(playpath, ret1[2].part, 1, 0);
22                        video_id = ostrcat(video_id, ret1[3].part, 1, 0);                                                                       
23                }
24                free(ret1), ret1 = NULL;
25        }       
26
27        ip = string_replace("http://", "", (char*)link, 0);
28
29        if(ip != NULL)
30                pos = strchr(ip, '/');
31        if(pos != NULL)
32        {
33                pos[0] = '\0';
34                path = pos + 1;
35        }
36
37        tmppath = ostrcat("watch/", video_id , 0, 0);
38        tmppath = ostrcat(tmppath, "/" , 1, 0);
39        tmpstr = gethttp(ip, tmppath, 80, NULL, NULL, 10000, NULL, 0);
40        error = string_resub("<div class='lContent lContNoBorder error sBold sCenter'>", "</div>", tmpstr, 0);
41
42        unlink("/tmp/myvideo_tmpstr");
43        unlink("/tmp/myvideo_tmpstr_uni");
44        unlink("/tmp/myvideo_tmpstr_error");
45
46        titheklog(debuglevel, "/tmp/myvideo_tmpstr_error", NULL, tmpstr);
47                               
48        if(ostrstr(error, "<div class='error sBold' id='error_screen_body'>") == NULL)
49        {
50                textbox(_("Message"), _(error) , _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1200, 200, 0, 0);
51                debug(99, "error msg: %s", error);
52        }       
53       
54        debug(99, "error link: http://%s/%s", ip, tmppath);
55        free(tmpstr), tmpstr = NULL;
56        free(tmppath), tmppath = NULL;
57        free(error), error = NULL;
58       
59// not working tmpstr hat zusatzdaten im string
60        tmpstr = gethttp(ip, path, 80, NULL, NULL, 10000, NULL, 0);
61
62        debug(99, "link: http://%s/%s", ip, path);
63
64        titheklog(debuglevel, "/tmp/myvideo_tmpstr", NULL, tmpstr);
65
66/*
67// work start
68        unlink("/tmp/myvideo_tmp");
69        char* cmd = NULL;
70        cmd = ostrcat("wget \"", input, 0, 0);
71        cmd = ostrcat(cmd, "\" -O /tmp/myvideo_tmp", 1, 0);
72        system(cmd);
73        free(cmd), cmd = NULL;
74        tmpstr = readfiletomem("/tmp/myvideo_tmp", 0);
75// work end
76*/
77        if(flag == 1)
78        {
79                int count = 0;
80                struct splitstr* ret1 = NULL;
81                ret1 = strsplit(tmpstr, "=", &count);
82                int hlen = 0;
83
84                if(ret1 != NULL && count >= 2)
85                {
86//                      debug(99, "ret1[1].part=%s", (ret1[1]).part);
87                        hlen = strlen(ret1[1].part);
88                        tmpstr_uni = unhexlify(ret1[1].part);
89                }
90                free(ret1), ret1 = NULL;
91
92                b64 = ostrcat("c8407a08b3c71ea418ec9dc662f2a56e40cbd6d5a114aa50fb1e1079e17f2b83", MDString(video_id), 0, 1);
93                debug(99, "b64=%s", b64);
94
95                key = MDString(b64);
96                int slen = 0;
97                int klen = 0;
98                if(tmpstr_uni != NULL) slen = strlen(tmpstr_uni);
99                if(key != NULL) klen = strlen(key);
100               
101                if(tmpstr_uni != NULL)
102                {
103                        debug(99, "hexlen=%d", hlen);
104                        hlen /= 2;
105                        debug(99, "binlen=%d", hlen);
106                        debug(99, "keylen=%d", klen);
107                        debug(99, "b64=%s", b64);
108                        debug(99, "key=%s", key);
109
110                        rc4(tmpstr_uni, hlen, key, klen);
111
112                        debug(99, "encrypted=%s", tmpstr_uni);
113                        debug(99, "pageUrl: %s\n", pageUrl);
114                        debug(99, "playpath: %s\n", playpath);
115                        debug(99, "video_id: %s\n", video_id);
116                        //printf("tmpstr_uni: %s\n",tmpstr_uni);
117
118                        htmldecode(tmpstr_uni, tmpstr_uni);
119
120                        titheklog(debuglevel, "/tmp/myvideo_tmpstr_uni", NULL, tmpstr_uni);
121
122                        if(ostrstr(tmpstr_uni, "connectionurl='rtmp"))
123                        {
124                                printf("found rtmpe:// stream\n");
125                                source = string_resub("source='", ".flv'", tmpstr_uni, 0);
126
127                                newurl = string_resub("connectionurl='", "'", tmpstr_uni, 0);
128
129/*
130                                if(ostrstr(newurl, "myvideo2flash"))
131                                {
132                                        printf("change to rtmpt:// stream\n");
133                                        newurl = string_replace("rtmpe://", "rtmpt://", newurl, 1);
134                                }
135*/
136                                newurl = string_replace("rtmpe://", "rtmp://", newurl, 1);
137       
138                                streamurl = ostrcat(newurl, NULL, 0, 0);
139                                streamurl = ostrcat(streamurl, " ", 1, 0);
140                                streamurl = ostrcat(streamurl, "tcUrl=", 1, 0);
141                                streamurl = ostrcat(streamurl, newurl, 1, 0);
142                                streamurl = ostrcat(streamurl, " swfVfy=http://is4.myvideo.de/de/player/mingR11q/ming.swf ", 1, 0);
143                                streamurl = ostrcat(streamurl, pageUrl, 1, 0);
144                                streamurl = ostrcat(streamurl, " ", 1, 0);
145                                streamurl = ostrcat(streamurl, "playpath=flv:", 1, 0);
146                                streamurl = ostrcat(streamurl, source, 1, 0);           
147                        }
148                        else
149                        {               
150                                printf("rtmpe not found, change to *.flv stream\n");
151                                source = string_resub("source='", "'", tmpstr_uni, 0);
152       
153                                newurl = string_resub("path='", "'", tmpstr_uni, 0);
154       
155                                streamurl = ostrcat(newurl, source, 0, 0);
156                        }
157                }
158        }
159
160        free(key), key = NULL;         
161        free(b64), b64 = NULL;
162        free(tmpstr_uni), tmpstr_uni = NULL;           
163        free(url), url = NULL;
164        free(source), source = NULL;
165        free(tmpstr), tmpstr = NULL;
166        free(pageUrl), pageUrl = NULL;         
167        free(playpath), playpath = NULL;
168        free(ip), ip = NULL;
169        free(video_id), video_id = NULL;
170        free(newurl), newurl = NULL;
171// segfault munmap_chunk(): invalid pointer
172//      free(pos), pos = NULL;
173//      free(path), path = NULL;
174
175//      debug(99, "streamurl2: %s", streamurl);
176        return streamurl;
177}
178
179int myvideo_search(struct skin* grid, struct skin* listbox, struct skin* countlabel, struct skin* load, char* link, char* title, char* searchstr, int flag)
180{
181        int ret = 1;
182
183        if(listbox == NULL || listbox->select == NULL || listbox->select->handle == NULL)
184                return ret;
185
186        char* search = NULL;
187
188        if(flag == 0)
189        {
190                if(searchstr == NULL)
191                        search = textinputhist(_("Search"), " ", "searchhist");
192                else
193                        search = textinputhist(_("Search"), searchstr, "searchhist");
194        }
195
196        if(search != NULL || flag > 0)
197        {
198                drawscreen(load, 0, 0);
199                search = stringreplacechar(search, ' ', '+');
200                char* id = NULL;
201                char* line = NULL;
202                char* pic = NULL;
203                char* title = NULL;
204                char* menu = NULL;
205                char* path = NULL;
206                char* ip = ostrcat("www.myvideo.de", NULL, 0, 0);
207
208                if(flag == 0)
209                        path = ostrcat("Videos_A-Z?searchWord=", search, 0, 0);
210                else
211                        path = ostrcat("Top_100/Top_100_Single_Charts", NULL, 0, 0);
212               
213                char* tmpstr = gethttp(ip, path, 80, NULL, NULL, 10000, NULL, 0);
214                tmpstr = string_replace_all("<", "\n", tmpstr, 1);
215                tmpstr = string_replace_all(">", "\n", tmpstr, 1);
216
217                int count = 0;
218                int incount = 0;
219                int i = 0;
220                struct splitstr* ret1 = NULL;
221                ret1 = strsplit(tmpstr, "\n", &count);
222
223                if(ret1 != NULL)
224                {
225                        int max = count;
226                        for(i = 0; i < max; i++)
227                        {                                                               
228                                if(ostrstr(ret1[i].part, "img id='i") != NULL)
229                                {
230                                        debug(99, "---------------------------");
231                                        debug(99, "ret1[i].part: %s", ret1[i].part);
232                                        int rcret = waitrc(NULL, 10, 0);
233                                        if(rcret == getrcconfigint("rcexit", NULL)) break;
234                                        pic = oregex(".*longdesc='(.*)' class='vThumb.*", ret1[i].part);
235                                        id = oregex(".*img id='i(.*)' onload=.*", ret1[i].part);
236                                        title = oregex(".*alt='(.*)' onmouseover=.*", ret1[i].part);
237                                        debug(99, "title: %s", title);
238                                        debug(99, "pic: %s", pic);
239                                        debug(99, "id: %s", id);
240                                        debug(99, "---------------------------");
241
242                                        if(id != NULL)
243                                        {
244                                                incount += 1;
245                                                line = ostrcat(line, title, 1, 0);
246//                                              line = ostrcat(line, "#http://www.myvideo.de/dynamic/get_player_video_xml.php?flash_playertype=SER&ID=", 1, 0);
247// de fix
248                                                line = ostrcat(line, "#http://www.myvideo.de/dynamic/get_player_video_xml.php?domain=www.myvideo.de&flash_playertype=D&ds=1&autorun=yes&ID=", 1, 0);
249                                                line = ostrcat(line, id, 1, 0);
250//                                              line = ostrcat(line, "&_countlimit=4&autorun=yes;pageUrl=http://www.myvideo.de/watch/", 1, 0);                                                                         
251// de fix
252                                                line = ostrcat(line, "&_countlimit=4;pageUrl=http://www.myvideo.de/watch/", 1, 0);                                                                             
253                                                line = ostrcat(line, id, 1, 0);
254                                                line = ostrcat(line, "/;playpath=flv:movie24/a0/", 1, 0);
255                                                line = ostrcat(line, id, 1, 0);
256                                                line = ostrcat(line, ";", 1, 0);
257                                                line = ostrcat(line, id, 1, 0);                                                                                                                                                         
258                                                line = ostrcat(line, "#", 1, 0);
259                                                line = ostrcat(line, pic, 1, 0);
260                                                line = ostrcat(line, "#myvideo_search_", 1, 0);
261                                                line = ostrcat(line, oitoa(incount + time(NULL)), 1, 0);
262                                                line = ostrcat(line, ".jpg#MyVideo - Search#12\n", 1, 0);
263                                                free(ip), ip = NULL;
264                                                free(path), path = NULL;
265                                                free(title), title = NULL;
266                                        }
267
268                                }
269                        }
270                        free(ret1), ret1 = NULL;
271
272                        if(line != NULL)
273                        {
274                                menu = ostrcat("/tmp/tithek/myvideo.search.list", NULL, 0, 0);
275                                writesys(menu, line, 0);
276                                struct tithek* tnode = (struct tithek*)listbox->select->handle;
277                                createtithek(tnode, tnode->title, menu, tnode->pic, tnode->localname, tnode->menutitle, tnode->flag);
278                                ret = 0;
279                        }
280                }
281                free(tmpstr), tmpstr = NULL;
282        }
283        free(search), search = NULL;
284        return ret;
285}
286
287int myvideo_search_local(struct skin* grid, struct skin* listbox, struct skin* countlabel, struct skin* load, char* link, char* title, char* searchstr, int flag)
288{
289        char* tmpstr = NULL, *tmpstr1 = NULL, *line = NULL, *menu = NULL, *search = NULL;
290        int ret = 1, count = 0, i = 0;
291
292        if(listbox == NULL || listbox->select == NULL || listbox->select->handle == NULL)
293                return ret;
294
295        if(searchstr == NULL)
296                search = textinputhist(_("Search"), " ", "searchhist");
297        else
298                search = textinputhist(_("Search"), searchstr, "searchhist");
299
300        if(search != NULL)
301        {
302                drawscreen(load, 0, 0);
303
304                strstrip(search);
305                string_tolower(search);
306
307                tmpstr = gethttp("atemio.dyndns.tv", "/mediathek/myvideo/streams/myvideo.all-sorted.list", 80, NULL, HTTPAUTH, 5000, NULL, 0);
308
309                struct splitstr* ret1 = NULL;
310                ret1 = strsplit(tmpstr, "\n", &count);
311
312                if(ret1 != NULL)
313                {
314                        int max = count;
315                        for(i = 0; i < max; i++)
316                        {
317                       
318                                tmpstr1 = ostrcat(ret1[i].part, NULL, 0, 0);
319                                tmpstr1 = stringreplacecharonce(tmpstr1, '#', '\0');
320                                string_tolower(tmpstr1);
321
322                                if(ostrstr(tmpstr1, search) != NULL)
323                                {
324                                        printf("found: %s\n", ret1[i].part);
325                                        int rcret = waitrc(NULL, 10, 0);
326                                        if(rcret == getrcconfigint("rcexit", NULL)) break;
327
328                                        line = ostrcat(line, ret1[i].part, 1, 0);
329                                        line = ostrcat(line, "\n", 0, 0);
330                                }
331                                free(tmpstr1), tmpstr1 = NULL;                         
332                        }
333                        free(ret1), ret1 = NULL;
334
335                        if(line != NULL)
336                        {
337                                line = string_replace_all("http://atemio.dyndns.tv/", "http://imageshack.us/md/up/grd/", line, 1);
338                                menu = ostrcat("/tmp/tithek/myvideo.search.list", NULL, 0, 0);
339                                writesys(menu, line, 0);
340                                struct tithek* tnode = (struct tithek*)listbox->select->handle;
341                                createtithek(tnode, tnode->title, menu, tnode->pic, tnode->localname, tnode->menutitle, tnode->flag);
342                                ret = 0;
343                        }
344                }
345                free(tmpstr), tmpstr = NULL;
346        }
347        free(search), search = NULL;
348        return ret;
349}
350
351#endif
Note: See TracBrowser for help on using the repository browser.