1 | #ifndef YOUTUBE_H |
---|
2 | #define YOUTUBE_H |
---|
3 | |
---|
4 | // flag 1 = getstreamurl |
---|
5 | |
---|
6 | char* 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 | tmpstr = gethttp(ip, path, 80, NULL, NULL, 10000, NULL, 0); |
---|
22 | if(flag == 1) |
---|
23 | { |
---|
24 | |
---|
25 | if(ostrstr(tmpstr, "status=fail&") == NULL) |
---|
26 | { |
---|
27 | struct splitstr* ret1 = NULL; |
---|
28 | struct menulist* mlist = NULL, *mbox = NULL; |
---|
29 | int count = 0, i = 0; |
---|
30 | tmpstr = ostrcat(tmpstr,"&",0,0); |
---|
31 | tmpstr = string_resub("url_encoded_fmt_stream_map=","&",tmpstr,0); |
---|
32 | |
---|
33 | if(tmpstr != NULL) |
---|
34 | { |
---|
35 | ret1 = strsplit(string_decode(tmpstr,0),",",&count); |
---|
36 | |
---|
37 | for(i = 0; i < count; i++) |
---|
38 | { |
---|
39 | if(ret1[i].part != NULL && strlen(ret1[i].part) > 1) |
---|
40 | { |
---|
41 | debug(99, "\nRound %d started, processing = %s",i,ret1[i].part); |
---|
42 | ret1[i].part = ostrcat(ret1[i].part,"&",0,0); |
---|
43 | |
---|
44 | murl = string_resub("url=","&",ret1[i].part,0); |
---|
45 | sig = string_resub("sig=","&",ret1[i].part,0); |
---|
46 | |
---|
47 | free(streamurl), streamurl = NULL; |
---|
48 | if(murl != NULL && sig != NULL) |
---|
49 | { |
---|
50 | streamurl = ostrcat(murl, NULL, 0, 0); |
---|
51 | streamurl = ostrcat(streamurl, "&signature=", 1, 0); |
---|
52 | streamurl = ostrcat(streamurl, sig, 1, 0); |
---|
53 | streamurl = string_decode(streamurl,0); |
---|
54 | |
---|
55 | if(ostrstr(ret1[i].part, "itag=85") != NULL) |
---|
56 | { |
---|
57 | title = ostrcat("MP4 520p H.264 3D", NULL, 0, 0); |
---|
58 | pic = ostrcat("mp4.png", NULL, 0, 0); |
---|
59 | } |
---|
60 | else if(ostrstr(ret1[i].part, "itag=84") != NULL) |
---|
61 | { |
---|
62 | title = ostrcat("MP4 720p H.264 3D", NULL, 0, 0); |
---|
63 | pic = ostrcat("mp4.png", NULL, 0, 0); |
---|
64 | } |
---|
65 | else if(ostrstr(ret1[i].part, "itag=83") != NULL) |
---|
66 | { |
---|
67 | title = ostrcat("MP4 240p H.264 3D", NULL, 0, 0); |
---|
68 | pic = ostrcat("mp4.png", NULL, 0, 0); |
---|
69 | } |
---|
70 | else if(ostrstr(ret1[i].part, "itag=82") != NULL) |
---|
71 | { |
---|
72 | title = ostrcat("MP4 360p H.264 3D", NULL, 0, 0); |
---|
73 | pic = ostrcat("mp4.png", NULL, 0, 0); |
---|
74 | } |
---|
75 | else if(ostrstr(ret1[i].part, "itag=38") != NULL) |
---|
76 | { |
---|
77 | title = ostrcat("MP4 3072p H.264 High", NULL, 0, 0); |
---|
78 | pic = ostrcat("mp4.png", NULL, 0, 0); |
---|
79 | } |
---|
80 | else if(ostrstr(ret1[i].part, "itag=37") != NULL) |
---|
81 | { |
---|
82 | title = ostrcat("MP4 1080p H.264 High", NULL, 0, 0); |
---|
83 | pic = ostrcat("mp4.png", NULL, 0, 0); |
---|
84 | } |
---|
85 | else if(ostrstr(ret1[i].part, "itag=22") != NULL) |
---|
86 | { |
---|
87 | title = ostrcat("MP4 720p H.264 High", NULL, 0, 0); |
---|
88 | pic = ostrcat("mp4.png", NULL, 0, 0); |
---|
89 | } |
---|
90 | else if(ostrstr(ret1[i].part, "itag=18") != NULL) |
---|
91 | { |
---|
92 | title = ostrcat("MP4 360p H.264 Baseline", NULL, 0, 0); |
---|
93 | pic = ostrcat("mp4.png", NULL, 0, 0); |
---|
94 | } |
---|
95 | else if(ostrstr(ret1[i].part, "itag=6") != NULL) |
---|
96 | { |
---|
97 | title = ostrcat("FLV 270p Sorenson H.263", NULL, 0, 0); |
---|
98 | pic = ostrcat("flv.png", NULL, 0, 0); |
---|
99 | } |
---|
100 | else if(ostrstr(ret1[i].part, "itag=5") != NULL) |
---|
101 | { |
---|
102 | title = ostrcat("FLV 240p Sorenson H.263", NULL, 0, 0); |
---|
103 | pic = ostrcat("flv.png", NULL, 0, 0); |
---|
104 | } |
---|
105 | else if(ostrstr(ret1[i].part, "itag=35") != NULL) |
---|
106 | { |
---|
107 | title = ostrcat("FLV 480p H.264 Main", NULL, 0, 0); |
---|
108 | pic = ostrcat("flv.png", NULL, 0, 0); |
---|
109 | } |
---|
110 | else if(ostrstr(ret1[i].part, "itag=34") != NULL) |
---|
111 | { |
---|
112 | title = ostrcat("FLV 360p H.264 Main", NULL, 0, 0); |
---|
113 | pic = ostrcat("3gp.png", NULL, 0, 0); |
---|
114 | } |
---|
115 | else if(ostrstr(ret1[i].part, "itag=36") != NULL) |
---|
116 | { |
---|
117 | title = ostrcat("3GP 240p MPEG-4 Visual Simple", NULL, 0, 0); |
---|
118 | pic = ostrcat("3gp.png", NULL, 0, 0); |
---|
119 | } |
---|
120 | else if(ostrstr(ret1[i].part, "itag=17") != NULL) |
---|
121 | { |
---|
122 | title = ostrcat("3GP 144p MPEG-4 Visual Simple", NULL, 0, 0); |
---|
123 | pic = ostrcat("3gp.png", NULL, 0, 0); |
---|
124 | } |
---|
125 | |
---|
126 | if(title == NULL) |
---|
127 | { |
---|
128 | title = ostrcat(_("unknown"), NULL, 0, 0); |
---|
129 | debug(99, "(%d) title: %s streamurl: %s\n", i, title, streamurl); |
---|
130 | debug(99, "(%d) ret1 %s\n",i, (ret1[i]).part); |
---|
131 | } |
---|
132 | else |
---|
133 | { |
---|
134 | debug(99, "(%d) title: %s streamurl: %s\n", i, title, streamurl); |
---|
135 | addmenulist(&mlist, title, streamurl, pic, 0, 0); |
---|
136 | } |
---|
137 | free(title), title = NULL; |
---|
138 | free(pic), pic = NULL; |
---|
139 | free(streamurl), streamurl = NULL; |
---|
140 | |
---|
141 | } |
---|
142 | free(murl), murl = NULL; |
---|
143 | free(sig), sig = NULL; |
---|
144 | } |
---|
145 | |
---|
146 | // TODO handle error while parsing |
---|
147 | |
---|
148 | } |
---|
149 | free(ret1), ret1 = NULL; |
---|
150 | |
---|
151 | if(mlist != NULL){ |
---|
152 | mbox = menulistbox(mlist, NULL, NULL, NULL, NULL, 1, 0); |
---|
153 | if(mbox != NULL){ |
---|
154 | free(streamurl), streamurl = NULL; |
---|
155 | |
---|
156 | debug(99, "mbox->name %s", mbox->name); |
---|
157 | debug(99, "mbox->text %s", mbox->text); |
---|
158 | streamurl = ostrcat(mbox->text, NULL, 0, 0); |
---|
159 | |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | else |
---|
165 | { |
---|
166 | tmpstr = string_resub("&reason=", "&errordetail", tmpstr, 1); |
---|
167 | tmpstr = string_replace_all("+", " ", tmpstr, 1); |
---|
168 | tmpstr = string_replace_all(", ", "\n", tmpstr, 1); |
---|
169 | tmpstr = string_replace("wiedergegeben", "\nwiedergegeben ", tmpstr, 1); |
---|
170 | tmpstr = string_replace("<br/><u><a href='", "\n\n", tmpstr, 1); |
---|
171 | tmpstr = string_replace("' target='_blank'>", "\n", tmpstr, 1); |
---|
172 | tmpstr = string_replace("</a></u>", "\n", tmpstr, 1); |
---|
173 | |
---|
174 | tmpstr = strstrip(tmpstr); |
---|
175 | if(tmpstr != NULL && strlen(tmpstr) > 0) |
---|
176 | textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1200, 400, 0, 0); |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | free(tmpstr); tmpstr = NULL; |
---|
181 | free(title); title = NULL; |
---|
182 | free(ip), ip = NULL; |
---|
183 | |
---|
184 | // segfault munmap_chunk(): invalid pointer |
---|
185 | // free(pos), pos = NULL; |
---|
186 | // free(path), path = NULL; |
---|
187 | |
---|
188 | debug(99, "streamurl2: %s", streamurl); |
---|
189 | return streamurl; |
---|
190 | } |
---|
191 | |
---|
192 | int youtube_search(struct skin* grid, struct skin* listbox, struct skin* countlabel, struct skin* load, char* link, char* title, char* searchstr) |
---|
193 | { |
---|
194 | int ret = 1; |
---|
195 | |
---|
196 | if(listbox == NULL || listbox->select == NULL || listbox->select->handle == NULL) |
---|
197 | return ret; |
---|
198 | |
---|
199 | char* search = NULL; |
---|
200 | if(searchstr == NULL) |
---|
201 | search = textinputhist("Search", " ", "searchhist"); |
---|
202 | else |
---|
203 | search = textinputhist("Search", searchstr, "searchhist"); |
---|
204 | |
---|
205 | if(search != NULL) |
---|
206 | { |
---|
207 | drawscreen(load, 0, 0); |
---|
208 | search = stringreplacechar(search, ' ', '+'); |
---|
209 | char* id = NULL; |
---|
210 | char* line = NULL; |
---|
211 | char* pic = NULL; |
---|
212 | char* title = NULL; |
---|
213 | char* menu = NULL; |
---|
214 | char* ip = ostrcat("gdata.youtube.com", NULL, 0, 0); |
---|
215 | char* path = ostrcat("feeds/api/videos?q=", search, 0, 0); |
---|
216 | if(((struct tithek*)listbox->select->handle)->flag == 9) |
---|
217 | path = ostrcat(path, "&max-results=10", 1, 0); |
---|
218 | else if(((struct tithek*)listbox->select->handle)->flag == 10) |
---|
219 | path = ostrcat(path, "&max-results=25", 1, 0); |
---|
220 | else if(((struct tithek*)listbox->select->handle)->flag == 11) |
---|
221 | path = ostrcat(path, "&max-results=50", 1, 0); |
---|
222 | |
---|
223 | char* tmpstr = gethttp(ip, path, 80, NULL, NULL, 10000, NULL, 0); |
---|
224 | tmpstr = string_replace_all("media:thumbnail", "\nthumbnail", tmpstr, 1); |
---|
225 | |
---|
226 | int count = 0; |
---|
227 | int incount = 0; |
---|
228 | int i = 0; |
---|
229 | struct splitstr* ret1 = NULL; |
---|
230 | ret1 = strsplit(tmpstr, "\n", &count); |
---|
231 | |
---|
232 | if(ret1 != NULL) |
---|
233 | { |
---|
234 | int max = count; |
---|
235 | for(i = 0; i < max; i++) |
---|
236 | { |
---|
237 | if(ostrstr(ret1[i].part, "http://i.ytimg.com/vi/") != NULL) |
---|
238 | { |
---|
239 | pic = oregex(".*thumbnail url=\'(http://i.ytimg.com/vi/.*/0.jpg).*", ret1[i].part); |
---|
240 | id = oregex(".*thumbnail url=\'http://i.ytimg.com/vi/(.*)/0.jpg.*", ret1[i].part); |
---|
241 | int rcret = waitrc(NULL, 10, 0); |
---|
242 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
243 | |
---|
244 | if(id != NULL) |
---|
245 | { |
---|
246 | incount += 1; |
---|
247 | ip = ostrcat("www.youtube.com", NULL, 0, 0); |
---|
248 | path = ostrcat("watch?v=", id, 0, 0); |
---|
249 | title = gethttp(ip, path, 80, NULL, NULL, 10000, NULL, 0); |
---|
250 | title = string_resub("<meta name=\"title\" content=\"", "\">", title, 0); |
---|
251 | |
---|
252 | line = ostrcat(line, title, 1, 0); |
---|
253 | // line = ostrcat(line, "#http://www.youtube.com/watch?v=", 1, 0); |
---|
254 | line = ostrcat(line, "#http://www.youtube.com/get_video_info?&video_id=", 1, 0); |
---|
255 | line = ostrcat(line, id, 1, 0); |
---|
256 | line = ostrcat(line, "#", 1, 0); |
---|
257 | line = ostrcat(line, pic, 1, 0); |
---|
258 | line = ostrcat(line, "#youtube_search_", 1, 0); |
---|
259 | line = ostrcat(line, oitoa(incount + time(NULL)), 1, 0); |
---|
260 | line = ostrcat(line, ".jpg#YouTube - Search#4\n", 1, 0); |
---|
261 | free(ip), ip = NULL; |
---|
262 | free(path), path = NULL; |
---|
263 | free(title), title = NULL; |
---|
264 | } |
---|
265 | } |
---|
266 | } |
---|
267 | free(ret1), ret1 = NULL; |
---|
268 | |
---|
269 | if(line != NULL) |
---|
270 | { |
---|
271 | menu = ostrcat("/tmp/tithek/youtube.search.list", NULL, 0, 0); |
---|
272 | writesys(menu, line, 0); |
---|
273 | struct tithek* tnode = (struct tithek*)listbox->select->handle; |
---|
274 | createtithek(tnode, tnode->title, menu, tnode->pic, tnode->localname, tnode->menutitle, tnode->flag); |
---|
275 | ret = 0; |
---|
276 | } |
---|
277 | } |
---|
278 | free(tmpstr), tmpstr = NULL; |
---|
279 | } |
---|
280 | free(search), search = NULL; |
---|
281 | return ret; |
---|
282 | } |
---|
283 | |
---|
284 | #endif |
---|