source: titan/plugins/tithek/youtube.h @ 25158

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

[tithek] add to all theken a search local entry, here search all pre parsed entrys

File size: 11.4 KB
Line 
1#ifndef YOUTUBE_H
2#define YOUTUBE_H
3
4// flag 1 = getstreamurl
5
6char* youtube(char* link, char* url, char* name, int flag)
7{
8        debug(99, "link(%d): %s", flag, link);
9        char* ip = NULL, *pos = NULL, *path = NULL, *streamurl = NULL, *title = NULL, *tmpstr = NULL, *murl = NULL, *sig = NULL, *pic = NULL;
10               
11        ip = string_replace("http://", "", (char*)link, 0);
12
13        if(ip != NULL)
14                pos = strchr(ip, '/');
15        if(pos != NULL)
16        {
17                pos[0] = '\0';
18                path = pos + 1;
19        }
20
21/* spox.com
22
23http://www.spox.com/de/sport/ussport/nba/live-stream/1310/miami-heat-washington-wizards-frank-buschmann.html
24grep code:
25<div id="spxliveplayer"><iframe frameborder="0" width="640px" height="360px" scrolling="no" src="http://www.youtube.com/embed/SjMEn0d6ByU" id="spxliveiframe" ></iframe></div>
26
27and get to youtube
28*/
29
30        tmpstr = gethttp(ip, path, 80, NULL, NULL, 10000, NULL, 0);
31//      writesys("/var/usr/local/share/titan/plugins/tithek/youtube_tmpstr", tmpstr, 0);
32
33        if(flag == 1)
34        {
35                if(ostrstr(tmpstr, "&hlsvp=") != NULL)
36                {
37                        printf("found NBA1\n");
38                        streamurl = string_resub("&hlsvp=", "&", tmpstr, 0);
39                        string_decode(streamurl,0);
40                        string_decode(streamurl,0);
41                        string_decode(streamurl,0);
42                        string_decode(streamurl,0);
43                        string_decode(streamurl,0);
44                        string_decode(streamurl,0);     
45                }
46                else if(ostrstr(tmpstr, "status=fail&") == NULL)
47                {
48                        struct splitstr* ret1 = NULL;
49                        struct menulist* mlist = NULL, *mbox = NULL;
50                        int count = 0, i = 0;
51                        tmpstr = ostrcat(tmpstr,"&",0,0);
52                        tmpstr = string_resub("url_encoded_fmt_stream_map=","&",tmpstr,0);
53
54                        if(tmpstr != NULL)
55                        {
56                                ret1 = strsplit(string_decode(tmpstr,0),",",&count);
57
58                                for(i = 0; i < count; i++)
59                                {
60                                        if(ret1[i].part != NULL && strlen(ret1[i].part) > 1)
61                                        {
62                                                debug(99, "\nRound %d started, processing = %s",i,ret1[i].part);
63                                                ret1[i].part = ostrcat(ret1[i].part,"&",0,0);
64                                               
65                                                murl = string_resub("url=","&",ret1[i].part,0);
66                                                sig = string_resub("sig=","&",ret1[i].part,0);
67                                               
68                                                free(streamurl), streamurl = NULL;
69                                                if(murl != NULL && sig != NULL)
70                                                {                                       
71                                                        streamurl = ostrcat(murl, NULL, 0, 0);
72                                                        streamurl = ostrcat(streamurl, "&signature=", 1, 0);
73                                                        streamurl = ostrcat(streamurl, sig, 1, 0);
74                                                        streamurl = string_decode(streamurl,0);
75                                                                                                                       
76                                                        if(ostrstr(ret1[i].part, "itag=85") != NULL)
77                                                        {
78                                                                title = ostrcat("MP4 520p H.264 3D", NULL, 0, 0);
79                                                                pic = ostrcat("mp4.png", NULL, 0, 0);
80                                                        }
81                                                        else if(ostrstr(ret1[i].part, "itag=84") != NULL)
82                                                        {
83                                                                title = ostrcat("MP4 720p H.264 3D", NULL, 0, 0);
84                                                                pic = ostrcat("mp4.png", NULL, 0, 0);
85                                                        }
86                                                        else if(ostrstr(ret1[i].part, "itag=83") != NULL)
87                                                        {
88                                                                title = ostrcat("MP4 240p H.264 3D", NULL, 0, 0);
89                                                                pic = ostrcat("mp4.png", NULL, 0, 0);
90                                                        }
91                                                        else if(ostrstr(ret1[i].part, "itag=82") != NULL)
92                                                        {
93                                                                title = ostrcat("MP4 360p H.264 3D", NULL, 0, 0);
94                                                                pic = ostrcat("mp4.png", NULL, 0, 0);
95                                                        }
96                                                        else if(ostrstr(ret1[i].part, "itag=38") != NULL)
97                                                        {
98                                                                title = ostrcat("MP4 3072p H.264 High", NULL, 0, 0);
99                                                                pic = ostrcat("mp4.png", NULL, 0, 0);
100                                                        }
101                                                        else if(ostrstr(ret1[i].part, "itag=37") != NULL)
102                                                        {
103                                                                title = ostrcat("MP4 1080p H.264 High", NULL, 0, 0);
104                                                                pic = ostrcat("mp4.png", NULL, 0, 0);
105                                                        }
106                                                        else if(ostrstr(ret1[i].part, "itag=22") != NULL)
107                                                        {
108                                                                title = ostrcat("MP4 720p H.264 High", NULL, 0, 0);
109                                                                pic = ostrcat("mp4.png", NULL, 0, 0);
110                                                        }
111                                                        else if(ostrstr(ret1[i].part, "itag=18") != NULL)
112                                                        {
113                                                                title = ostrcat("MP4 360p H.264 Baseline", NULL, 0, 0);                                                                                         
114                                                                pic = ostrcat("mp4.png", NULL, 0, 0);
115                                                        }
116                                                        else if(ostrstr(ret1[i].part, "itag=6") != NULL)
117                                                        {
118                                                                title = ostrcat("FLV 270p Sorenson H.263", NULL, 0, 0);
119                                                                pic = ostrcat("flv.png", NULL, 0, 0);
120                                                        }
121                                                        else if(ostrstr(ret1[i].part, "itag=5") != NULL)
122                                                        {
123                                                                title = ostrcat("FLV 240p Sorenson H.263", NULL, 0, 0);
124                                                                pic = ostrcat("flv.png", NULL, 0, 0);
125                                                        }
126                                                        else if(ostrstr(ret1[i].part, "itag=35") != NULL)
127                                                        {
128                                                                title = ostrcat("FLV 480p H.264 Main", NULL, 0, 0);
129                                                                pic = ostrcat("flv.png", NULL, 0, 0);
130                                                        }
131                                                        else if(ostrstr(ret1[i].part, "itag=34") != NULL)
132                                                        {
133                                                                title = ostrcat("FLV 360p H.264 Main", NULL, 0, 0);                                                                                                             
134                                                                pic = ostrcat("3gp.png", NULL, 0, 0);
135                                                        }
136                                                        else if(ostrstr(ret1[i].part, "itag=36") != NULL)
137                                                        {
138                                                                title = ostrcat("3GP 240p MPEG-4 Visual Simple", NULL, 0, 0);
139                                                                pic = ostrcat("3gp.png", NULL, 0, 0);
140                                                        }
141                                                        else if(ostrstr(ret1[i].part, "itag=17") != NULL)
142                                                        {
143                                                                title = ostrcat("3GP 144p MPEG-4 Visual Simple", NULL, 0, 0);
144                                                                pic = ostrcat("3gp.png", NULL, 0, 0);
145                                                        }
146                                                                                                               
147                                                        if(title == NULL)
148                                                        {
149                                                                title = ostrcat(_("unknown"), NULL, 0, 0);
150                                                                debug(99, "(%d) title: %s streamurl: %s\n", i, title, streamurl);
151                                                                debug(99, "(%d) ret1 %s\n",i, (ret1[i]).part);
152                                                        }
153                                                        else
154                                                        {
155                                                                debug(99, "(%d) title: %s streamurl: %s\n", i, title, streamurl);                                                                                                                                                                                                       
156                                                                addmenulist(&mlist, title, streamurl, pic, 0, 0);
157                                                        }
158                                                        free(title), title = NULL;
159                                                        free(pic), pic = NULL;
160                                                        free(streamurl), streamurl = NULL;
161                                                 
162                                                }
163                                                free(murl), murl = NULL;
164                                                free(sig), sig = NULL;
165                                        }
166
167                                        // TODO handle error while parsing
168       
169                                }
170                                free(ret1), ret1 = NULL;
171
172                                if(mlist != NULL){
173                                        mbox = menulistbox(mlist, NULL, NULL, NULL, NULL, 1, 0);
174                                        if(mbox != NULL){
175                                            free(streamurl), streamurl = NULL;
176                   
177                                            debug(99, "mbox->name %s", mbox->name);
178                                            debug(99, "mbox->text %s", mbox->text);
179                                            streamurl = ostrcat(mbox->text, NULL, 0, 0);
180                   
181                                        }
182                                }
183                        }
184                }
185                else
186                {       
187                        tmpstr = string_resub("&reason=", "&errordetail", tmpstr, 1);
188                        tmpstr = string_replace_all("+", " ", tmpstr, 1);
189                        tmpstr = string_replace_all(", ", "\n", tmpstr, 1);
190                        tmpstr = string_replace("wiedergegeben", "\nwiedergegeben ", tmpstr, 1);
191                        tmpstr = string_replace("<br/><u><a href='", "\n\n", tmpstr, 1);
192                        tmpstr = string_replace("' target='_blank'>", "\n", tmpstr, 1);
193                        tmpstr = string_replace("</a></u>", "\n", tmpstr, 1);
194
195                        tmpstr = strstrip(tmpstr);
196                        if(tmpstr != NULL && strlen(tmpstr) > 0)
197                                textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1200, 400, 0, 0);
198                }
199        }
200
201        free(tmpstr); tmpstr = NULL;
202        free(title); title = NULL;
203        free(ip), ip = NULL;
204
205// segfault munmap_chunk(): invalid pointer
206//      free(pos), pos = NULL;
207//      free(path), path = NULL;
208
209        debug(99, "streamurl2: %s", streamurl);
210        return streamurl;
211}
212
213int youtube_search(struct skin* grid, struct skin* listbox, struct skin* countlabel, struct skin* load, char* link, char* title, char* searchstr)
214{
215        int ret = 1;
216
217        if(listbox == NULL || listbox->select == NULL || listbox->select->handle == NULL)
218                return ret;
219
220        char* search = NULL;
221        if(searchstr == NULL)
222                search = textinputhist("Search", " ", "searchhist");
223        else
224                search = textinputhist("Search", searchstr, "searchhist");
225
226        if(search != NULL)
227        {
228                drawscreen(load, 0, 0);
229                search = stringreplacechar(search, ' ', '+');
230                char* id = NULL;
231                char* line = NULL;
232                char* pic = NULL;
233                char* title = NULL;
234                char* menu = NULL;     
235                char* ip = ostrcat("gdata.youtube.com", NULL, 0, 0);
236                char* path = ostrcat("feeds/api/videos?q=", search, 0, 0);
237                if(((struct tithek*)listbox->select->handle)->flag == 9)
238                        path = ostrcat(path, "&max-results=10", 1, 0);
239                else if(((struct tithek*)listbox->select->handle)->flag == 10)
240                        path = ostrcat(path, "&max-results=25", 1, 0);
241                else if(((struct tithek*)listbox->select->handle)->flag == 11)
242                        path = ostrcat(path, "&max-results=50", 1, 0);
243                                       
244                char* tmpstr = gethttp(ip, path, 80, NULL, NULL, 10000, NULL, 0);
245                tmpstr = string_replace_all("media:thumbnail", "\nthumbnail", tmpstr, 1);
246
247                int count = 0;
248                int incount = 0;
249                int i = 0;
250                struct splitstr* ret1 = NULL;
251                ret1 = strsplit(tmpstr, "\n", &count);
252
253                if(ret1 != NULL)
254                {
255                        int max = count;
256                        for(i = 0; i < max; i++)
257                        {
258                                if(ostrstr(ret1[i].part, "http://i.ytimg.com/vi/") != NULL)
259                                {
260                                        pic = oregex(".*thumbnail url=\'(http://i.ytimg.com/vi/.*/0.jpg).*", ret1[i].part);
261                                        id = oregex(".*thumbnail url=\'http://i.ytimg.com/vi/(.*)/0.jpg.*", ret1[i].part);
262                                        int rcret = waitrc(NULL, 10, 0);
263                                        if(rcret == getrcconfigint("rcexit", NULL)) break;
264
265                                        if(id != NULL)
266                                        {
267                                                incount += 1;
268                                                ip = ostrcat("www.youtube.com", NULL, 0, 0);
269                                                path = ostrcat("watch?v=", id, 0, 0);
270                                                title = gethttp(ip, path, 80, NULL, NULL, 10000, NULL, 0);
271                                                title = string_resub("<meta name=\"title\" content=\"", "\">", title, 0);
272
273                                                line = ostrcat(line, title, 1, 0);
274//                                                                              line = ostrcat(line, "#http://www.youtube.com/watch?v=", 1, 0);
275                                                line = ostrcat(line, "#http://www.youtube.com/get_video_info?&video_id=", 1, 0);
276                                                line = ostrcat(line, id, 1, 0);
277                                                line = ostrcat(line, "#", 1, 0);
278                                                line = ostrcat(line, pic, 1, 0);
279                                                line = ostrcat(line, "#youtube_search_", 1, 0);
280                                                line = ostrcat(line, oitoa(incount + time(NULL)), 1, 0);
281                                                line = ostrcat(line, ".jpg#YouTube - Search#4\n", 1, 0);
282                                                free(ip), ip = NULL;
283                                                free(path), path = NULL;
284                                                free(title), title = NULL;
285                                        }
286                                }
287                        }
288                        free(ret1), ret1 = NULL;
289
290                        if(line != NULL)
291                        {
292                                menu = ostrcat("/tmp/tithek/youtube.search.list", NULL, 0, 0);
293                                writesys(menu, line, 0);
294                                struct tithek* tnode = (struct tithek*)listbox->select->handle;
295                                createtithek(tnode, tnode->title, menu, tnode->pic, tnode->localname, tnode->menutitle, tnode->flag);
296                                ret = 0;
297                        }
298                }
299                free(tmpstr), tmpstr = NULL;
300        }
301        free(search), search = NULL;
302        return ret;
303}
304
305int youtube_search_local(struct skin* grid, struct skin* listbox, struct skin* countlabel, struct skin* load, char* link, char* title, char* searchstr, int flag)
306{
307        char* tmpstr = NULL, *tmpstr1 = NULL, *line = NULL, *menu = NULL, *search = NULL;
308        int ret = 1, count = 0, i = 0;
309
310        if(listbox == NULL || listbox->select == NULL || listbox->select->handle == NULL)
311                return ret;
312
313        if(searchstr == NULL)
314                search = textinputhist("Search", " ", "searchhist");
315        else
316                search = textinputhist("Search", searchstr, "searchhist");
317
318        if(search != NULL)
319        {
320                drawscreen(load, 0, 0);
321
322                strstrip(search);
323                string_tolower(search);
324
325                tmpstr = gethttp("atemio.dyndns.tv", "/mediathek/youtube/streams/youtube.all-sorted.list", 80, NULL, HTTPAUTH, 5000, NULL, 0);
326
327                struct splitstr* ret1 = NULL;
328                ret1 = strsplit(tmpstr, "\n", &count);
329
330                if(ret1 != NULL)
331                {
332                        int max = count;
333                        for(i = 0; i < max; i++)
334                        {
335                       
336                                tmpstr1 = ostrcat(ret1[i].part, NULL, 0, 0);
337                                tmpstr1 = stringreplacecharonce(tmpstr1, '#', '\0');
338                                string_tolower(tmpstr1);
339
340                                if(ostrstr(tmpstr1, search) != NULL)
341                                {
342                                        printf("found: %s\n", ret1[i].part);
343                                        int rcret = waitrc(NULL, 10, 0);
344                                        if(rcret == getrcconfigint("rcexit", NULL)) break;
345
346                                        line = ostrcat(line, ret1[i].part, 1, 0);
347                                        line = ostrcat(line, "\n", 0, 0);
348                                }
349                                free(tmpstr1), tmpstr1 = NULL;                         
350                        }
351                        free(ret1), ret1 = NULL;
352
353                        if(line != NULL)
354                        {
355                                menu = ostrcat("/tmp/tithek/youtube.search.list", NULL, 0, 0);
356                                writesys(menu, line, 0);
357                                struct tithek* tnode = (struct tithek*)listbox->select->handle;
358                                createtithek(tnode, tnode->title, menu, tnode->pic, tnode->localname, tnode->menutitle, tnode->flag);
359                                ret = 0;
360                        }
361                }
362                free(tmpstr), tmpstr = NULL;
363        }
364        free(search), search = NULL;
365        return ret;
366}
367
368#endif
Note: See TracBrowser for help on using the repository browser.