| tvkaista-0.962/tvkaista-helper.pl | | tvkaista-0.964/tvkaista-helper.pl |
| 4 | # Author: Tomi Ollila -- too ät iki piste fi | 4 | # Author: Tomi Ollila -- too ät iki piste fi |
| 5 | # | 5 | # |
| 6 | # Created: Sat Feb 07 21:29:53 EET 2009 too | 6 | # Created: Sat Feb 07 21:29:53 EET 2009 too |
| 7 | # Last modified: Tue 28 Apr 2009 21:55:13 EEST too | 7 | # Last modified: Mon 04 May 2009 21:40:38 EEST too |
| 8 | | 8 | |
| 9 | #PERL_UNICODE=SD perl tvkaista-helper.pl 1 update | 9 | #PERL_UNICODE=SD perl tvkaista-helper.pl 1 update |
| 10 | #or perl -CSD perl tvkaista-helper.pl 1 list | 10 | #or perl -CSD perl tvkaista-helper.pl 1 list |
| 26 | | 26 | |
| 27 | sub usage() | 27 | sub usage() |
| 28 | { | 28 | { |
| 29 | die "Usage: $0 <output-fd> (list|play|update)\n"; | 29 | die "Usage: $0 [gui] (list|play|update)\n"; |
| 30 | } | 30 | } |
| 31 | | 31 | |
| 32 | if (defined $ARGV[1]) | 32 | my $gui = 0; |
| 33 | { | 33 | $gui = 1, shift @ARGV if (defined $ARGV[0] && $ARGV[0] eq 'gui'); |
| 34 | my $dfd = int($ARGV[0]); | | |
| 35 | open STDOUT, ">>&$dfd" if ($dfd > 1); | | |
| 36 | } | | |
| 37 | else { usage; } | | |
| 38 | | 34 | |
| 39 | my $recdir = 'tallenteet'; | 35 | my $recdir = 'tallenteet'; |
| 40 | if (-e $recdir) | 36 | if (-e $recdir) |
| 63 | | 59 | |
| 64 | sub mkpw($) | 60 | sub mkpw($) |
| 65 | { | 61 | { |
| 66 | if ($_[0]) { | 62 | if ($gui) { |
| 67 | print "\nKäyttäjätunnus ja/tai salasana saattaa olla väärä\n"; | 63 | open I, '-|', "./tvkaista_gtkpw $_[0]"; |
| 68 | print "tai kyseessä on verkko-ongelma.\n"; | 64 | chomp ($username = <I>); |
| 69 | print "Haluatko antaa uudet (k/e) ? "; | 65 | chomp ($password = <I>); |
| 70 | do { | 66 | close I; |
| 71 | chomp ($_ = <STDIN>); | 67 | return if $username =~ /^\s*$/; |
| 72 | } while (! /^k/ && ! /^e/); | | |
| 73 | return unless /^k/; | | |
| 74 | } | 68 | } |
| 75 | else { | 69 | else { |
| | 70 | if ($_[0]) { |
| | 71 | print "\nKäyttäjätunnus ja/tai salasana saattaa olla väärä\n"; |
| | 72 | print "tai kyseessä on verkko-ongelma.\n"; |
| | 73 | print "Haluatko antaa uudet (k/e) ? "; |
| | 74 | do { |
| | 75 | chomp ($_ = <STDIN>); |
| | 76 | } while (! /^k/ && ! /^e/); |
| | 77 | return unless /^k/; |
| | 78 | } |
| | 79 | else { |
| 76 | print "\nKäyttäjätunnusta ja/tai salasanaa ei tiedossa...\n"; | 80 | print "\nKäyttäjätunnusta ja/tai salasanaa ei tiedossa...\n"; |
| 77 | } | 81 | } |
| 78 | print "\nKäyttäjätunnus: "; | 82 | print "\nKäyttäjätunnus: "; |
| 79 | chomp ($username = <STDIN>); | 83 | chomp ($username = <STDIN>); |
| 80 | print "Salasana: "; | 84 | print "Salasana: "; |
| 81 | system 'stty', '-echo'; | 85 | system 'stty', '-echo'; |
| 82 | chomp ($password = <STDIN>); | 86 | chomp ($password = <STDIN>); |
| 83 | print "\n"; | 87 | print "\n"; |
| 84 | system 'stty', 'echo'; | 88 | system 'stty', 'echo'; |
| 85 | | 89 | } |
| 86 | open O, '>', '2/tunnus' or die $!; | 90 | open O, '>', '2/tunnus' or die $!; |
| 87 | print O "tunnus = $username\nsalasana = $password\n"; | 91 | print O "tunnus = $username\nsalasana = $password\n"; |
| 88 | close O; | 92 | close O; |
| 263 | mkpw 1 if ($username eq '' or $password eq ''); | 267 | mkpw 1 if ($username eq '' or $password eq ''); |
| 264 | getdatetime; | 268 | getdatetime; |
| 265 | recwget "2/today/login-$time.html", 'http://www.tvkaista.fi/netpvr/Login', | 269 | recwget "2/today/login-$time.html", 'http://www.tvkaista.fi/netpvr/Login', |
| 266 | '--save-cookies', "cookies-$date-$time.txt", '--keep-session-cookies', | 270 | '--save-cookies', "2/cookies-$date-$time.txt", '--keep-session-cookies', |
| 267 | '--max-redirect=0', | 271 | '--max-redirect=0', |
| 268 | '--post-data', | 272 | '--post-data', |
| 269 | "action=login&username=$username&password=$password&rememberme=on"; | 273 | "action=login&username=$username&password=$password&rememberme=on"; |
| 270 | unlink 'cookies.txt'; | 274 | unlink '2/cookies.txt'; |
| 271 | symlink "cookies-$date-$time.txt", 'cookies.txt'; | 275 | symlink "cookies-$date-$time.txt", '2/cookies.txt'; |
| 272 | | 276 | |
| 273 | return -z "2/today/login-$time.html"; | 277 | return -z "2/today/login-$time.html"; |
| 274 | } | 278 | } |
| 294 | { | 298 | { |
| 295 | #http://www.tvkaista.fi/netpvr/Download/774338.srt | 299 | #http://www.tvkaista.fi/netpvr/Download/774338.srt |
| 296 | | 300 | |
| 297 | my $tof = "$_[0].srt"; | 301 | my $tof = "$recdir/$_[0].srt"; |
| 298 | | 302 | |
| 299 | recwget $tof, "http://www.tvkaista.fi/netpvr/Download/$_[0].srt", | 303 | recwget $tof, "http://www.tvkaista.fi/netpvr/Download/$_[0].srt", |
| 300 | '--load-cookies', '2/cookies.txt'; | 304 | '--load-cookies', '2/cookies.txt'; |
| 310 | close I; | 314 | close I; |
| 311 | if ($conlen > 0) { | 315 | if ($conlen > 0) { |
| 312 | $namepfx = 'tekstitys' if $_[1] ne 'wget'; | 316 | $namepfx = 'tekstitys' if $_[1] ne 'wget'; |
| 313 | rename $tof, "$namepfx.srt"; } | 317 | rename $tof, "$recdir/$namepfx.srt"; } |
| 314 | else { | 318 | else { |
| 315 | unlink $tof; } | 319 | unlink $tof; } |
| 316 | | 320 | |
| 321 | | 325 | |
| 322 | sub play ($) | 326 | sub play ($) |
| 323 | { | 327 | { |
| 324 | die "Play needs player, media id and format\n" unless defined $ARGV[4]; | 328 | die "Play needs player, media id and format\n" unless defined $ARGV[3]; |
| 325 | | 329 | |
| 326 | getpw; | 330 | getpw; |
| 327 | | 331 | |
| 328 | my $pagename = "2/today/play-$time.html"; | 332 | my $pagename = "2/today/play-$time.html"; |
| 329 | | 333 | |
| 330 | my $format = $speeds{$ARGV[4]}; | 334 | my $format = $speeds{$ARGV[3]}; |
| 331 | recwget $pagename, | 335 | recwget $pagename, |
| 332 | "http://www.tvkaista.fi/netpvr/VLC?id=$ARGV[3]&format=$format", | 336 | "http://www.tvkaista.fi/netpvr/VLC?id=$ARGV[2]&format=$format", |
| 333 | '--load-cookies', '2/cookies.txt'; | 337 | '--load-cookies', '2/cookies.txt'; |
| 334 | | 338 | |
| 335 | open I, '<', $pagename or die "Can not open '$pagename': $!\n"; | 339 | open I, '<', $pagename or die "Can not open '$pagename': $!\n"; |
| 343 | die "No content found!\n"; | 347 | die "No content found!\n"; |
| 344 | } | 348 | } |
| 345 | | 349 | |
| | 350 | my ($namepfx, $srtflen) = getsrt($ARGV[2], $ARGV[1]); |
| 346 | chdir $recdir; | 351 | chdir $recdir; |
| 347 | my ($namepfx, $srtflen) = getsrt($ARGV[3], $ARGV[2]); | | |
| 348 | | 352 | |
| 349 | my @list = ( $ARGV[2] ); | 353 | my @list = ( $ARGV[1] ); |
| 350 | if ($ARGV[2] eq 'wget') { | 354 | if ($ARGV[1] eq 'wget') { |
| 351 | push @list, '-O' , "$namepfx.$format"; | 355 | push @list, '-O' , "$namepfx.$format"; |
| 352 | } | 356 | } |
| 353 | elsif ($ARGV[2] eq 'vlc') { | 357 | elsif ($ARGV[1] eq 'vlc') { |
| 354 | push @list, '--sub-file', "$namepfx.srt" if $srtflen > 0; | 358 | push @list, '--sub-file', "$namepfx.srt" if $srtflen > 0; |
| 355 | } | 359 | } |
| 356 | elsif ($ARGV[2] eq 'mplayer') { | 360 | elsif ($ARGV[1] eq 'mplayer') { |
| 357 | push @list, '-ao', 'oss', '-utf8'; | 361 | push @list, '-ao', 'oss', '-utf8'; |
| 358 | push @list, '-sub', "$namepfx.srt" if $srtflen > 0; | 362 | push @list, '-sub', "$namepfx.srt" if $srtflen > 0; |
| 359 | } | 363 | } |
| 360 | elsif ($ARGV[2] eq 'xine') { | 364 | elsif ($ARGV[1] eq 'xine') { |
| 361 | # how to give subtitle file as separate command line parameter ? | 365 | # how to give subtitle file as separate command line parameter ? |
| 362 | } | 366 | } |
| 363 | | 367 | |
| 366 | system @list or warn "system(): $!\n"; | 370 | system @list or warn "system(): $!\n"; |
| 367 | print "Executed @list\n"; | 371 | print "Executed @list\n"; |
| 368 | | 372 | |
| 369 | unlink "$namepfx.srt" if $srtflen > 0 && $ARGV[2] ne 'wget'; | 373 | unlink "$namepfx.srt" if $srtflen > 0 && $ARGV[1] ne 'wget'; |
| 370 | | 374 | |
| 371 | # add more checks & cleanups | 375 | # add more checks & cleanups |
| 372 | exit 0; | 376 | exit 0; |
| 373 | } | 377 | } |
| 374 | | 378 | |
| 375 | if ($ARGV[1] eq 'play') | 379 | if ($ARGV[0] eq 'play') |
| 376 | { | 380 | { |
| 377 | login, play 1 unless play 0; | 381 | login, play 1 unless play 0; |
| 378 | exit 1; | 382 | exit 1; |
| 379 | } | 383 | } |
| 380 | | 384 | |
| 381 | if ($ARGV[1] eq 'update') | 385 | if ($ARGV[0] eq 'update') |
| 382 | { | 386 | { |
| 383 | my $minfile; | 387 | my $minfile; |
| 384 | getpw; | 388 | getpw; |
| 396 | pop @logdirs foreach (1..2); | 400 | pop @logdirs foreach (1..2); |
| 397 | system '/bin/rm', '-rf', @logdirs if defined (pop @logdirs); | 401 | system '/bin/rm', '-rf', @logdirs if defined (pop @logdirs); |
| 398 | } | 402 | } |
| 399 | elsif ($ARGV[1] ne 'list') | 403 | elsif ($ARGV[0] ne 'list') |
| 400 | { | 404 | { |
| 401 | usage; | 405 | usage; |
| 402 | } | 406 | } |
| tvkaista-0.962/tvkaista_gtkui.c | | tvkaista-0.964/tvkaista_gtkui.c |
| 40 | #include <sys/stat.h> | 40 | #include <sys/stat.h> |
| 41 | #include <fcntl.h> | 41 | #include <fcntl.h> |
| 42 | | 42 | |
| 43 | #include <signal.h> | | |
| 44 | #include <errno.h> | 43 | #include <errno.h> |
| 45 | | 44 | |
| 46 | #define null ((void*)0) | 45 | #define null ((void*)0) |
| 137 | G.prgfd[i] = -1; | 136 | G.prgfd[i] = -1; |
| 138 | } | 137 | } |
| 139 | | 138 | |
| 140 | FILE * runhelper(bool xterm, const char * format, ...) | 139 | FILE * runhelper(const char * format, ...) |
| 141 | { | 140 | { |
| 142 | char cmdline[512]; | 141 | char cmdline[512]; |
| 143 | va_list ap; | 142 | va_list ap; |
| 144 | int l; | 143 | int l; |
| 145 | | 144 | |
| 146 | sprintf(cmdline, xterm ? | 145 | sprintf(cmdline, "exec \"%s\" gui ", G_helper); |
| 147 | /* */ "exec 8>&1; exec xterm -hold -fa '' -fs 10 -e \"%s\" 8 " : | | |
| 148 | /* */ "exec \"%s\" 1 ", G_helper); | | |
| 149 | l = strlen(cmdline); | 146 | l = strlen(cmdline); |
| 150 | if (l > 500) | 147 | if (l > 500) |
| 151 | return null; | 148 | return null; |
| 446 | | 443 | |
| 447 | model = create_model(); | 444 | model = create_model(); |
| 448 | | 445 | |
| 449 | FILE * fh = runhelper(0, "list"); | 446 | FILE * fh = runhelper("list"); |
| 450 | if (fh == null) | 447 | if (fh == null) |
| 451 | die("Can not run helper to get program list: $!\n"); | 448 | die("Can not run helper to get program list: $!\n"); |
| 452 | fill_store(fh); | 449 | fill_store(fh); |
| 685 | | 682 | |
| 686 | bool reset_signal(void * inprogress_p) | 683 | bool reset_signal(void * inprogress_p) |
| 687 | { | 684 | { |
| 688 | signal(SIGTERM, SIG_DFL); | | |
| 689 | *(int*)inprogress_p = false; | 685 | *(int*)inprogress_p = false; |
| 690 | return false; | 686 | return false; |
| 691 | } | 687 | } |
| 698 | if (inprogress) | 694 | if (inprogress) |
| 699 | return; | 695 | return; |
| 700 | | 696 | |
| 701 | FILE * fh = runhelper(1, "update"); | 697 | FILE * fh = runhelper("update"); |
| 702 | clean_data(); | 698 | clean_data(); |
| 703 | if (fill_store(fh)) { | 699 | if (fill_store(fh)) { |
| 704 | sleep(1); | | |
| 705 | signal(SIGTERM, SIG_IGN); | | |
| 706 | kill(0, SIGTERM); | | |
| 707 | inprogress = true; | 700 | inprogress = true; |
| 708 | g_idle_add(reset_signal, &inprogress); | 701 | g_idle_add(reset_signal, &inprogress); |
| 709 | } | 702 | } |
| 729 | int i = G.previndx / 1000; | 722 | int i = G.previndx / 1000; |
| 730 | int j = G.previndx % 1000; | 723 | int j = G.previndx % 1000; |
| 731 | | 724 | |
| 732 | runhelper(1, "play %s %d %s", tool, G.prgbuffers[i][j].id, speeds[speed]); | 725 | runhelper("play %s %d %s", tool, G.prgbuffers[i][j].id, speeds[speed]); |
| 733 | } | 726 | } |
| 734 | | 727 | |
| 735 | void play_pressed(void * uu) | 728 | void play_pressed(void * uu) |
| 787 | 2, true, true, | 780 | 2, true, true, |
| 788 | aVBox(/* <- homogeneous spacing */ false, 2, | 781 | aVBox(/* <- homogeneous spacing */ false, 2, |
| 789 | aHBox(/* <- homogeneous spacing */ false, 2, | 782 | aHBox(/* <- homogeneous spacing */ false, 2, |
| 790 | aButton("Päivitä", update_pressed, null), | 783 | aButton("päivitä", update_pressed, null), |
| 791 | /* ^^ expand fill padding */ false, true, 2, | 784 | /* ^^ expand fill padding */ false, true, 2, |
| 792 | aButton("Katso", play_pressed, null), | 785 | aButton("katso", play_pressed, null), |
| 793 | /* ^^ expand fill padding */ false, true, 2, | 786 | /* ^^ expand fill padding */ false, true, 2, |
| 794 | aButton("Tallenna", save_pressed, null), | 787 | aButton("tallenna", save_pressed, null), |
| 795 | /* ^^ expand fill padding */ false, true, 2, | 788 | /* ^^ expand fill padding */ false, true, 2, |
| 796 | W.scb = aTextComboBox(speeds, nspeeds, 2), | 789 | W.scb = aTextComboBox(speeds, nspeeds, 2), |
| 797 | /* ^^ expand fill padding */ false, true, 2, | 790 | /* ^^ expand fill padding */ false, true, 2, |
| 834 | // gtk_widget_show_all(W.w); | 827 | // gtk_widget_show_all(W.w); |
| 835 | } | 828 | } |
| 836 | | 829 | |
| | 830 | const char intro[] = "\n" |
| | 831 | "KORJAA: tarkenna tätä tekstiä...\n" |
| | 832 | "\n" |
| | 833 | "Tähän ilmestyy logia tvkaista-ohjelman ajamista komennoista ja\n" |
| | 834 | "niiden tulostuksesta. Tästä voi seurata kun ongemia ilmenee.\n" |
| | 835 | "\n" |
| | 836 | "Ctrl-C tässä lopettaa tvkaista-ohjelman ja mahdollisesti suoritettavan\n" |
| | 837 | "tallennuksen/tv-ohjelman seurannan. Myöhemmin toimii ehkä paremmin.\n" |
| | 838 | "\n" |
| | 839 | "Sitä ennen ehkä kuitenkin selausominaisuudet...\n" |
| | 840 | "\n" |
| | 841 | "Tallenteiden sijaintipaikka on $HOME/.tvkaista/tallenteet/.\n" |
| | 842 | "\n"; |
| 837 | | 843 | |
| 838 | int main(int argc, char *argv[]) | 844 | int main(int argc, char *argv[]) |
| 839 | { | 845 | { |
| 841 | init_G(); | 847 | init_G(); |
| 842 | gtk_init(&argc, &argv); | 848 | gtk_init(&argc, &argv); |
| 843 | setenv("PERL_UNICODE", "SD", 1); | 849 | setenv("PERL_UNICODE", "SD", 1); |
| | 850 | write(1, intro, sizeof intro - 1); |
| 844 | gui(); | 851 | gui(); |
| 845 | gtk_main(); | 852 | gtk_main(); |
| 846 | return 0; | 853 | return 0; |