source: titan/plugins/tithek/amazon.h @ 40119

Last change on this file since 40119 was 36083, checked in by obi, 8 years ago

fix

File size: 42.9 KB
Line 
1#ifndef AMAZON_H
2#define AMAZON_H
3
4// imdb
5//http://api-doc.imdbws.com/static-content/documents/v1/de-DE/video/lovefilm_de/amzn1.dv.vcid.183d4cd2-d2f0-4d5d-8712-771b05cb0feb/events:imdb.api.video.events/data.json?Expires=1442152236&Signature=ay5qtA6EvuUQ253Ch2-MIGLt~GgrFl1gFNxhvgME9nyd5BP9vmX9nnusTJYgnqXlbDxa0XlDkPxm0zEOOlaQaRhTbxT5VOV75KZuOlJXb9PQou75KbT8fbWfhY5LJpKrHeLkqU5xSuV8TQ0L2OK997GL5N7147vf2gs3eya8PyA_&Key-Pair-Id=APKAJHKHQ2OMFVLH6TKA
6
7void amazon_init(char* titheklink, char* tithekfile)
8{
9        int ret = 0;
10        char* tmpstr = NULL;
11       
12        if(ostrcmp("http://atemio.dyndns.tv/mediathek/mainmenu.list", titheklink) == 0)
13                writesys(tithekfile, "Amazon#/tmp/tithek/amazon.mainmenu.list#http://atemio.dyndns.tv/mediathek/menu/amazon.jpg#amazon.jpg#TiThek#0", 3);
14
15        if(ostrcmp("/tmp/tithek/amazon.mainmenu.list", titheklink) == 0)
16        {
17                if(amazonlogin == 0)
18                {
19                        ret = amazon_login();
20                        if(ret == 0)
21                                textbox(_("Message"), _("Amazon login not successful! Please check Amazon Prime User/Pass in Tithek settings and try again."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 1100, 200, 0, 0);
22                        else
23                        {
24                                textbox(_("Message"), _("Amazon Prime login successful!"), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 10, 0);
25                                amazonlogin = 1;
26                        }
27                }
28                unlink(tithekfile);
29                printf("add amazon mainmenu entrys\n");
30
31
32//              writesys(tithekfile, "Currently (Movie)#/tmp/tithek/amazon.currently.movie.list#http://atemio.dyndns.tv/mediathek/menu/currently.movie.jpg#currently.movie.jpg#Amazon#86", 3);
33                tmpstr = ostrcat(_("Currently"), " (", 0, 0);
34                tmpstr = ostrcat(tmpstr, _("Movies"), 0, 0);
35                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.currently.movie.list#http://atemio.dyndns.tv/mediathek/menu/currently.movie.jpg#currently.movie.jpg#Amazon#86", 0, 0);
36                writesys(tithekfile, tmpstr, 3);
37                free(tmpstr), tmpstr = NULL;
38
39//              writesys(tithekfile, "Popularity Kids (Movie)#/tmp/tithek/amazon.popularity.kids.movie.list#http://atemio.dyndns.tv/mediathek/menu/popularity.kids.movie.jpg#popularity.kids.movie.jpg#Amazon#84", 3);
40                tmpstr = ostrcat(_("Popularity Kids"), " (", 0, 0);
41                tmpstr = ostrcat(tmpstr, _("Movies"), 0, 0);
42                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.popularity.kids.movie.list#http://atemio.dyndns.tv/mediathek/menu/popularity.kids.movie.jpg#popularity.kids.movie.jpg#Amazon#84", 0, 0);
43                writesys(tithekfile, tmpstr, 3);
44                free(tmpstr), tmpstr = NULL;
45
46//              writesys(tithekfile, "Popularity Kids (Series)#/tmp/tithek/amazon.popularity.kids.tv.list#http://atemio.dyndns.tv/mediathek/menu/popularity.kids.tv.jpg#popularity.kids.tv.jpg#Amazon#85", 3);
47                tmpstr = ostrcat(_("Popularity Kids"), " (", 0, 0);
48                tmpstr = ostrcat(tmpstr, _("Series"), 0, 0);
49                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.popularity.kids.tv.list#http://atemio.dyndns.tv/mediathek/menu/popularity.kids.tv.jpg#popularity.kids.tv.jpg#Amazon#85", 0, 0);
50                writesys(tithekfile, tmpstr, 3);
51                free(tmpstr), tmpstr = NULL;
52
53//              writesys(tithekfile, "Popularity (Movie)#/tmp/tithek/amazon.popularity.rank.movie.list#http://atemio.dyndns.tv/mediathek/menu/popularity.rank.movie.jpg#popularity.rank.movie.jpg#Amazon#81", 3);
54                tmpstr = ostrcat(_("Popularity Rank"), " (", 0, 0);
55                tmpstr = ostrcat(tmpstr, _("Movies"), 0, 0);
56                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.popularity.rank.movie.list#http://atemio.dyndns.tv/mediathek/menu/popularity.rank.movie.jpg#popularity.rank.movie.jpg#Amazon#81", 0, 0);
57                writesys(tithekfile, tmpstr, 3);
58                free(tmpstr), tmpstr = NULL;
59
60//              writesys(tithekfile, "Popularity (Series)#/tmp/tithek/amazon.popularity.rank.tv.list#http://atemio.dyndns.tv/mediathek/menu/popularity.rank.tv.jpg#popularity.rank.tv.jpg#Amazon#83", 3);
61                tmpstr = ostrcat(_("Popularity Rank"), " (", 0, 0);
62                tmpstr = ostrcat(tmpstr, _("Series"), 0, 0);
63                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.popularity.rank.tv.list#http://atemio.dyndns.tv/mediathek/menu/popularity.rank.tv.jpg#popularity.rank.tv.jpg#Amazon#83", 0, 0);
64                writesys(tithekfile, tmpstr, 3);
65                free(tmpstr), tmpstr = NULL;
66
67//              writesys(tithekfile, "Genre (Movie)#/tmp/tithek/amazon.genre.movie.list#http://atemio.dyndns.tv/mediathek/menu/genre.movie.jpg#watchlist.movie.jpg#Amazon#87", 3);
68                tmpstr = ostrcat(_("Genre"), " (", 0, 0);
69                tmpstr = ostrcat(tmpstr, _("Movies"), 0, 0);
70                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.genre.movie.list#http://atemio.dyndns.tv/mediathek/menu/genre.movie.jpg#watchlist.movie.jpg#Amazon#87", 0, 0);
71                writesys(tithekfile, tmpstr, 3);
72                free(tmpstr), tmpstr = NULL;
73
74//              writesys(tithekfile, "Genre (Series)#/tmp/tithek/amazon.genre.tv.list#http://atemio.dyndns.tv/mediathek/menu/genre.tv.jpg#watchlist.movie.jpg#Amazon#89", 3);
75                tmpstr = ostrcat(_("Genre"), " (", 0, 0);
76                tmpstr = ostrcat(tmpstr, _("Series"), 0, 0);
77                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.genre.tv.list#http://atemio.dyndns.tv/mediathek/menu/genre.tv.jpg#watchlist.movie.jpg#Amazon#89", 0, 0);
78                writesys(tithekfile, tmpstr, 3);
79                free(tmpstr), tmpstr = NULL;
80
81//              writesys(tithekfile, "Watchlist (Movie)#/tmp/tithek/amazon.watchlist.movie.list#http://atemio.dyndns.tv/mediathek/menu/watchlist.movie.jpg#watchlist.movie.jpg#Amazon#79", 3);
82                tmpstr = ostrcat(_("Watchlist"), " (", 0, 0);
83                tmpstr = ostrcat(tmpstr, _("Movies"), 0, 0);
84                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.watchlist.movie.list#http://atemio.dyndns.tv/mediathek/menu/watchlist.movie.jpg#watchlist.movie.jpg#Amazon#79", 0, 0);
85                writesys(tithekfile, tmpstr, 3);
86                free(tmpstr), tmpstr = NULL;
87
88//              writesys(tithekfile, "Watchlist (Series)#/tmp/tithek/amazon.watchlist.tv.list#http://atemio.dyndns.tv/mediathek/menu/watchlist.tv.jpg#watchlist.tv.jpg#Amazon#80", 3);
89                tmpstr = ostrcat(_("Watchlist"), " (", 0, 0);
90                tmpstr = ostrcat(tmpstr, _("Series"), 0, 0);
91                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.watchlist.tv.list#http://atemio.dyndns.tv/mediathek/menu/watchlist.tv.jpg#watchlist.tv.jpg#Amazon#80", 0, 0);
92                writesys(tithekfile, tmpstr, 3);
93                free(tmpstr), tmpstr = NULL;
94
95//              writesys(tithekfile, "Search (Movie)#/tmp/tithek/amazon.search.movie.list#http://atemio.dyndns.tv/mediathek/menu/search.jpg#search.jpg#Amazon#76", 3);
96                tmpstr = ostrcat(_("Search"), " (", 0, 0);
97                tmpstr = ostrcat(tmpstr, _("Movies"), 0, 0);
98                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.search.movie.list#http://atemio.dyndns.tv/mediathek/menu/search.jpg#search.jpg#Amazon#76", 0, 0);
99                writesys(tithekfile, tmpstr, 3);
100                free(tmpstr), tmpstr = NULL;
101
102//              writesys(tithekfile, "Search (Tv)#/tmp/tithek/amazon.search.tv.list#http://atemio.dyndns.tv/mediathek/menu/search.jpg#search.jpg#Amazon#77", 3);
103                tmpstr = ostrcat(_("Search"), " (", 0, 0);
104                tmpstr = ostrcat(tmpstr, _("Series"), 0, 0);
105                tmpstr = ostrcat(tmpstr, ")#/tmp/tithek/amazon.search.tv.list#http://atemio.dyndns.tv/mediathek/menu/search.jpg#search.jpg#Amazon#77", 0, 0);
106                writesys(tithekfile, tmpstr, 3);
107                free(tmpstr), tmpstr = NULL;
108               
109        }
110        free(tmpstr), tmpstr = NULL;
111}
112
113int amazon_search(struct skin* grid, struct skin* listbox, struct skin* countlabel, struct skin* load, char* link, char* title, char* searchstr, int flag)
114{
115        printf("amazon_search start flag: %d\n", flag);
116        int ret = 1, type = 0;
117        int debuglevel = getconfigint("debuglevel", NULL);
118
119        if(listbox == NULL || listbox->select == NULL || listbox->select->handle == NULL)
120                return ret;
121
122        char* remove = NULL, *tmpstr2 = NULL, *tmpstr3 = NULL, *filename = NULL, *tmpstr = NULL, *search = NULL, *line = NULL, *url = NULL, *id = NULL, *streamurl = NULL, *pic = NULL, *year = NULL, *runtime = NULL, *menu = NULL;
123        char* page = NULL, *pages = NULL, *nextpage = NULL, *tmpstr4 = NULL, *atitle = NULL;
124
125        if(flag == 0 || flag == 1)
126        {
127                if(searchstr == NULL)
128                        search = textinputhist(_("Search"), " ", "searchhist");
129                else
130                        search = textinputhist(_("Search"), searchstr, "searchhist");
131        }
132
133        if(search != NULL || flag > 0)
134        {
135                drawscreen(load, 0, 0);
136                search = stringreplacechar(search, ' ', '+');
137                if(flag == 0)
138                {
139                        filename = ostrcat("movie", NULL, 0, 0);
140                        type = 75;
141                        url = ostrcat("http://www.amazon.de/mn/search/ajax/?_encoding=UTF8&url=node%3D3356018031&field-keywords=", search, 0, 0);
142                }
143                else if(flag == 1)
144                {
145                        filename = ostrcat("season", NULL, 0, 0);
146                        type = 78;
147                        url = ostrcat("http://www.amazon.de/mn/search/ajax/?_encoding=UTF8&url=node%3D3356019031&field-keywords=", search, 0, 0);
148                }
149                else if(flag == 2)
150                {
151                        filename = ostrcat("episode", NULL, 0, 0);
152                        type = 75;
153                        url = ostrcat("http://www.amazon.de/dp/", link, 0, 0);
154                        url = ostrcat(url, "/?_encoding=UTF8", 1, 0);           
155                }
156                else if(flag == 3)
157                {
158                        filename = ostrcat("watchlist.movie", NULL, 0, 0);
159                        type = 75;
160                        url = ostrcat("http://www.amazon.de/gp/video/watchlist/movie?ie=UTF8&show=all&sort=DATE_ADDED_DESC", NULL, 0, 0);
161                }
162                else if(flag == 4)
163                {
164                        filename = ostrcat("watchlist.tv", NULL, 0, 0);
165                        type = 78;
166                        url = ostrcat("http://www.amazon.de/gp/video/watchlist/tv?ie=UTF8&show=all&sort=DATE_ADDED_DESC", NULL, 0, 0);
167                }
168                else if(flag == 5)
169                {
170                        filename = ostrcat("popularity.rank.movie", NULL, 0, 0);
171                        type = 75;
172                        url = ostrcat("http://www.amazon.de/gp/search/ajax/?_encoding=UTF8&rh=n%3A3010075031%2Cn%3A3356018031&sort=popularity-rank", NULL, 0, 0);
173                }
174                else if(flag == 6)
175                {
176                        filename = ostrcat("popularity.rank.tv.nextpage", NULL, 0, 0);
177                        type = 75;
178                        url = ostrcat(link, NULL, 0, 0);
179                }
180                else if(flag == 7)
181                {
182                        filename = ostrcat("popularity.rank.tv", NULL, 0, 0);
183                        type = 78;
184                        url = ostrcat("http://www.amazon.de/gp/search/ajax/?_encoding=UTF8&rh=n%3A3010075031%2Cn%3A3356019031&sort=popularity-rank", NULL, 0, 0);
185                }
186                else if(flag == 8)
187                {
188                        filename = ostrcat("popularity.kids.movie", NULL, 0, 0);
189                        type = 75;
190                        url = ostrcat("http://www.amazon.de/gp/search/ajax/?rh=n%3A3010075031%2Cn%3A!3010076031%2Cn%3A3015915031%2Cp_n_theme_browse-bin%3A3015972031%2Cp_85%3A3282148031&ie=UTF8", NULL, 0, 0);
191                }
192                else if(flag == 9)
193                {
194                        filename = ostrcat("popularity.kids.tv", NULL, 0, 0);
195                        type = 78;
196                        url = ostrcat("http://www.amazon.de/gp/search/ajax/?rh=n%3A3010075031%2Cn%3A!3010076031%2Cn%3A3015916031%2Cp_n_theme_browse-bin%3A3015972031%2Cp_85%3A3282148031&ie=UTF8", NULL, 0, 0);
197                }
198                else if(flag == 10)
199                {
200                        filename = ostrcat("currently.movie", NULL, 0, 0);
201                        type = 75;
202                        url = ostrcat("http://www.amazon.de/s/?n=4963842031&_encoding=UTF", NULL, 0, 0);
203                }
204                else if(flag == 11)
205                {
206                        filename = ostrcat("genre.movie", NULL, 0, 0);
207                        type = 88;
208                        url = ostrcat("http://www.amazon.de/gp/search/other/?rh=n%3A3279204031%2Cn%3A!3010076031%2Cn%3A3356018031&pickerToList=theme_browse-bin&ie=UTF8", NULL, 0, 0);
209                }
210                else if(flag == 12)
211                {
212                        filename = ostrcat("genre.movie.listed", NULL, 0, 0);
213                        type = 75;
214                        url = ostrcat(link, NULL, 0, 0);
215                }
216                else if(flag == 13)
217                {
218                        filename = ostrcat("genre.tv", NULL, 0, 0);
219                        type = 90;
220                        url = ostrcat("http://www.amazon.de/gp/search/other/?rh=n%3A3279204031%2Cn%3A!3010076031%2Cn%3A3356019031&pickerToList=theme_browse-bin&ie=UTF8", NULL, 0, 0);
221                }
222                else if(flag == 14)
223                {
224                        filename = ostrcat("genre.tv.listed", NULL, 0, 0);
225                        type = 78;
226                        url = ostrcat(link, NULL, 0, 0);
227                }
228
229///////////////////////////
230                debug(99, "url: %s", url);
231                tmpstr = gethttps(url, NULL, NULL, NULL, NULL, NULL, 1);
232///////////////
233                pages = string_resub("<span class=\\\"pagnDisabled\\\">", "</span>", tmpstr, 0);       
234                nextpage = string_resub("<span class=\\\"pagnLink\\\"><a href=\\\"", "\\\"", tmpstr, 0);       
235
236                if(pages == NULL)
237                        pages = string_resub("<span class=\"pagnDisabled\">", "</span>", tmpstr, 0);
238
239                if(nextpage == NULL)
240                {
241                        tmpstr4 = string_resub("class=\"pagnNext\"", ">", tmpstr, 0);   
242                        nextpage = string_resub("href=\"", "\"", tmpstr4, 0);   
243                        free(tmpstr4), tmpstr4 = NULL;
244                }
245
246                page = oregex(".*/ref=.*([0-9]{2,2})\\?rh=.*", nextpage);
247                if(page == NULL)
248                        page = oregex(".*/ref=.*([0-9]{1,2})\\?rh=.*", nextpage);
249
250                if(pages == NULL)
251                {
252                        tmpstr4 = string_resub("pagnCur", "pagnRA", tmpstr, 0);
253                        pages = oregex(".*ref=sr_pg_([0-9]{1,2})\\?rh=.*", tmpstr4);
254                        free(tmpstr4), tmpstr4 = NULL;
255                }
256
257                nextpage = string_replace_all("&amp;", "&", nextpage, 1);
258//////////////////////
259
260                tmpstr2 = ostrcat("/tmp/amazon_search_tmpstr_get", filename, 0, 0);
261                tmpstr2 = ostrcat(tmpstr2, "_page_", 1, 0);
262                tmpstr2 = ostrcat(tmpstr2, page, 1, 0);
263                tmpstr2 = ostrcat(tmpstr2, "_pages_", 1, 0);
264                tmpstr2 = ostrcat(tmpstr2, pages, 1, 0);
265                unlink(tmpstr2);
266
267                tmpstr3 = ostrcat(tmpstr2, "_replace", 0, 0);
268                unlink(tmpstr3);
269
270///////////////////////////
271                titheklog(debuglevel, tmpstr2, NULL, NULL, NULL, tmpstr);               
272                free(url), url = NULL;
273///////////////////////////
274
275                int count1 = 0;
276                int j = 0;
277
278                if(flag == 10)
279                        tmpstr = stringreplacechar(tmpstr, '\n', ' ');
280//                      tmpstr = string_replace_all("\n", " ", tmpstr, 1);
281
282                if(flag == 0 || flag == 1 || flag == 5 || flag == 7 || flag == 8 || flag == 9 || flag == 12 || flag == 14)
283                        tmpstr = string_replace_all("<li id=\\\"result_", "\n<li id=\\\"result_", tmpstr, 1);
284                else if(flag == 6 || flag == 10)
285                        tmpstr = string_replace_all("<li id=\"result_", "\n<li id=\"result_", tmpstr, 1);
286                else if(flag == 2)
287                {
288                        tmpstr = string_replace_all("\n", " ", tmpstr, 1);                     
289                        tmpstr = string_replace_all("<li class=\"selected-episode", "\n<li class=\"\">", tmpstr, 1);
290                        tmpstr = string_replace_all("<li class=\"\">", "\n<li class=\"\">", tmpstr, 1);
291//                      tmpstr = string_replace_all("<li class=\"last-episode", "\n<li class=\"last-episode", tmpstr, 1);
292                        tmpstr = string_replace_all("<li class=\"last-episode", "\n<li class=\"\">", tmpstr, 1);
293                        tmpstr = string_replace_all("<li class=\"first-episode", "\n<li class=\"\">", tmpstr, 1);
294                        tmpstr = string_replace_all("<li class=\"has-watched", "\n<li class=\"\">", tmpstr, 1);
295                        tmpstr = string_replace_all("</div> </div>", "\n</div> </div>", tmpstr, 1);     
296                }
297                else if(flag == 3 || flag == 4)
298                {
299                        tmpstr = string_replace_all("\n", " ", tmpstr, 1);
300                        tmpstr = string_replace_all("<div class=\"grid-list-item downloadable_", "\n<div class=\"grid-list-item downloadable_", tmpstr, 1);
301                        tmpstr = string_replace_all("<script type=\"text/javascript\">", "\n<script type=\"text/javascript\">", tmpstr, 1);     
302                }
303                else if(flag == 11 || flag == 13)
304                {
305                        tmpstr = string_replace_all("\n", " ", tmpstr, 1);
306                        tmpstr = string_replace_all("<a href=\"/s/ref=sr_in_", "\n<a href=\"/s/ref=sr_in_", tmpstr, 1);
307                        tmpstr = string_replace_all("</div></div>", "\n</div></div>", tmpstr, 1);
308                }
309
310                titheklog(debuglevel, tmpstr3, NULL, NULL, NULL, tmpstr);               
311
312                count1 = 0;
313                j = 0;
314                struct splitstr* ret1 = NULL;
315                ret1 = strsplit(tmpstr, "\n", &count1);
316                int incount = 0;
317
318                if(ret1 != NULL && count1 > 0)
319                {
320                        int max = count1;
321                        for(j = 0; j < max; j++)
322                        {
323                                if(ostrstr(ret1[j].part, "<li id=\\\"result_") != NULL)
324                                {
325                                        debug(99, "(%d) ret1[j].part: %s", j, ret1[j].part);
326                                        streamurl = string_resub("\" href=\\\"", "\\\">", ret1[j].part, 0);
327                                        pic = string_resub("\" src=\\\"", "\\\"", ret1[j].part, 0);
328                                        if(pic == NULL)
329                                                pic = ostrcat(pic, "http://atemio.dyndns.tv/mediathek/menu/default.jpg", 1, 0);
330                                        atitle = string_resub("\" title=\\\"", "\\\"", ret1[j].part, 0);
331                                        year = string_resub("<span class=\\\"a-size-small a-color-secondary\\\">", "</span>", ret1[j].part, 0);
332                                        runtime = oregex(".*a-size-small a-color-secondary.*>(.*)</span>.*", ret1[j].part);
333                                        id = oregex("http.*//.*/.*/(.*)/ref.*", streamurl);
334                                }
335                                if(ostrstr(ret1[j].part, "<li id=\"result_") != NULL)
336                                {
337                                        debug(99, "(%d) ret1[j].part: %s", j, ret1[j].part);
338                                        streamurl = string_resub("\" href=\"", "\">", ret1[j].part, 0);
339                                        pic = string_resub("\" src=\"", "\"", ret1[j].part, 0);
340                                        if(pic == NULL)
341                                                pic = ostrcat(pic, "http://atemio.dyndns.tv/mediathek/menu/default.jpg", 1, 0);
342                                        atitle = string_resub("\" title=\"", "\"", ret1[j].part, 0);
343                                        year = string_resub("<span class=\"a-size-small a-color-secondary\">", "</span>", ret1[j].part, 0);
344                                        runtime = oregex(".*a-size-small a-color-secondary.*>(.*)</span>.*", ret1[j].part);
345                                        id = oregex("http.*//.*/.*/(.*)/ref.*", streamurl);
346                                }
347                                else if(ostrstr(ret1[j].part, "<li class=\"\">") != NULL)
348                                {
349                                        debug(99, "(%d) ret1[j].part: %s", j, ret1[j].part);
350                                        streamurl = string_resub("href=\"", "\"", ret1[j].part, 0);
351                                        pic = string_resub("src=\"", "\"", ret1[j].part, 0);
352                                        if(pic == NULL)
353                                                pic = ostrcat(pic, "http://atemio.dyndns.tv/mediathek/menu/default.jpg", 1, 0);
354                                        atitle = string_resub("<span class=\"episode-title\">", "</span>", ret1[j].part, 0);
355                                        year = string_resub("<span class=\"dv-badge release-date\">", "</span>", ret1[j].part, 0);
356                                        runtime = string_resub("<span class=\"dv-badge runtime\">", "</span>", ret1[j].part, 0);
357                                        id = oregex("http.*//.*/.*/(.*)/ref.*", streamurl);
358                                }
359                                else if(ostrstr(ret1[j].part, "<div class=\"grid-list-item downloadable_") != NULL)
360                                {
361                                        debug(99, "(%d) ret1[j].part: %s", j, ret1[j].part);
362                                        streamurl = string_resub("href=\"", "\"", ret1[j].part, 0);
363                                        pic = string_resub("src=\"", "\"", ret1[j].part, 0);
364                                        if(pic == NULL)
365                                                pic = ostrcat(pic, "http://atemio.dyndns.tv/mediathek/menu/default.jpg", 1, 0);
366                                        atitle = string_resub("data-title=\"", "\"", ret1[j].part, 0);
367                                        year = string_resub("<span class=\"dv-badge release-date\">", "</span>", ret1[j].part, 0);
368                                        runtime = string_resub("<span class=\"dv-badge runtime\">", "</span>", ret1[j].part, 0);
369                                        id = string_resub("id=\"", "\"", ret1[j].part, 0);
370                                        remove = string_resub("data-action=\"remove\" href=\"", "\"", ret1[j].part, 0);                                 
371                                        debug(99, "(%d) remove: %s", j, remove);
372                                }
373                                else if(ostrstr(ret1[j].part, "<span class=\\\"pagnLink\\\">") != NULL)
374                                {
375                                        debug(99, "(%d) ret1[j].part: %s", j, ret1[j].part);
376                                        streamurl = string_resub("\" href=\\\"", "\\\">", ret1[j].part, 0);
377                                        pic = string_resub("\" src=\\\"", "\\\"", ret1[j].part, 0);
378                                        if(pic == NULL)
379                                                pic = ostrcat(pic, "http://atemio.dyndns.tv/mediathek/menu/default.jpg", 1, 0);
380                                        atitle = string_resub("\" title=\\\"", "\\\"", ret1[j].part, 0);
381                                        year = string_resub("<span class=\\\"a-size-small a-color-secondary\\\">", "</span>", ret1[j].part, 0);
382                                        runtime = oregex(".*a-size-small a-color-secondary.*>(.*)</span>.*", ret1[j].part);
383                                        id = oregex("http.*//.*/.*/(.*)/ref.*", streamurl);
384                                }
385                                else if(ostrstr(ret1[j].part, "<a href=\"/s/ref=sr_in_") != NULL)
386                                {
387                                        debug(99, "(%d) ret1[j].part: %s", j, ret1[j].part);
388                                        streamurl = string_resub("<a href=\"", "\">", ret1[j].part, 0);
389                                        streamurl = string_replace_all("/s/", "https://www.amazon.de/mn/search/ajax/", streamurl, 1);
390                                        streamurl = string_replace_all("&amp;", "&", streamurl, 1);
391                                        pic = ostrcat(pic, "http://atemio.dyndns.tv/mediathek/menu/default.jpg", 1, 0);
392                                        atitle = string_resub("<span class=\"refinementLink\">", "</span>", ret1[j].part, 0);
393//                                      id = oregex("http.*//.*/.*/(.*)/ref.*", streamurl);
394                                        id = string_resub("bbn=", "&", streamurl, 0);
395                                }
396
397                                if(ostrstr(ret1[j].part, "result_") != NULL || ostrstr(ret1[j].part, "<li class=\"\">") != NULL || ostrstr(ret1[j].part, "<div class=\"grid-list-item downloadable_") != NULL || ostrstr(ret1[j].part, "<span class=\\\"pagnLink\\\">") != NULL || ostrstr(ret1[j].part, "<a href=\"/s/ref=sr_in_") != NULL)
398                                {
399                                        if(atitle == NULL)
400                                        {
401                                                atitle = string_resub("http://www.amazon.de/", "/", streamurl, 0);
402                                                atitle = string_replace_all("-", " ", atitle, 1);
403                                        }
404                                        if(atitle != NULL)
405                                                atitle = string_decode3(atitle);
406
407                                        if(atitle != NULL)
408                                                htmldecode2(atitle, atitle);
409
410                                        debug(99, "(%d) streamurl: %s", j, streamurl);
411                                        if(flag != 11 && flag != 13)
412                                        {
413                                                free(streamurl), streamurl = NULL;                                     
414                                                streamurl = ostrcat("http://www.amazon.de/dp/", id, 0, 0);
415                                                streamurl = ostrcat(streamurl, "/?_encoding=UTF8", 1, 0);
416                                                debug(99, "(%d) streamurl changed: %s", j, streamurl);
417                                        }
418                                        else
419                                        {
420                                                debug(99, "(%d) streamurl: %s", j, streamurl);
421                                        }                                       
422                                        debug(99, "(%d) id: %s", j, id);
423                                        debug(99, "(%d) pic: %s", j, pic);
424                                        debug(99, "(%d) atitle: %s", j, atitle);
425                                        debug(99, "(%d) year: %s", j, year);
426                                        debug(99, "(%d) runtime: %s", j, runtime);
427                                        debug(99, "----------------------");
428
429                                        if(id != NULL)
430                                        {
431                                                incount += 1;
432                                                line = ostrcat(line, atitle, 1, 0);
433                                                if(year != NULL)
434                                                {
435                                                        line = ostrcat(line, " (", 1, 0);
436                                                        line = ostrcat(line, year, 1, 0);
437                                                        line = ostrcat(line, ") ", 1, 0);
438                                                }
439                                                if(runtime != NULL)
440                                                        line = ostrcat(line, runtime, 1, 0);
441                                                line = ostrcat(line, "#", 1, 0);
442                                                if(flag == 11 || flag == 13)
443                                                        line = ostrcat(line, streamurl, 1, 0);
444                                                else
445                                                        line = ostrcat(line, id, 1, 0);
446                                                line = ostrcat(line, "#", 1, 0);
447                                                line = ostrcat(line, pic, 1, 0);
448                                                line = ostrcat(line, "#amazon_search_", 1, 0);
449                                                line = ostrcat(line, oitoa(incount + time(NULL)), 1, 1);
450                                                line = ostrcat(line, ".jpg#Amazon - Search#", 1, 0);
451                                                line = ostrcat(line, oitoa(type), 1, 1);
452                                                line = ostrcat(line, "\n", 1, 0);
453                                        }
454                                       
455                                        free(id), id = NULL;
456                                        free(streamurl), streamurl = NULL;
457                                        free(pic), pic = NULL;
458                                        free(atitle), atitle = NULL;
459                                        free(year), year = NULL;
460                                        free(runtime), runtime = NULL;
461                                        free(remove), remove = NULL;
462                                }
463                        }
464                }
465                free(ret1), ret1 = NULL;
466                free(tmpstr), tmpstr = NULL;
467
468                if(line != NULL)
469                {
470                        if(nextpage != NULL)
471                        {
472                                type = 82;
473                                url = ostrcat("http://www.amazon.de", nextpage, 0, 0);
474                                incount += 1;
475                                line = ostrcat(line, _("Next Page"), 1, 0);
476                                line = ostrcat(line, " (", 1, 0);
477                                line = ostrcat(line, page, 1, 0);
478                                line = ostrcat(line, "/", 1, 0);
479                                line = ostrcat(line, pages, 1, 0);
480                                line = ostrcat(line, ")#", 1, 0);
481                                line = ostrcat(line, url, 1, 0);
482                                line = ostrcat(line, "#", 1, 0);
483                                line = ostrcat(line, "http://atemio.dyndns.tv/mediathek/menu/next.jpg", 1, 0);
484                                line = ostrcat(line, "#amazon_search_", 1, 0);
485                                line = ostrcat(line, oitoa(incount + time(NULL)), 1, 1);
486                                line = ostrcat(line, ".jpg#Amazon - Search#", 1, 0);
487                                line = ostrcat(line, oitoa(type), 1, 1);
488                                line = ostrcat(line, "\n", 1, 0);
489                        }
490                        debug(99, "line: %s", line);
491                        menu = ostrcat("/tmp/tithek/amazon.", NULL, 0, 0);
492                        menu = ostrcat(menu, filename, 1, 0);
493                        menu = ostrcat(menu, ".page.", 1, 0);
494                        menu = ostrcat(menu, page, 1, 0);
495                        menu = ostrcat(menu, ".pages.", 1, 0);
496                        menu = ostrcat(menu, pages, 1, 0);
497                        menu = ostrcat(menu, ".nextpage.list", 1, 0);
498                        writesys(menu, line, 0);
499                        struct tithek* tnode = (struct tithek*)listbox->select->handle;
500                        createtithek(tnode, tnode->title, menu, tnode->pic, tnode->localname, tnode->menutitle, tnode->flag);
501                        ret = 0;
502                }
503
504/*
505                int i = 0, len = 0, treffer = 0, amazontoken = 1000;
506                jsmn_parser parser;
507        //      jsmntok_t tokens[FACEMAXTOKEN]; //TODO
508                jsmntok_t tokens[amazontoken]; //TODO
509                char* buf = NULL;
510
511                if(buf == NULL)
512                {
513                        err("no mem");
514                        free(curlretbuf); curlretbuf = NULL;
515                        curlretbufsize = 0;
516                        return 1;
517                }
518       
519                jsmn_init(&parser);
520       
521        //      ret = jsmn_parse(&parser, curlretbuf, tokens, FACEMAXTOKEN);
522                int ret1 = jsmn_parse(&parser, curlretbuf, tokens, amazontoken);
523                if(ret1 == JSMN_SUCCESS)
524                {
525                        for(i = 0; i < amazontoken; i++)
526                        {
527                                if(tokens[i].start == -1) break;
528       
529                                len = tokens[i].end - tokens[i].start;
530                                if(len > MINMALLOC) len = MINMALLOC;
531                                char* ptr = curlretbuf + tokens[i].start;
532       
533                                printf("tokens[i].type=%d ptr=%s buf=%s\n", tokens[i].type, ptr, buf);
534                        }
535                }
536*/
537///////
538        }
539
540        printf("amazon_search before free url\n");
541        free(url), url = NULL;
542        printf("amazon_search before free page\n");
543        free(page), page = NULL;
544        printf("amazon_search before free pages\n");
545        free(pages), pages = NULL;
546        printf("amazon_search before free nextpage\n");
547        free(nextpage), nextpage = NULL;
548        printf("amazon_search before free filename\n");
549        free(filename), filename = NULL;
550        printf("amazon_search before free runtime\n");
551        free(runtime), runtime = NULL;
552        printf("amazon_search before free year\n");
553        free(year), year = NULL;
554        printf("amazon_search before free atitle\n");
555        free(atitle), atitle = NULL;
556        printf("amazon_search before free pic\n");
557        free(pic), pic = NULL;
558        printf("amazon_search before free streamurl\n");
559        free(streamurl), streamurl = NULL;
560        printf("amazon_search before free id\n");
561        free(id), id = NULL;
562        printf("amazon_search before free tmpstr\n");
563        free(tmpstr), tmpstr = NULL;
564        printf("amazon_search before free tmpstr2\n");
565        free(tmpstr2), tmpstr2 = NULL;
566        printf("amazon_search before free tmpstr3\n");
567        free(tmpstr3), tmpstr3 = NULL;
568        printf("amazon_search before free line\n");
569        free(line), line = NULL;
570        printf("amazon_search before free search\n");
571        free(search), search = NULL;
572        printf("amazon_search before free menu\n");
573        free(menu), menu = NULL;
574
575        printf("amazon_search end flag: %d\n", flag);
576
577        return ret;
578}
579
580void amazon_deinit()
581{
582        printf("amazon_deinit start\n");
583
584        int debuglevel = getconfigint("debuglevel", NULL);
585        char* tmpstr = NULL;
586
587        unlink("/tmp/amazon_tmpstr_get0_logout");
588
589        tmpstr = gethttps("https://www.amazon.de/ap/signin?_encoding=UTF8&openid.assoc_handle=deflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.de%2Fgp%2Fyourstore%2Fhome%3Fie%3DUTF8%26action%3Dsign-out%26path%3D%252Fgp%252Fyourstore%252Fhome%26ref_%3Dnav__gno_signout%26signIn%3D1%26useRedirectOnSuccess%3D1", NULL, NULL, NULL, NULL, NULL, 1);
590        titheklog(debuglevel, "/tmp/amazon_tmpstr_get0_logout", NULL, NULL, NULL, tmpstr);     
591        free(tmpstr), tmpstr = NULL;
592        printf("amazon_deinit end\n");
593}
594
595char* amazon(char* link)
596{
597        printf("amazon start link: %s\n", link);
598
599        int debuglevel = getconfigint("debuglevel", NULL);
600        char* url = NULL, *customerid = NULL, *marketplaceid = NULL, *matchtoken = NULL, *devicetypeid = NULL, *apimain = NULL, *token = NULL;
601        char* tmpstr = NULL, *title = NULL, *pic = NULL, *streamurl = NULL, *bitrate = NULL, *random = NULL, *lang = NULL, *langtext = NULL, *tmpstr2 = NULL;
602       
603        unlink("/tmp/amazon_streamurl_get1");
604        unlink("/tmp/amazon_streamurl_get2");
605        unlink("/tmp/amazon_streamurl_get3");
606        unlink("/tmp/amazon_streamurl_get4");
607
608        url = ostrcat("http://www.amazon.de/gp/video/detail/", link, 0, 0);
609        url = ostrcat(url, "?ie=UTF8&*Version*=1&*entries*=0", 1, 0);
610
611        url = ostrcat("http://www.amazon.de/dp/", link, 0, 0);
612        url = ostrcat(url, "/?_encoding=UTF8", 1, 0);
613
614//////////////////////////////////////////////////
615        tmpstr = gethttps(url, NULL, NULL, NULL, NULL, NULL, 1);
616        titheklog(debuglevel, "/var/usr/local/share/titan/plugins/tithek/amazon_streamurl_get1", NULL, NULL, NULL, tmpstr);     
617        free(url), url = NULL;
618//////////////////////////////////////////////////     
619
620        tmpstr2 = string_resub("class=\"dv-toggle-box dv-tb-closed\">", "<span id=\"dv-mta-submit-announce\"", tmpstr, 0);
621        tmpstr2 = string_replace_all("\n", " ", tmpstr2, 1);
622        tmpstr2 = string_replace_all("<option value=\"", "\n<option value=\"", tmpstr2, 1);
623
624        int count = 0, i = 0;   
625        struct splitstr* ret1 = NULL;
626        struct menulist* mlist = NULL, *mbox = NULL;
627        ret1 = strsplit(tmpstr2, "\n", &count);
628        for(i = 0; i < count; i++)
629        {
630                printf("%d round %s\n", i, ret1[i].part);
631
632                if(ostrstr(ret1[i].part, "<option value=\"") != NULL)
633                {
634                        lang = oregex(".*<option value=\"(.*)\".*>", ret1[i].part);
635                        langtext = oregex(".*>(.*)</option>", ret1[i].part);
636                        strstrip(lang);
637                        strstrip(langtext);
638                        lang = stringreplacecharonce(lang, '\"', '\0');
639                        pic = ostrcat(lang, NULL, 0, 0);
640                        pic = stringreplacecharonce(pic, '_', '\0');
641                        if(pic != NULL)
642                                pic[2] = '\0'; // strip string from deu > de or eng > en
643                        pic = ostrcat(pic, ".png", 1, 0);
644
645                        if(ostrstr(lang, "_") != NULL && langtext != NULL)
646                        {
647                                debug(99, "(%d) langtext: %s lang: %s\n", i, langtext, lang);                                                                                                                                                                                                   
648                                addmenulist(&mlist, langtext, lang, pic, 0, 0);
649                        }
650                        free(lang), lang = NULL;
651                        free(langtext), langtext = NULL;
652                        free(pic), pic = NULL;
653                }
654        }
655        free(ret1), ret1 = NULL;
656        free(tmpstr2), tmpstr2 = NULL;
657
658        if(mlist != NULL)
659        {
660                mbox = menulistbox(mlist, NULL, _("Select Language"), _("Choose your Language from the following list"), NULL, NULL, 1, 0);
661                if(mbox != NULL)
662                {
663
664                        debug(99, "mbox->name %s", mbox->name);
665                        debug(99, "mbox->text %s", mbox->text);
666                        lang = ostrcat(mbox->text, NULL, 0, 0);
667                }
668        }
669        freemenulist(mlist, 0); mlist = NULL;
670
671//////////////////////////////////////////////////
672
673        customerid = string_resub("\"customerID\":\"", "\"", tmpstr, 0);
674        marketplaceid = string_resub("\"marketplaceID\":\"", "\"", tmpstr, 0);
675        matchtoken = string_resub("\"csrfToken\":\"", "\"", tmpstr, 0);
676        devicetypeid = ostrcat("A35LWR0L7KC0TJ", NULL, 0, 0);
677        free(tmpstr), tmpstr = NULL;
678
679//      apiMain = ["atv-ps", "atv-ps-eu", "atv-ps-eu"][int(siteVersion)]
680        apimain = ostrcat("atv-ps-eu", NULL, 0, 0);
681
682        url = ostrcat("https://", apimain, 0, 0);
683        url = ostrcat(url, ".amazon.com/cdp/catalog/GetASINDetails?version=2&format=json&asinlist=", 1, 0);
684        url = ostrcat(url, link, 1, 0);
685        url = ostrcat(url, "&deviceID=", 1, 0);
686        url = ostrcat(url, customerid, 1, 0);
687        url = ostrcat(url, "&includeRestrictions=true&deviceTypeID=", 1, 0);
688        url = ostrcat(url, devicetypeid, 1, 0);
689        url = ostrcat(url, "&firmware=WIN%2017,0,0,188%20PlugIn&NumberOfResults=1", 1, 0);
690
691        printf("customerid: %s\n", customerid);
692        printf("marketplaceid: %s\n", marketplaceid);
693        printf("matchtoken: %s\n", matchtoken);
694        printf("devicetypeid: %s\n", devicetypeid);
695        printf("apimain: %s\n", apimain);
696        printf("lang: %s\n", lang);
697
698//////////////////////////////////////////////////     
699        tmpstr = gethttps(url, NULL, NULL, NULL, NULL, NULL, 1);
700        titheklog(debuglevel, "/var/usr/local/share/titan/plugins/tithek/amazon_streamurl_get2", NULL, NULL, NULL, tmpstr);     
701        free(url), url = NULL;
702//////////////////////////////////////////////////     
703
704        random = randomstring(18);
705        url = ostrcat("https://www.amazon.de/gp/video/streaming/player-token.json?callback=jQuery1640", random, 0, 0);
706        url = ostrcat(url, "_", 1, 0);
707        url = ostrcat(url, olutoa(time(NULL)*1000), 1, 1);
708        url = ostrcat(url, "&csrftoken=", 1, 0);
709        url = ostrcat(url, matchtoken, 1, 0);
710        url = ostrcat(url, "_", 1, 0);
711        url = ostrcat(url, olutoa(time(NULL)*1000), 1, 1);
712
713        free(tmpstr), tmpstr = NULL;
714
715//////////////////////////////////////////////////     
716        tmpstr = gethttps(url, NULL, NULL, NULL, NULL, NULL, 1);
717        titheklog(debuglevel, "/var/usr/local/share/titan/plugins/tithek/amazon_streamurl_get3", NULL, NULL, NULL, tmpstr);     
718        free(url), url = NULL;
719//////////////////////////////////////////////////     
720
721        token = string_resub("\"token\":\"", "\"", tmpstr, 0);
722        free(tmpstr), tmpstr = NULL;
723
724        debug(99, "token: %s", token);
725
726        url = ostrcat("https://", apimain, 0, 0);
727        if(amazonlogin == 1)
728                url = ostrcat(url, ".amazon.com/cdp/catalog/GetStreamingUrlSets?version=1&format=json&firmware=WIN%2011,7,700,224%20PlugIn", 1, 0);
729        else // trailer
730                url = ostrcat(url, ".amazon.com/cdp/catalog/GetStreamingTrailerUrls?version=1&format=json&firmware=WIN%2011,7,700,224%20PlugIn", 1, 0);
731        if(lang != NULL)
732        {
733                url = ostrcat(url, "&audioTrackId=", 1, 0);
734                url = ostrcat(url, lang, 1, 0);
735        }
736        url = ostrcat(url, "&marketplaceID=", 1, 0);
737        url = ostrcat(url, marketplaceid, 1, 0);
738        url = ostrcat(url, "&token=", 1, 0);
739        url = ostrcat(url, token, 1, 0);
740        url = ostrcat(url, "&deviceTypeID=", 1, 0);
741        url = ostrcat(url, devicetypeid, 1, 0);
742        url = ostrcat(url, "&asin=", 1, 0);
743        url = ostrcat(url, link, 1, 0);
744        url = ostrcat(url, "&customerID=", 1, 0);
745        url = ostrcat(url, customerid, 1, 0);
746        url = ostrcat(url, "&deviceID=", 1, 0);
747        url = ostrcat(url, customerid, 1, 0);
748        url = ostrcat(url, olutoa(time(NULL)*1000), 1, 1);
749        url = ostrcat(url, link, 1, 0);
750
751//////////////////////////////////////////////////     
752        tmpstr = gethttps(url, NULL, NULL, NULL, NULL, NULL, 1);
753        titheklog(debuglevel, "/tmp/amazon_streamurl_get4", NULL, NULL, NULL, tmpstr); 
754        free(url), url = NULL;
755//////////////////////////////////////////////////     
756
757        if(tmpstr == NULL || ostrstr(tmpstr, "\"statusCode\":\"ERROR\"") != NULL)
758        {
759                tmpstr = string_resub("\"message\":\"", "\"", tmpstr, 0);
760                textbox(_("Message"), tmpstr , _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1200, 200, 0, 0);
761                goto end;
762        }
763
764        tmpstr = string_replace_all("{\"bitrate\":", "\n{\"bitrate\":", tmpstr, 1);
765
766        count = 0;
767        i = 0;
768        ret1 = strsplit(tmpstr, "\n", &count);
769        for(i = 0; i < count; i++)
770        {
771                free(streamurl), streamurl = NULL;
772
773                if(ostrstr(ret1[i].part, "f4m") != NULL)
774                        pic = ostrcat("f4m.png", NULL, 0, 0);
775                else if(ostrstr(ret1[i].part, "mp4") != NULL)
776                        pic = ostrcat("mp4.png", NULL, 0, 0);
777                else if(ostrstr(ret1[i].part, "3gp") != NULL)
778                        pic = ostrcat("3gp.png", NULL, 0, 0);
779                else if(ostrstr(ret1[i].part, "flv") != NULL)
780                        pic = ostrcat("flv.png", NULL, 0, 0);
781                bitrate = string_resub("\"bitrate\":", ",", ret1[i].part, 0);
782                streamurl = string_resub("\"url\":\"", "\"", ret1[i].part, 0);
783                streamurl = string_replace("rtmpe://azeufms-vodfs.fplive.net/azeufms-vod/mp4:", "http://azeufms-vodfs.fplive.net/", streamurl, 1);
784
785                if(ostrstr(streamurl, "http://") != NULL)
786                {
787                        title = ostrcat("Http Stream (Bitrate ", NULL, 0, 0);
788                        title = ostrcat(title, bitrate, 1, 0);
789                        title = ostrcat(title, ")", 1, 0);
790                        debug(99, "(%d) title: %s streamurl: %s\n", i, title, streamurl);                                                                                                                                                                                                       
791                        addmenulist(&mlist, title, streamurl, pic, 0, 0);
792                }
793                free(bitrate), bitrate = NULL;
794                free(title), title = NULL;
795                free(pic), pic = NULL;
796        }
797        free(ret1), ret1 = NULL;
798
799        if(mlist != NULL)
800        {
801                mbox = menulistbox(mlist, NULL, _("Stream Menu"), _("Choose your Streaming Format from the following list"), NULL, NULL, 1, 0);
802                if(mbox != NULL)
803                {
804                        free(streamurl), streamurl = NULL;
805                        debug(99, "mbox->name %s", mbox->name);
806                        debug(99, "mbox->text %s", mbox->text);
807                        streamurl = ostrcat(mbox->text, NULL, 0, 0);
808                }
809        }
810        freemenulist(mlist, 0); mlist = NULL;
811end:
812        printf("amazon before free lang\n");
813        free(lang), lang = NULL;
814        printf("amazon before free random\n");
815        free(random), random = NULL;
816        printf("amazon before free url\n");
817        free(url), url = NULL;
818        printf("amazon before free customerid\n");
819        free(customerid), customerid = NULL;
820        printf("amazon before free marketplaceid\n");
821        free(marketplaceid), marketplaceid = NULL;
822        printf("amazon before free matchtoken\n");
823        free(matchtoken), matchtoken = NULL;
824        printf("amazon before free devicetypeid\n");
825        free(devicetypeid), devicetypeid = NULL;
826        printf("amazon before free apimain\n");
827        free(apimain), apimain = NULL;
828        printf("amazon before free token\n");
829        free(token), token = NULL;
830        printf("amazon before free tmpstr\n");
831        free(tmpstr), tmpstr = NULL;
832        printf("amazon before free title\n");
833        free(title), title = NULL;
834        printf("amazon before free pic\n");
835        free(pic), pic = NULL;
836        printf("amazon before free bitrate\n");
837        free(bitrate), bitrate = NULL;
838
839        debug(99, "streamurl: %s", streamurl);
840        printf("amazon end link: %s\n", link);
841
842        return streamurl;
843}
844
845int amazon_search_local(struct skin* grid, struct skin* listbox, struct skin* countlabel, struct skin* load, char* link, char* title, char* searchstr, int flag)
846{
847        char* tmpstr = NULL, *tmpstr1 = NULL, *line = NULL, *menu = NULL, *search = NULL;
848        int ret = 1, count = 0, i = 0;
849
850        if(listbox == NULL || listbox->select == NULL || listbox->select->handle == NULL)
851                return ret;
852
853        if(searchstr == NULL)
854                search = textinputhist(_("Search"), " ", "searchhist");
855        else
856                search = textinputhist(_("Search"), searchstr, "searchhist");
857
858        if(search != NULL)
859        {
860                drawscreen(load, 0, 0);
861
862                strstrip(search);
863                string_tolower(search);
864
865                tmpstr = gethttp("atemio.dyndns.tv", "/mediathek/amazon/streams/amazon.all-sorted.list", 80, NULL, HTTPAUTH, 5000, NULL, 0);
866
867                struct splitstr* ret1 = NULL;
868                ret1 = strsplit(tmpstr, "\n", &count);
869
870                if(ret1 != NULL)
871                {
872                        int max = count;
873                        for(i = 0; i < max; i++)
874                        {
875                       
876                                tmpstr1 = ostrcat(ret1[i].part, NULL, 0, 0);
877                                tmpstr1 = stringreplacecharonce(tmpstr1, '#', '\0');
878                                string_tolower(tmpstr1);
879
880                                if(ostrstr(tmpstr1, search) != NULL)
881                                {
882                                        printf("found: %s\n", ret1[i].part);
883                                        int rcret = waitrc(NULL, 10, 0);
884                                        if(rcret == getrcconfigint("rcexit", NULL)) break;
885
886                                        line = ostrcat(line, ret1[i].part, 1, 0);
887                                        line = ostrcat(line, "\n", 0, 0);
888                                }
889                                free(tmpstr1), tmpstr1 = NULL;                         
890                        }
891                        free(ret1), ret1 = NULL;
892
893                        if(line != NULL)
894                        {
895                                line = string_replace_all("http://atemio.dyndns.tv/", "http://imageshack.us/md/up/grd/", line, 1);
896                                menu = ostrcat("/tmp/tithek/amazon.search.list", NULL, 0, 0);
897                                writesys(menu, line, 0);
898                                struct tithek* tnode = (struct tithek*)listbox->select->handle;
899                                createtithek(tnode, tnode->title, menu, tnode->pic, tnode->localname, tnode->menutitle, tnode->flag);
900                                ret = 0;
901                        }
902                }
903                free(tmpstr), tmpstr = NULL;
904        }
905        free(search), search = NULL;
906
907        return ret;
908}
909
910int amazon_login()
911{
912        printf("amazon_login start\n");
913
914        int ret = 0;
915        int debuglevel = getconfigint("debuglevel", NULL);
916
917        char* hash = NULL, *tmpstr = NULL, *login = NULL;
918
919        char* user = getconfig("amazon_user", NULL);
920        char* pass = getconfig("amazon_pass", NULL);
921
922        unlink("/tmp/amazon_tmpstr_get1_blank");
923        unlink("/tmp/amazon_tmpstr_get2_sign-in");
924        unlink("/tmp/amazon_tmpstr_post1");
925        unlink("/tmp/amazon_tmpstr_get3_blank");
926        unlink("/tmp/amazon_tmpstr_get4_blank");
927
928        tmpstr = gethttps("https://www.amazon.de/", NULL, NULL, NULL, NULL, NULL, 1);
929//      debug(99, "tmpstr: %s", tmpstr);
930        titheklog(debuglevel, "/tmp/amazon_tmpstr_get1_blank", NULL, NULL, NULL, tmpstr);       
931
932        login = string_resub("'config.signOutText',", ");", tmpstr, 0);
933        free(tmpstr), tmpstr = NULL;
934        debug(99, "login: %s", login);
935        strstrip(login);
936        debug(99, "login: %s", login);
937
938        if(login == NULL || ostrcmp("null", login) == 0)
939        {
940                debug(99, "Amazon Login Error");
941                ret = 0;
942        }
943        else
944        {
945                debug(99, "Amazon Login Successful: %s", login);
946                ret = 1;
947        }
948        free(login), login = NULL;
949
950        if(ret == 0)
951        {
952                tmpstr = gethttps("https://www.amazon.de/gp/sign-in.html", NULL, NULL, NULL, NULL, NULL, 1);
953                titheklog(debuglevel, "/tmp/amazon_tmpstr_get2_sign-in", NULL, NULL, NULL, tmpstr);     
954
955                char* pos1 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"appActionToken\" value=");
956                char* tmp1 = getxmlentry(pos1, "value=");
957                debug(99, "appActionToken: %s", tmp1);
958       
959                char* pos2 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"appAction\" value=");
960                char* tmp2 = getxmlentry(pos2, "value=");
961                debug(99, "appActionToken: %s", tmp2);
962       
963                char* pos3 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"openid.pape.max_auth_age\" value=");
964                char* tmp3 = getxmlentry(pos3, "value=");
965                debug(99, "openid.pape.max_auth_age: %s", tmp3);
966       
967                char* pos4 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"openid.return_to\" value=");
968                char* tmp4 = getxmlentry(pos4, "value=");
969                debug(99, "openid.return_to: %s", tmp4);
970       
971                char* pos5 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"prevRID\" value=");
972                char* tmp5 = getxmlentry(pos5, "value=");
973                debug(99, "prevRID: %s", tmp5);
974       
975                char* pos6 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"openid.identity\" value=");
976                char* tmp6 = getxmlentry(pos6, "value=");
977                debug(99, "openid.identity: %s", tmp6);
978       
979                char* pos7 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"openid.assoc_handle\" value=");
980                char* tmp7 = getxmlentry(pos7, "value=");
981                debug(99, "openid.assoc_handle: %s", tmp7);
982       
983                char* pos8 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"openid.mode\" value=");
984                char* tmp8 = getxmlentry(pos8, "value=");
985                debug(99, "openid.mode: %s", tmp8);
986       
987                char* pos9 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"openid.ns.pape\" value=");
988                char* tmp9 = getxmlentry(pos9, "value=");
989                debug(99, "openid.ns.pape: %s", tmp9);
990       
991                char* pos10 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"openid.claimed_id\" value=");
992                char* tmp10 = getxmlentry(pos10, "value=");
993                debug(99, "openid.claimed_id: %s", tmp10);
994       
995                char* pos11 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"pageId\" value=");
996                char* tmp11 = getxmlentry(pos11, "value=");
997                debug(99, "pageId: %s", tmp11);
998       
999                char* pos12 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"openid.ns\" value=");
1000                char* tmp12 = getxmlentry(pos12, "value=");
1001                debug(99, "openid.ns: %s", tmp12);
1002                free(tmpstr), tmpstr = NULL;
1003
1004                hash = ostrcat(hash, "appActionToken=", 1, 0);
1005                hash = ostrcat(hash, tmp1, 1, 0);
1006                hash = ostrcat(hash, "&appAction=", 1, 0);
1007                hash = ostrcat(hash, tmp2, 1, 0);
1008                hash = ostrcat(hash, "&openid.pape.max_auth_age=", 1, 0);
1009                hash = ostrcat(hash, tmp3, 1, 0);
1010                hash = ostrcat(hash, "&openid.return_to=", 1, 0);
1011                hash = ostrcat(hash, tmp4, 1, 0);
1012                hash = ostrcat(hash, "&prevRID=", 1, 0);
1013                hash = ostrcat(hash, tmp5, 1, 0);
1014                hash = ostrcat(hash, "&openid.identity=", 1, 0);
1015                hash = ostrcat(hash, tmp6, 1, 0);
1016                hash = ostrcat(hash, "&openid.assoc_handle=", 1, 0);
1017                hash = ostrcat(hash, tmp7, 1, 0);
1018                hash = ostrcat(hash, "&openid.mode=", 1, 0);
1019                hash = ostrcat(hash, tmp8, 1, 0);
1020                hash = ostrcat(hash, "&openid.ns.pape=", 1, 0);
1021                hash = ostrcat(hash, tmp9, 1, 0);
1022                hash = ostrcat(hash, "&openid.claimed_id=", 1, 0);
1023                hash = ostrcat(hash, tmp10, 1, 0);
1024                hash = ostrcat(hash, "&pageId=", 1, 0);
1025                hash = ostrcat(hash, tmp11, 1, 0);
1026                hash = ostrcat(hash, "&openid.ns=", 1, 0);
1027                hash = ostrcat(hash, tmp12, 1, 0);
1028                hash = ostrcat(hash, "&email=", 1, 0);
1029                hash = ostrcat(hash, user, 1, 0);
1030                hash = ostrcat(hash, "&create=0", 1, 0);
1031                hash = ostrcat(hash, "&password=", 1, 0);
1032                hash = ostrcat(hash, pass, 1, 0);
1033       
1034                tmpstr = gethttps("https://www.amazon.de/ap/signin", NULL, hash, NULL, NULL, NULL, 1);
1035//              debug(99, "ret=%s", tmpstr);
1036                titheklog(debuglevel, "/tmp/amazon_tmpstr_post1", NULL, NULL, NULL, tmpstr);   
1037                free(tmpstr), tmpstr = NULL;
1038
1039                tmpstr = gethttps("https://www.amazon.de/", NULL, NULL, NULL, NULL, NULL, 1);
1040//              debug(99, "tmpstr: %s", tmpstr);
1041                titheklog(debuglevel, "/tmp/amazon_tmpstr_get3_blank", NULL, NULL, NULL, tmpstr);       
1042                free(tmpstr), tmpstr = NULL;
1043
1044                tmpstr = gethttps("https://www.amazon.de/", NULL, NULL, NULL, NULL, NULL, 1);
1045//              debug(99, "tmpstr: %s", curlretbuf);
1046                titheklog(debuglevel, "/tmp/amazon_tmpstr_get4_blank", NULL, NULL, NULL, tmpstr);       
1047                free(tmpstr), tmpstr = NULL;
1048       
1049                login = string_resub("'config.signOutText',", ");", tmpstr, 0);
1050                debug(99, "login: %s", login);
1051                strstrip(login);
1052                debug(99, "login: %s", login);
1053                free(tmpstr), tmpstr = NULL;
1054       
1055                if(login == NULL || ostrcmp("null", login) == 0)
1056                {
1057                        debug(99, "Amazon Login Error");
1058                        ret = 0;
1059                }
1060                else
1061                {
1062                        debug(99, "Amazon Login Successful: %s", login);
1063                        ret = 1;
1064                }
1065
1066                printf("amazon_login before free tmp1\n");
1067                free(tmp1), tmp1 = NULL;
1068                printf("amazon_login before free tmp2\n");
1069                free(tmp2), tmp2 = NULL;
1070                printf("amazon_login before free tmp3\n");
1071                free(tmp3), tmp3 = NULL;
1072                printf("amazon_login before free tmp4\n");
1073                free(tmp4), tmp4 = NULL;
1074                printf("amazon_login before free tmp5\n");
1075                free(tmp5), tmp5 = NULL;
1076                printf("amazon_login before free tmp6\n");
1077                free(tmp6), tmp6 = NULL;
1078                printf("amazon_login before free tmp7\n");
1079                free(tmp7), tmp7 = NULL;
1080                printf("amazon_login before free tmp8\n");
1081                free(tmp8), tmp8 = NULL;
1082                printf("amazon_login before free tmp9\n");
1083                free(tmp9), tmp9 = NULL;
1084                printf("amazon_login before free tmp10\n");
1085                free(tmp10), tmp10 = NULL;
1086                printf("amazon_login before free tmp11\n");
1087                free(tmp11), tmp11 = NULL;
1088                printf("amazon_login before free tmp12\n");
1089                free(tmp12), tmp12 = NULL;
1090        }
1091
1092        printf("amazon_login end\n");
1093
1094        return ret;
1095}
1096
1097#endif
Note: See TracBrowser for help on using the repository browser.