Changeset 4283
- Timestamp:
- 03/07/10 10:36:22 (6 months ago)
- Location:
- trunk/showtime
- Files:
-
- 7 added
- 5 modified
-
Makefile (modified) (2 diffs)
-
src/api (added)
-
src/api/opensubtitles.c (added)
-
src/api/opensubtitles.h (added)
-
src/api/xmlrpc.c (added)
-
src/api/xmlrpc.h (added)
-
src/fileaccess/fa_video.c (modified) (8 diffs)
-
src/main.c (modified) (2 diffs)
-
src/misc/gz.c (added)
-
src/misc/gz.h (added)
-
src/video/subtitles.c (modified) (2 diffs)
-
src/video/subtitles.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/showtime/Makefile
r4280 r4283 53 53 src/misc/pixmap.c \ 54 54 src/misc/jpeg.c \ 55 src/misc/gz.c \ 55 56 56 57 # … … 104 105 105 106 SRCS += src/scrappers/scrappers.c 107 108 # 109 # APIs 110 # 111 SRCS += src/api/xmlrpc.c \ 112 src/api/opensubtitles.c \ 106 113 107 114 # -
trunk/showtime/src/fileaccess/fa_video.c
r4262 r4283 37 37 #include "notifications.h" 38 38 #include "video/subtitles.h" 39 #include "api/opensubtitles.h" 39 40 40 41 /** … … 330 331 event_select_track_t *est = (event_select_track_t *)e; 331 332 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') { 334 349 unsigned int idx = atoi(est->id); 335 350 if(idx < fctx->nb_streams) { … … 339 354 prop_set_int(mp->mp_prop_audio_track_current, idx); 340 355 } else if(ctx->codec_type == CODEC_TYPE_SUBTITLE) { 356 357 if(sub != NULL) { 358 subtitles_destroy(sub); 359 sub = NULL; 360 } 361 341 362 mp->mp_video.mq_stream2 = idx; 342 363 prop_set_int(mp->mp_prop_subtitle_track_current, idx); 343 364 } 344 365 } 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); 345 375 } 346 376 … … 359 389 return e; 360 390 } 391 392 /** 393 * 394 */ 395 static void 396 add_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 361 404 362 405 /** … … 377 420 fa_handle_t *fh; 378 421 422 uint64_t hash; 423 uint64_t fsize; 424 int valid_hash = 0; 425 379 426 if(fa_stat(url, &buf, errbuf, errlen)) 380 427 return NULL; … … 405 452 #endif 406 453 } 454 455 456 valid_hash = !opensub_compute_hash(fh, &hash); 457 fsize = fa_fsize(fh); 407 458 fa_close(fh); 408 409 459 410 460 /** 411 461 * Open input file … … 427 477 TRACE(TRACE_DEBUG, "Video", "Starting playback of %s", url); 428 478 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 429 485 /** 430 486 * Update property metadata 431 487 */ 432 488 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)); 433 496 434 497 /** … … 462 525 prop_set_int(mp->mp_prop_audio_track_current, mp->mp_audio.mq_stream); 463 526 527 prop_set_string(mp->mp_prop_subtitle_track_current, "sub:off"); 528 464 529 mp_set_play_caps(mp, MP_PLAY_CAPS_SEEK | MP_PLAY_CAPS_PAUSE); 465 530 -
trunk/showtime/src/main.c
r4116 r4283 42 42 #include "scrappers/scrappers.h" 43 43 #include "misc/callout.h" 44 #include "api/opensubtitles.h" 44 45 45 46 /** … … 217 218 /* Service discovery. Must be after ipc_init() (d-bus and threads, etc) */ 218 219 sd_init(); 220 221 /* opensubtitles.org */ 222 opensub_init(); 219 223 220 224 TRACE(TRACE_DEBUG, "core", "Starting UI"); -
trunk/showtime/src/video/subtitles.c
r4270 r4283 19 19 #include <stdio.h> 20 20 #include <string.h> 21 #include <sys/time.h> 22 #include <time.h> 21 #include <unistd.h> 23 22 24 23 #include "showtime.h" 25 24 #include "subtitles.h" 26 25 #include "fileaccess/fileaccess.h" 27 #include <unistd.h>26 #include "misc/gz.h" 28 27 29 28 #if 0 … … 599 598 } 600 599 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 */ 609 604 subtitles_t * 610 subtitles_test(const char *fname) 611 { 612 struct stat st; 613 int fd = open(fname, O_RDONLY); 614 if(fd == -1) 605 subtitles_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); 615 616 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 46 46 subtitle_entry_t *subtitles_pick(subtitles_t *sub, int64_t pts); 47 47 48 subtitles_t *subtitles_load(const char *url); 49 48 50 #endif /* SUBTITLES_H_ */