Changeset 4283

Show
Ignore:
Timestamp:
03/07/10 10:36:22 (6 months ago)
Author:
andoma
Message:

Add support for opensubtitles.org

Location:
trunk/showtime
Files:
7 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/showtime/Makefile

    r4280 r4283  
    5353        src/misc/pixmap.c \ 
    5454        src/misc/jpeg.c \ 
     55        src/misc/gz.c \ 
    5556 
    5657# 
     
    104105 
    105106SRCS                   += src/scrappers/scrappers.c 
     107 
     108# 
     109# APIs 
     110# 
     111SRCS +=                 src/api/xmlrpc.c \ 
     112                        src/api/opensubtitles.c \ 
    106113 
    107114# 
  • trunk/showtime/src/fileaccess/fa_video.c

    r4262 r4283  
    3737#include "notifications.h" 
    3838#include "video/subtitles.h" 
     39#include "api/opensubtitles.h" 
    3940 
    4041/** 
     
    330331      event_select_track_t *est = (event_select_track_t *)e; 
    331332      const char *id = est->id; 
    332        
    333       if(id[0] >= '0' && id[0] <= '9') { 
     333 
     334      if(!strcmp(id, "sub:off")) { 
     335        prop_set_string(mp->mp_prop_subtitle_track_current, id); 
     336        mp->mp_video.mq_stream2 = -1; 
     337 
     338        if(sub != NULL) { 
     339          subtitles_destroy(sub); 
     340          sub = NULL; 
     341        } 
     342 
     343 
     344      } else if(!strcmp(id, "audio:off")) { 
     345        prop_set_string(mp->mp_prop_subtitle_track_current, id); 
     346        mp->mp_video.mq_stream2 = -1; 
     347 
     348      } else if(id[0] >= '0' && id[0] <= '9') { 
    334349        unsigned int idx = atoi(est->id); 
    335350        if(idx < fctx->nb_streams) { 
     
    339354            prop_set_int(mp->mp_prop_audio_track_current, idx); 
    340355          } else if(ctx->codec_type == CODEC_TYPE_SUBTITLE) { 
     356 
     357            if(sub != NULL) { 
     358              subtitles_destroy(sub); 
     359              sub = NULL; 
     360            } 
     361 
    341362            mp->mp_video.mq_stream2 = idx; 
    342363            prop_set_int(mp->mp_prop_subtitle_track_current, idx); 
    343364          } 
    344365        } 
     366      } else { 
     367        mp->mp_video.mq_stream2 = -1; 
     368 
     369        prop_set_string(mp->mp_prop_subtitle_track_current, est->id); 
     370 
     371        if(sub != NULL) 
     372          subtitles_destroy(sub); 
     373 
     374        sub = subtitles_load(est->id); 
    345375      } 
    346376 
     
    359389  return e; 
    360390} 
     391 
     392/** 
     393 * 
     394 */ 
     395static void 
     396add_off_stream(prop_t *prop, const char *id) 
     397{ 
     398  prop_t *p = prop_create(prop, NULL); 
     399   
     400  prop_set_string(prop_create(p, "id"), id); 
     401  prop_set_string(prop_create(p, "title"), "Off"); 
     402} 
     403 
    361404 
    362405/** 
     
    377420  fa_handle_t *fh; 
    378421 
     422  uint64_t hash; 
     423  uint64_t fsize; 
     424  int valid_hash = 0; 
     425 
    379426  if(fa_stat(url, &buf, errbuf, errlen)) 
    380427    return NULL; 
     
    405452#endif 
    406453  } 
     454 
     455 
     456  valid_hash = !opensub_compute_hash(fh, &hash); 
     457  fsize = fa_fsize(fh); 
    407458  fa_close(fh); 
    408  
    409  
     459   
    410460  /** 
    411461   * Open input file 
     
    427477  TRACE(TRACE_DEBUG, "Video", "Starting playback of %s", url); 
    428478 
     479  add_off_stream(prop_create(mp->mp_prop_metadata, "subtitlestreams"), 
     480                 "sub:off"); 
     481 
     482  add_off_stream(prop_create(mp->mp_prop_metadata, "audiostreams"), 
     483                 "audio:off"); 
     484 
    429485  /** 
    430486   * Update property metadata 
    431487   */ 
    432488  fa_probe_load_metaprop(mp->mp_prop_metadata, fctx, faurl); 
     489 
     490  /** 
     491   * Query opensubtitles.org 
     492   */ 
     493 
     494  opensub_add_subtitles(prop_create(mp->mp_prop_metadata, "subtitlestreams"), 
     495                        opensub_build_query(NULL, hash, fsize, NULL, NULL)); 
    433496 
    434497  /** 
     
    462525  prop_set_int(mp->mp_prop_audio_track_current, mp->mp_audio.mq_stream); 
    463526 
     527  prop_set_string(mp->mp_prop_subtitle_track_current, "sub:off"); 
     528 
    464529  mp_set_play_caps(mp, MP_PLAY_CAPS_SEEK | MP_PLAY_CAPS_PAUSE); 
    465530 
  • trunk/showtime/src/main.c

    r4116 r4283  
    4242#include "scrappers/scrappers.h" 
    4343#include "misc/callout.h" 
     44#include "api/opensubtitles.h" 
    4445 
    4546/** 
     
    217218  /* Service discovery. Must be after ipc_init() (d-bus and threads, etc) */ 
    218219  sd_init(); 
     220 
     221  /* opensubtitles.org */ 
     222  opensub_init(); 
    219223 
    220224  TRACE(TRACE_DEBUG, "core", "Starting UI"); 
  • trunk/showtime/src/video/subtitles.c

    r4270 r4283  
    1919#include <stdio.h> 
    2020#include <string.h> 
    21 #include <sys/time.h> 
    22 #include <time.h> 
     21#include <unistd.h> 
    2322 
    2423#include "showtime.h" 
    2524#include "subtitles.h" 
    2625#include "fileaccess/fileaccess.h" 
    27 #include <unistd.h> 
     26#include "misc/gz.h" 
    2827 
    2928#if 0 
     
    599598} 
    600599 
    601 #if 1 
    602  
    603 #include <sys/types.h> 
    604 #include <sys/stat.h> 
    605 #include <unistd.h> 
    606 #include <fcntl.h> 
    607  
    608  
     600 
     601/** 
     602 * 
     603 */ 
    609604subtitles_t * 
    610 subtitles_test(const char *fname) 
    611 { 
    612   struct stat st; 
    613   int fd = open(fname, O_RDONLY); 
    614   if(fd == -1) 
     605subtitles_load(const char *url) 
     606{ 
     607  subtitles_t *sub; 
     608  char errbuf[256]; 
     609  size_t datalen; 
     610 
     611  char *data = fa_quickload(url, &datalen, NULL, errbuf, sizeof(errbuf)); 
     612 
     613  if(data == NULL) { 
     614    TRACE(TRACE_ERROR, "Subtitles", "Unable to load %s -- %s",  
     615          url, errbuf); 
    615616    return NULL; 
    616  
    617   if(fstat(fd, &st)) 
    618     return NULL; 
    619  
    620   char *mem = malloc(st.st_size); 
    621   if(read(fd, mem, st.st_size) != st.st_size) 
    622     return NULL; 
    623  
    624   close(fd); 
    625   printf("Reading subtitles\n"); 
    626   return subtitles_create(mem, st.st_size); 
    627 } 
    628 #endif 
     617  } 
     618 
     619  if(gz_check(data, datalen)) { 
     620    // is .gz compressed, inflate it 
     621 
     622    char *inflated; 
     623    size_t inflatedlen; 
     624 
     625    inflated = gz_inflate(data, datalen, &inflatedlen, errbuf, sizeof(errbuf)); 
     626 
     627    free(data); 
     628    if(inflated == NULL) { 
     629      TRACE(TRACE_ERROR, "Subtitles", "Unable to decompress %s -- %s",  
     630            url, errbuf); 
     631      return NULL; 
     632    } else { 
     633      data = inflated; 
     634      datalen = inflatedlen; 
     635    } 
     636  } 
     637 
     638  sub = subtitles_create(data, datalen); 
     639 
     640  free(data); 
     641 
     642  if(sub == NULL) 
     643    TRACE(TRACE_ERROR, "Subtitles", "Unable to load %s -- Unknown format",  
     644          url); 
     645  return sub; 
     646} 
  • trunk/showtime/src/video/subtitles.h

    r4262 r4283  
    4646subtitle_entry_t *subtitles_pick(subtitles_t *sub, int64_t pts); 
    4747 
     48subtitles_t *subtitles_load(const char *url); 
     49 
    4850#endif /* SUBTITLES_H_ */