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

Last change on this file since 40135 was 39993, checked in by obi, 7 years ago

update tithek

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