/tags/v2-73/mh/code/common/tv_info.pl

# · Perl · 103 lines · 79 code · 17 blank · 7 comment · 16 complexity · ee57db5dd7e0cba6d70e1fc9c37d2502 MD5 · raw file

  1. # Category=TV
  2. #@ This code will search for tv shows in the database created
  3. #@ by tv_grid code.
  4. $f_tv_file = new File_Item("$config_parms{data_dir}/tv_info1.txt");
  5. $v_tv_movies1 = new Voice_Cmd('What TV movies are on channel [all,4-12,4,6,8,9,12] tonight');
  6. $v_tv_movies2 = new Voice_Cmd('What TV movies are on at [6pm,7pm,8pm,9pm] tonight');
  7. $v_tv_movies1-> set_info('Looks for TV shows that are 2-3 hours in length from 6 to 10 pm, on channels:');
  8. $v_tv_movies2-> set_info('Looks for TV shows that are 2-3 hours in length on all channels, at time:');
  9. $v_tv_shows1 = new Voice_Cmd('What TV shows are on channel [5,6,8,9,12,51] tonight');
  10. $v_tv_shows2 = new Voice_Cmd('What favorite TV shows are on today');
  11. $v_tv_shows1-> set_info('Lists all shows on from 6 to 10 pm tonight on channel:');
  12. $v_tv_shows2-> set_info("Checks to see if any of the following shows in $config_parms{favorite_tv_shows} are on today");
  13. if ($state = said $v_tv_movies1) {
  14. run qq[get_tv_info -length 2-3 -times 6pm+4 -channels $state];
  15. set_watch $f_tv_file;
  16. }
  17. if ($state = said $v_tv_movies2) {
  18. run qq[get_tv_info -length 2-3 -times $state+.5];
  19. set_watch $f_tv_file;
  20. }
  21. if ($state = said $v_tv_shows1) {
  22. run qq[get_tv_info -channels $state];
  23. set_watch $f_tv_file;
  24. }
  25. if (said $v_tv_shows2) {
  26. print_log "Searching for favorite shows";
  27. run qq[get_tv_info -times all -keys "$config_parms{favorite_tv_shows}" -keyfile $config_parms{favorite_tv_shows_file} -title_only];
  28. set_watch $f_tv_file 'favorites today';
  29. }
  30. # Check for favorite shows ever 1/2 hour
  31. if (time_cron('58,28 * * * *')) {
  32. my ($min, $hour, $mday, $mon) = (localtime(time + 120))[1,2,3,4];
  33. $mon++;
  34. run qq[get_tv_info -quiet -times $hour:$min -dates $mon/$mday -keys "$config_parms{favorite_tv_shows}" -keyfile $config_parms{favorite_tv_shows_file} -title_only];
  35. set_watch $f_tv_file 'favorites now';
  36. }
  37. # Search for requested keywords
  38. #&tk_entry('TV search', \$Save{tv_search}, 'TV dates', \$Save{tv_days});
  39. if ($Tk_results{'TV search'} or $Tk_results{'TV dates'}) {
  40. speak "Searching";
  41. run qq[get_tv_info -times all -dates "$Save{tv_days}" -keys "$Save{tv_search}"];
  42. set_watch $f_tv_file;
  43. undef $Tk_results{'TV search'};
  44. undef $Tk_results{'TV dates'};
  45. }
  46. # Speak/show the results for all of the above requests
  47. $v_tv_results = new Voice_Cmd 'What are the tv search results';
  48. if ($state = changed $f_tv_file or said $v_tv_results) {
  49. my $f_tv_info2 = "$config_parms{data_dir}/tv_info2.txt";
  50. my $summary = read_head $f_tv_file 6;
  51. my ($show_count) = $summary =~ /Found (\d+)/;
  52. my @data = read_all $f_tv_file;
  53. shift @data; # Drop summary;
  54. my $i = 0;
  55. foreach my $line (@data) {
  56. if (my ($title, $channel, $start, $end) =
  57. $line =~ /^\d+\.\s+(.+)\.\s+\S+\s+Channel (\d+).+From ([0-9: APM]+) till ([0-9: APM]+)\./) {
  58. if ($state eq 'favorites now') {
  59. $data[$i] = "$title Channel $channel.\n";
  60. }
  61. else {
  62. $data[$i] = "$start Channel $channel $title.\n";
  63. }
  64. }
  65. $i++;
  66. }
  67. my $msg = "There ";
  68. $msg .= ($show_count > 1) ? " are " : " is ";
  69. $msg .= plural($show_count, 'favorite show');
  70. if ($state eq 'favorites today') {
  71. if ($show_count > 0) {
  72. speak "$msg on today. @data";
  73. }
  74. else {
  75. speak "There are no favorite shows on today";
  76. }
  77. }
  78. elsif ($state eq 'favorites now') {
  79. speak "rooms=all Notice, $msg starting now. @data" if $show_count > 0;
  80. }
  81. else {
  82. chomp $summary; # Drop the cr
  83. speak "$summary @data ";
  84. }
  85. display $f_tv_info2 if $show_count;
  86. }