Changeset 15276


Ignore:
Timestamp:
04/15/12 21:27:58 (12 years ago)
Author:
nit
Message:

[titan] update imdb

Location:
titan/plugins/imdb
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • titan/plugins/imdb/imdb.c

    r13646 r15276  
    4747void start(void)
    4848{
    49         imdb();
     49        screenimdb(NULL);
    5050}
  • titan/plugins/imdb/imdb.h

    r14748 r15276  
    22#define IMDB_H
    33
    4 extern struct skin* skin;
     4#define TMPIMDBPIC "/tmp/tmpimdb.jpg"
    55
    6 char* screensearch(char* input)
     6struct imdb
    77{
    8         char* lastline = NULL;
    9         char* tmpstr = NULL;
    10         if(input != NULL)
    11                 lastline = textinput(_("Imdb Suche"), input);
    12         else
    13                 lastline = textinput(_("Imdb Suche"), "");
     8        char* title;
     9        char* year;
     10        char* rated;
     11        char* released;
     12        char* genre;
     13        char* director;
     14        char* writer;
     15        char* actors;
     16        char* plot;
     17        char* poster;
     18        char* runtime;
     19        char* rating;
     20        char* votes;
     21        char* id;
     22};
    1423
    15         return lastline;
     24void freeimdb(struct imdb* node)
     25{
     26        if(node == NULL) return;
     27
     28        free(node->title); node->title = NULL;
     29        free(node->year); node->year = NULL;
     30        free(node->rated); node->rated = NULL;
     31        free(node->released); node->released = NULL;
     32        free(node->genre); node->genre = NULL;
     33        free(node->director); node->director = NULL;
     34        free(node->writer); node->writer = NULL;
     35        free(node->actors); node->actors = NULL;
     36        free(node->plot); node->plot = NULL;
     37        free(node->poster); node->poster = NULL;
     38        free(node->runtime); node->runtime = NULL;
     39        free(node->rating); node->rating = NULL;
     40        free(node->votes); node->votes = NULL;
     41        free(node->id); node->id = NULL;
     42        unlink(TMPIMDBPIC);
     43
     44        free(node); node = NULL;
    1645}
    1746
    18 void imdb()
     47struct imdb* getimdb(char* title)
     48{
     49        struct imdb* imdb = NULL;
     50        char* tmpstr = NULL;
     51        char* tmpsearch = NULL;
     52
     53        tmpsearch = ostrcat("?i=&t=", title, 0, 0);
     54        tmpsearch = stringreplacechar(tmpsearch, ' ', '+');
     55
     56        tmpstr = gethttp("www.imdbapi.com", tmpsearch, 80, NULL, NULL, NULL, 0);
     57        free(tmpsearch); tmpsearch = NULL;
     58
     59        if(tmpstr != NULL)
     60        {
     61                imdb = (struct imdb*)malloc(sizeof(struct imdb));
     62                if(imdb == NULL)
     63                {
     64                        err("no mem");
     65                        free(tmpstr); tmpstr = NULL;
     66                        return NULL;
     67                }
     68                memset(imdb, 0, sizeof(struct imdb));
     69
     70                imdb->title = ostrcat(getxmlentry(tmpstr, "\"Title\":"), NULL, 0, 0);
     71                imdb->year = ostrcat(getxmlentry(tmpstr, "\"Year\":"), NULL, 0, 0);
     72                imdb->rated = ostrcat(getxmlentry(tmpstr, "\"Rated\":"), NULL, 0, 0);
     73                imdb->released = ostrcat(getxmlentry(tmpstr, "\"Released\":"), NULL, 0, 0);
     74                imdb->genre = ostrcat(getxmlentry(tmpstr, "\"Genre\":"), NULL, 0, 0);
     75                imdb->director = ostrcat(getxmlentry(tmpstr, "\"Director\":"), NULL, 0, 0);
     76                imdb->writer = ostrcat(getxmlentry(tmpstr, "\"Writer\":"), NULL, 0, 0);
     77                imdb->actors = ostrcat(getxmlentry(tmpstr, "\"Actors\":"), NULL, 0, 0);
     78                imdb->plot = ostrcat(getxmlentry(tmpstr, "\"Plot\":"), NULL, 0, 0);
     79                imdb->poster = ostrcat(getxmlentry(tmpstr, "\"Poster\":"), NULL, 0, 0);
     80                imdb->runtime = ostrcat(getxmlentry(tmpstr, "\"Runtime\":"), NULL, 0, 0);
     81                imdb->rating = ostrcat(getxmlentry(tmpstr, "\"Rating\":"), NULL, 0, 0);
     82                imdb->votes = ostrcat(getxmlentry(tmpstr, "\"Votes\":"), NULL, 0, 0);
     83                imdb->id = ostrcat(getxmlentry(tmpstr, "\"ID\":"), NULL, 0, 0);
     84
     85                if(imdb->poster != NULL)
     86                {
     87                        char* ip = NULL, *pos = NULL, *path = NULL;
     88                        ip = string_replace("http://", "", imdb->poster, 0);
     89
     90                        if(ip != NULL)
     91                                pos = strchr(ip, '/');
     92                        if(pos != NULL)
     93                        {
     94                                pos[0] = '\0';
     95                                path = pos + 1;
     96                        }
     97
     98                        gethttp(ip, path, 80, TMPIMDBPIC, NULL, NULL, 0);
     99                        free(ip); ip = NULL;
     100
     101                }
     102                free(tmpstr); tmpstr = NULL;
     103        }
     104
     105        return imdb;
     106}
     107
     108void screenimdb(char* title)
    19109{
    20110        int rcret = 0;
    21         drawscreen(skin, 0);
    22         setfbtransparent(255);
    23 //NIT: muß wieder richtig gesetzt werden
    24         status.hangtime = 99999;
    25         struct skin* blackscreen = getscreen("blackscreen");
    26         drawscreen(blackscreen, 0);
    27 
    28         // main screen
    29111        struct skin* imdbskin = getscreen("imdb");
    30112        struct skin* skin_plot = getscreennode(imdbskin, "plot");
     
    38120        struct skin* skin_cover = getscreennode(imdbskin, "cover");
    39121        struct skin* skin_cast = getscreennode(imdbskin, "cast");
     122        struct imdb* node = NULL;
    40123
    41 //if(ostrcmp("vfdisplay", name) == 0) return 0;
    42 //tmpstr = ostrcat(tmpstr, "", 1, 0);
     124        setfbtransparent(255);
     125        status.hangtime = 99999;
    43126
    44         char* input = NULL;
     127        if(title = NULL) title = getepgakttitle(NULL);
    45128
    46         char* url = NULL;
    47         char* apiSearchTV = NULL;
    48         char* apiImdbLookup = NULL;
    49         char* apiSearch = NULL;
    50         char* localfile = NULL;
    51         char* fetchurl = NULL;
    52         char* search = NULL;
    53         char* tmpstr = NULL;
    54         char* imdbid = NULL;
    55         char* title = NULL;
    56         char* plot = NULL;
    57         char* director = NULL;
    58         char* writers = NULL;
    59         char* genre = NULL;
    60         char* tagline = NULL;
    61         char* releasetime = NULL;
    62         char* pagebigcover = NULL;
    63         char* bigcover = NULL;
    64         char* cover = NULL;
    65         char* cast = NULL;
    66 
    67 
    68         input = getepgakttitle(NULL);
    69 //      input = screensearch("Rambo");
    70         printf("input: %s\n", input);
    71 //      stringreplacechar(input, ' ', '%20');
    72         input = string_replace(" ", "%20", input, 1);
    73 //      htmlencode(input);
    74         printf("input: %s\n", input);
    75 
    76 //drawscreen(imdbskin, 0);
    77 //imdbskin->hidden = YES;
    78 //      input = ostrcat("", "Days+of+Summer", 0, 0);
    79         url = ostrcat(url, "www.imdb.de", 1, 0);
    80 
    81         apiSearchTV = ostrcat("", "/search/title?title=<title>&title_type=tv_series", 0, 0);
    82         apiImdbLookup = ostrcat("", "/title/tt", 0, 0);
    83         apiSearch = ostrcat("", "/find?s=tt;q=", 0, 0);
    84         localfile = ostrcat("", "/tmp/cache.getMovieByTitle.html", 0, 0);
    85         search = ostrcat(apiSearch, input, 0, 0);
    86         printf("search: %s\n", search);
    87         tmpstr = get_ip(url);
    88         printf("get_ip(url): %s\n", tmpstr);
    89         gethttp(tmpstr, search, 80, localfile, NULL, NULL, 0);
    90         free(tmpstr); tmpstr = NULL;
    91 //      gethttp(url, search, 80, localfile, NULL, NULL, 0);
    92 
    93 
    94         tmpstr = readfiletomem(localfile, 1);
    95 
    96         if(string_find("<title>IMDb Title Search</title>",tmpstr))
     129        node = getimdb(title);
     130        if(node != NULL)
    97131        {
    98                 imdbid = ostrcat(tmpstr, "", 0, 0);
    99                 string_resub("<a href=\"/title/tt","/",imdbid);
    100                 strstrip(imdbid);
    101                 printf("imdbid: %s\n", imdbid);
     132                changetext(skin_plot, node->plot);
     133                changetext(skin_title, node->title);
     134                changetext(skin_director, node->director);
     135                changetext(skin_writers, node->writer);
     136                changetext(skin_genre, node->genre);
     137                changetext(skin_releasetime, node->released);
     138                changepic(skin_cover, TMPIMDBPIC);
    102139        }
    103140
    104         free(tmpstr), tmpstr = NULL;
    105 ////////////////////
    106         search = ostrcat(apiImdbLookup, imdbid, 0, 0);
    107         search = ostrcat(search, "/", 0, 0);
     141        drawscreen(imdbskin, 0);
    108142
    109         localfile = ostrcat("", "/tmp/cache.getMoviesByImdbId.html", 0, 0);
    110         printf("search: %s\n", search);
    111         printf("url: %s\n", get_ip(url));
    112         printf("localfile: %s\n", localfile);
    113 
    114 //      gethttp(get_ip(url), search, 80, localfile, NULL, NULL, 0);
    115 //      gethttp(url, search, 80, localfile, NULL, NULL, 0);
    116         unlink(localfile);
    117 //cache.getMoviesByImdbId.html
    118         char* cmd = NULL;
    119         cmd = ostrcat(cmd, "wget http://", 1, 0);
    120         cmd = ostrcat(cmd, url, 1, 0);
    121         cmd = ostrcat(cmd, search, 1, 0);
    122         cmd = ostrcat(cmd, " -O ", 1, 0);
    123         cmd = ostrcat(cmd, localfile, 1, 0);
    124         printf("cmd: %s\n",cmd);
    125         system(cmd);
    126         free(cmd), cmd = NULL;
    127 //      tmpstr = string_strip_whitechars(readfiletomem(localfile, 1));
    128         tmpstr = readfiletomem(localfile, 1);
    129 
    130         title = ostrcat(tmpstr, "", 0, 0);
    131         string_resub("<title>","</title>",title);
    132         printf("title: %s\n", title);
    133         title = string_decode(title,1);
    134         printf("title: %s\n", title);
    135         changetext(skin_title, title);
    136 
    137 ////////////////////
    138         director = ostrcat(tmpstr, "", 0, 0);
    139 //      string_resub("Director:","</div>",director);   
    140         string_resub("Regisseur:","</div>",director);
    141         string_striptags(director);
    142         printf("director: %s\n", director);
    143         director = string_decode(director,1);
    144         printf("director: %s\n", director);
    145         changetext(skin_director, director);
    146 
    147 
    148 ////////////////////
    149 
    150         writers = ostrcat(tmpstr, "", 0, 0);
    151 //      string_resub("<h5>Writers","</div>",writers);
    152         string_resub("<h5>Drehbuchautor","</div>",writers);
    153         printf("writers1: %s\n", writers);
    154         string_resub("<div class=\"info-content\">","</div>",writers);
    155         printf("writers2: %s\n", writers);
    156 
    157         string_striptags(writers);
    158         printf("writers3: %s\n", writers);
    159         writers = string_decode(writers,1);
    160         printf("writers: %s\n", writers);       
    161         changetext(skin_writers, writers);
    162 ////////////////////
    163 
    164         genre = ostrcat(tmpstr, "", 0, 0);
    165         string_resub("<h5>Genre:</h5>","</div>",genre);
    166         printf("genre1: %s\n", genre);
    167         string_striptags(genre);
    168         printf("genre2: %s\n", genre);
    169         genre = string_decode(genre,1);
    170         printf("genre: %s\n", genre);
    171         changetext(skin_genre, genre);
    172 
    173 /*
    174         genre = string_replace("&#x", "%", genre, 1);
    175         printf("genre2222: %s\n", genre);
    176         char* genre_tmp = NULL;
    177         genre = string_replace(";", " ", genre, 1);
    178         genre_tmp = ostrcat(genre_tmp, genre, 1, 0);
    179         printf("genre333: %s\n", genre_tmp);           
    180 //      free(genre),genre = NULL;
    181 
    182         htmldecode(genre,genre_tmp);
    183         printf("genre444: %s\n", genre);
    184 //      free(genre_tmp),genre_tmp = NULL;               
    185         changetext(skin_genre, genre);
    186 */     
    187 ////////////////////
    188 
    189 /*
    190 
    191         tagline = ostrcat(tmpstr, "", 0, 0);
    192         string_resub("<h4 class=\"inline\">Taglines:</h4>","<span class",tagline);
    193 
    194         strstrip(tagline);
    195         printf("tagline: %s\n", tagline);
    196         changetext(skin_tagline, tagline);
    197 
    198         releasetime = ostrcat(tmpstr, "", 0, 0);
    199         string_resub("<h4 class=\"inline\">Release Date:</h4>","</time>",releasetime);
    200         count2 = 0;     
    201         tmpstr2 = ostrcat(tmpstr2, releasetime, 1, 0);
    202         ret2 = strsplit(tmpstr2, "<>", &count2);
    203         printf("releasetime1: %s\n", (&ret2[2])->part);
    204         strstrip(releasetime);
    205         printf("releasetime: %s\n", releasetime);
    206         changetext(skin_releasetime, (&ret2[2])->part);
    207 */
    208 
    209         releasetime = ostrcat(tmpstr, "", 0, 0);
    210         string_resub("<h5>Premierendatum:</h5>","<a class=",releasetime);
    211         printf("releasetime1: %s\n", releasetime);
    212 
    213         string_striptags(releasetime);
    214         printf("releasetime2: %s\n", releasetime);
    215         releasetime = string_decode(releasetime,1);
    216         printf("releasetime: %s\n", releasetime);
    217         changetext(skin_releasetime, releasetime);
    218 
    219 ////////////////////
    220 
    221         cast = ostrcat(tmpstr, "", 0, 0);
    222         string_resub("<h3>Besetzung</h3>&nbsp;","</td></tr></table>",cast);
    223         string_resub("<div class=\"info-content block\"><table class=\"cast\">","</a></td></tr>",cast);
    224 
    225         cast = string_replace("...", "als", cast, 1);
    226 
    227         printf("cast1: %s\n", cast);
    228 
    229         string_striptags(cast);
    230         string_strip_whitechars(cast);
    231         printf("cast2: %s\n", cast);
    232         cast = string_decode(cast,1);
    233         printf("cast: %s\n", cast);
    234         changetext(skin_cast, cast);
    235        
    236 ////////////////////
    237 
    238 
    239         pagebigcover = ostrcat(tmpstr, "", 0, 0);
    240 //      string_resub("href=\"/media/rm","/",pagebigcover);
    241         string_resub("/media/rm","/",pagebigcover);
    242 
    243         strstrip(pagebigcover);
    244         printf("pagebigcover: %s\n", pagebigcover);
    245 
    246 /*
    247 http://ia.media-imdb.com/images/M/MV5BMjE2MzU3Nzk4M15BMl5BanBnXkFtZTcwODcxNTI5Mw@@._V1_.jpg
    248 <link rel="image_src" href="
    249 
    250 //      char* tmpstr3 = NULL;
    251 //      tmpstr3 = ostrcat("href=\"/media/rm", pagebigcover, 0, 0);
    252 //      tmpstr3 = ostrcat(tmpstr3, "/tt", 1, 0);
    253 //      tmpstr3 = ostrcat(tmpstr3, imdbid, 1, 0);
    254 //      tmpstr3 = ostrcat(tmpstr3, "\"    ><img src=\"", 1, 0);
    255 
    256         cover = ostrcat(tmpstr, "", 0, 0);
    257         string_resub(tmpstr3,"\"",cover);
    258 
    259         printf("tmpstr3: %s\n", tmpstr3);
    260         strstrip(cover);
    261         printf("cover: %s\n", cover);
    262 
    263 char* filename = NULL;
    264 filename = ostrcat("wget ", cover, 0, 0);
    265 filename = ostrcat(filename, " -O /tmp/cover.jpg", 1, 0);
    266 system(filename);       
    267 changepic(skin_cover, "/tmp/cover.jpg");
    268 ////////////////////
    269 
    270 */
    271         char* filename = NULL;
    272         search = ostrcat("/media/rm", pagebigcover, 0, 0);
    273         search = ostrcat(search, "/tt", 1, 0);
    274         search = ostrcat(search, imdbid, 1, 0);
    275         search = ostrcat(search, "/", 1, 0);
    276 
    277         localfile = ostrcat("", "/tmp/cache.getpageBigCoverHtml.html", 0, 0);
    278         printf("search: %s\n", search);
    279         printf("url: %s\n", get_ip(url));
    280         printf("localfile: %s\n", localfile);
    281 
    282 
    283 //NIT: get_ip braucht ein free
    284         gethttp(get_ip(url), search, 80, localfile, NULL, NULL, 0);
    285 //      gethttp(url, search, 80, localfile, NULL, NULL, 0);
    286         bigcover = readfiletomem(localfile, 1);
    287         string_resub("<link rel=\"image_src\" href=\"","\"",bigcover);
    288         strstrip(bigcover);
    289         printf("bigcover: %s\n", bigcover);
    290 
    291         unlink("/tmp/bigcover.jpg");
    292         filename = ostrcat("wget ", bigcover, 0, 0);
    293         filename = ostrcat(filename, " -O /tmp/bigcover.jpg", 1, 0);
    294         system(filename);
    295 
    296         rcret = servicestop(status.aktservice, 1, 0);
    297         if(rcret == 1) return;
    298 
    299 changepic(skin_cover, "/tmp/bigcover.jpg");
    300 ////////////////////
    301 
    302 //      free(tmpstr), tmpstr = NULL;
    303         search = ostrcat(apiImdbLookup, imdbid, 0, 0);
    304         search = ostrcat(search, "/plotsummary", 1, 0);
    305 
    306         localfile = ostrcat("", "/tmp/cache.getPlot.html", 0, 0);
    307         printf("search: %s\n", search);
    308         printf("url: %s\n", get_ip(url));
    309         printf("localfile: %s\n", localfile);
    310 //      gethttp(get_ip(url), search, 80, localfile, NULL, NULL, 0);
    311 //      gethttp(url, search, 80, localfile, NULL, NULL, 0);
    312 
    313         unlink(localfile);
    314         cmd = ostrcat(cmd, "wget http://", 1, 0);
    315         cmd = ostrcat(cmd, url, 1, 0);
    316         cmd = ostrcat(cmd, search, 1, 0);
    317         cmd = ostrcat(cmd, " -O ", 1, 0);
    318         cmd = ostrcat(cmd, localfile, 1, 0);
    319         printf("cmd: %s\n",cmd);
    320         system(cmd);
    321         free(cmd), cmd = NULL;
    322        
    323        
    324         plot = readfiletomem(localfile, 1);
    325         string_resub("<div id=\"swiki.2.1\">","</div>",plot);
    326         printf("plot1: %s\n", plot);
    327         string_striptags(plot);
    328         printf("plot: %s\n", plot);
    329         plot = string_decode(plot,1);
    330         printf("plot: %s\n", plot);
    331         changetext(skin_plot, plot);   
    332        
    333 //      if(string_find("<p class=\"plotpar\">",plot))
    334 //      {
    335 //              string_resub("<p class=\"plotpar\">","<i>",plot);
    336 //              strstrip(plot);
    337 //              printf("plot: %s\n", plot);
    338 //changetext(skin_plot, plot);
    339 //      }
    340 
    341 drawscreen(imdbskin, 0);
    342 //imdbskin->hidden = NO;
    343         struct skin* tmp = NULL;
    344143        while(1)
    345144        {
    346 //              addscreenrc(mc_videoplayer_settings, tmp);
    347145                rcret = waitrc(imdbskin, 0, 0);
    348 //              tmp = listbox->select;
    349146       
    350147                if(rcret == getrcconfigint("rcexit", NULL)) break;
    351                 if(rcret == getrcconfigint("rcok", NULL))
    352                 {
    353                         break;
    354                 }
    355   }
     148                if(rcret == getrcconfigint("rcok", NULL)) break;
     149        }
    356150
    357 
    358         printf("done:\n");
    359 
    360         free(tmpstr), tmpstr = NULL;
    361         free(url), url = NULL;
    362         free(apiSearchTV), apiSearchTV = NULL;
    363         free(apiImdbLookup), apiImdbLookup = NULL;
    364         free(apiSearch), apiSearch = NULL;
    365         free(localfile), localfile = NULL;
    366         free(fetchurl), fetchurl = NULL;
    367         free(search), search = NULL;
    368         free(imdbid), imdbid = NULL;
    369         free(plot), plot = NULL;
    370         free(director), director = NULL;
    371         free(writers), writers = NULL;
    372         free(genre), genre = NULL;
    373         free(tagline), tagline = NULL;
    374         free(releasetime), releasetime = NULL;
    375         free(pagebigcover), pagebigcover = NULL;
    376         free(bigcover), bigcover = NULL;
    377         free(cover), cover = NULL;
    378         free(cast), cast = NULL;
    379 
    380         delownerrc(imdbskin);
     151        freeimdb(node); node = NULL;
     152        setosdtransparent(getskinconfigint("osdtransparent", NULL));
     153        status.hangtime = getconfigint("hangtime", NULL);
    381154        clearscreen(imdbskin);
    382         drawscreen(skin, 0);
    383 
    384         setosdtransparent(getskinconfigint("osdtransparent", NULL));
    385         servicestart(status.lastservice->channel, NULL, NULL, 0);
    386        
    387 //      return apiSearch;
    388         return;
    389155}
    390156
Note: See TracChangeset for help on using the changeset viewer.