diff options
author | psyc://loupsycedyglgamf.onion/~lynX <ircs://psyced.org/youbroketheinternet> | 2016-08-10 15:28:53 +0000 |
---|---|---|
committer | psyc://loupsycedyglgamf.onion/~lynX <ircs://psyced.org/youbroketheinternet> | 2016-08-10 15:28:53 +0000 |
commit | 684e58a63ea4e88d37d4869f6fe87aea7c7f219e (patch) | |
tree | 40ae144aa02a84185ea7fc7c5200d576e1822e1d | |
parent | 8fb2f089b39048d2f742a8558552a3e994410773 (diff) | |
download | perlpsyc-684e58a63ea4e88d37d4869f6fe87aea7c7f219e.tar.gz perlpsyc-684e58a63ea4e88d37d4869f6fe87aea7c7f219e.zip |
introducing a sleeping timer into psycamp
-rwxr-xr-x | bin/psycamp | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/bin/psycamp b/bin/psycamp index 6508d1d..5e64423 100755 --- a/bin/psycamp +++ b/bin/psycamp | |||
@@ -155,7 +155,7 @@ my $screen = 0; | |||
155 | 155 | ||
156 | MAIN: { | 156 | MAIN: { |
157 | if ($#ARGV >= 0) { | 157 | if ($#ARGV >= 0) { |
158 | getopt('AbMnsS'); | 158 | getopt('AbMnsSt'); |
159 | } | 159 | } |
160 | $nick = $opt_n | 160 | $nick = $opt_n |
161 | || $ENV{'PSYCNICK'} | 161 | || $ENV{'PSYCNICK'} |
@@ -278,6 +278,12 @@ X | |||
278 | add( \*STDIN, 'r', \&stdread ); | 278 | add( \*STDIN, 'r', \&stdread ); |
279 | &ginstart; | 279 | &ginstart; |
280 | 280 | ||
281 | if ($opt_t = 60 * int($opt_t)) { | ||
282 | print BOLD, BLUE, <<X, RESET; | ||
283 | Scheduling termination after $opt_t seconds. | ||
284 | X | ||
285 | add($opt_t, 't', \&scheduledQuit); | ||
286 | } | ||
281 | print STDERR $ENV{PWD} . " = PWD\n" if DEBUG & 1; | 287 | print STDERR $ENV{PWD} . " = PWD\n" if DEBUG & 1; |
282 | if ($opt_d) { | 288 | if ($opt_d) { |
283 | print STDERR BOLD, RED, ($Volatile = $ENV{PWD} | 289 | print STDERR BOLD, RED, ($Volatile = $ENV{PWD} |
@@ -313,7 +319,7 @@ X | |||
313 | $|=1; | 319 | $|=1; |
314 | 320 | ||
315 | # Net::PSYC::Event doesn't support idle events yet.. TODO | 321 | # Net::PSYC::Event doesn't support idle events yet.. TODO |
316 | add(3, 'i', \&timeout, 1); | 322 | add(7, 'i', \&timeout, 1); |
317 | # higher frequency necessary to detect timeouts this way.. | 323 | # higher frequency necessary to detect timeouts this way.. |
318 | # then again, if it's too high timer is sometimes faster | 324 | # then again, if it's too high timer is sometimes faster |
319 | # than rxaudio and produces an erroneous kick.. | 325 | # than rxaudio and produces an erroneous kick.. |
@@ -350,9 +356,9 @@ sub timeout { | |||
350 | # # so far timeout only happens when the input file is b0rked, so we skip it | 356 | # # so far timeout only happens when the input file is b0rked, so we skip it |
351 | # &next(0); | 357 | # &next(0); |
352 | # it also happens when the file is being delivered via network | 358 | # it also happens when the file is being delivered via network |
353 | # print MAGENTA, "\n*** Track not ready for playback. Retrying from start.\n"; | 359 | print MAGENTA, "\n*** Track not ready for playback. Retrying from start.", RESET; |
354 | # &gin( "seek 0 1" ); | 360 | &gin( "seek 0 1" ); |
355 | print MAGENTA, "\n*** Track not ready for playback. Waiting... \r"; | 361 | # print MAGENTA, "\n*** Track not ready for playback. Waiting...", RESET, "\r"; |
356 | #} X | 362 | #} X |
357 | } | 363 | } |
358 | return 3; | 364 | return 3; |
@@ -423,7 +429,7 @@ sub ginread { | |||
423 | print BOLD, GREEN, "\r [\n", RESET unless $opt_q; | 429 | print BOLD, GREEN, "\r [\n", RESET unless $opt_q; |
424 | } | 430 | } |
425 | &ginstop if $opt_I; | 431 | &ginstop if $opt_I; |
426 | if ($quitLater) { &save($CS-1), &exit(0); } | 432 | if ($quitLater) { &save($CS), &exit(0); } |
427 | &next(0); | 433 | &next(0); |
428 | } | 434 | } |
429 | } | 435 | } |
@@ -433,7 +439,7 @@ sub stdread { | |||
433 | $_ = scalar <STDIN>; | 439 | $_ = scalar <STDIN>; |
434 | # should be in timeout instead | 440 | # should be in timeout instead |
435 | if (waitpid(-1, WNOHANG)) { | 441 | if (waitpid(-1, WNOHANG)) { |
436 | print BOLD, RED, "\r>>> Media engine has terminated.", RESET, "\n"; | 442 | &say(BOLD, RED, ">>> Media engine has terminated", RESET); |
437 | exit; | 443 | exit; |
438 | } | 444 | } |
439 | &parse( $_ ); | 445 | &parse( $_ ); |
@@ -477,13 +483,13 @@ sub open { | |||
477 | if ($file =~ /\.sdj$/i and -T $file) { | 483 | if ($file =~ /\.sdj$/i and -T $file) { |
478 | # calling a script from a script is like a "skip".. | 484 | # calling a script from a script is like a "skip".. |
479 | $SCRIPT = $file; | 485 | $SCRIPT = $file; |
480 | print "[executing script $SCRIPT]\n" unless $opt_q; | 486 | &say("[executing script $SCRIPT]") unless $opt_q; |
481 | open(F, $file) || die "$file: $!"; | 487 | open(F, $file) || die "$file: $!"; |
482 | while(<F>) { | 488 | while(<F>) { |
483 | &parse($_); | 489 | &parse($_); |
484 | } | 490 | } |
485 | close F; | 491 | close F; |
486 | print "[script terminated]\n" unless $opt_q; | 492 | &say("[script terminated]") unless $opt_q; |
487 | undef $SCRIPT; | 493 | undef $SCRIPT; |
488 | &next(0); # hmmmm? | 494 | &next(0); # hmmmm? |
489 | } elsif (! -r $file) { | 495 | } elsif (! -r $file) { |
@@ -607,14 +613,14 @@ X | |||
607 | if ( /^(_|DD)\s*$/ ) { | 613 | if ( /^(_|DD)\s*$/ ) { |
608 | $moveLater = undef; | 614 | $moveLater = undef; |
609 | $deleteLater = $CurrentFile; | 615 | $deleteLater = $CurrentFile; |
610 | print BOLD, BLUE, ">> scheduled for removal\n", RESET; | 616 | &say(BOLD, BLUE, ">> scheduled for removal", RESET); |
611 | next; | 617 | next; |
612 | } | 618 | } |
613 | if ( /^D\s*$/ ) { | 619 | if ( /^D\s*$/ ) { |
614 | my $f = $CurrentFile; | 620 | my $f = $CurrentFile; |
615 | &ginclose; | 621 | &ginclose; |
616 | &trash; | 622 | &trash; |
617 | print BOLD, RED, ">> deleted: $f\n", RESET if unlink $f; | 623 | &say(BOLD, RED, ">> deleted: $f", RESET) if unlink $f; |
618 | &ginopen; | 624 | &ginopen; |
619 | &next(0); | 625 | &next(0); |
620 | next; | 626 | next; |
@@ -623,7 +629,7 @@ X | |||
623 | if ( /^(J|U|K|E|M|V|X|C|F|L|W|S|R|Y)(\w?)\s*$/ ) { | 629 | if ( /^(J|U|K|E|M|V|X|C|F|L|W|S|R|Y)(\w?)\s*$/ ) { |
624 | my $r = $2; | 630 | my $r = $2; |
625 | if ($r and $r ne $1) { | 631 | if ($r and $r ne $1) { |
626 | print BOLD, RED, ">> command $1$r not defined\n", RESET; | 632 | &say(BOLD, RED, ">> command $1$r not defined", RESET); |
627 | next; | 633 | next; |
628 | } | 634 | } |
629 | $trashLater = $deleteLater = undef; | 635 | $trashLater = $deleteLater = undef; |
@@ -646,17 +652,18 @@ X | |||
646 | # the initial (.*) is a hack to make the regexp match the last occurance in the path string rather than earlier ones | 652 | # the initial (.*) is a hack to make the regexp match the last occurance in the path string rather than earlier ones |
647 | unless ($f =~ s:^(.*)/(SHARE|T|COMPLETE|KEEP|EDITABLE|FAVES|WRONG|SECONDARY|REPERTOIRE|NEW|TODO|USE|DEEJAY|REMASTER|CRITICIZE|EASY|INCOMING|incomingDJ|EXPORT|VOLATILE|L8R|CHAOS|DJ|byArtist|byGenre|vol)\d?/:\1/$t/:i) | 653 | unless ($f =~ s:^(.*)/(SHARE|T|COMPLETE|KEEP|EDITABLE|FAVES|WRONG|SECONDARY|REPERTOIRE|NEW|TODO|USE|DEEJAY|REMASTER|CRITICIZE|EASY|INCOMING|incomingDJ|EXPORT|VOLATILE|L8R|CHAOS|DJ|byArtist|byGenre|vol)\d?/:\1/$t/:i) |
648 | { | 654 | { |
649 | print BOLD, RED, ">> not applicable for $f\n", RESET; | 655 | &say(BOLD, RED, ">> not applicable for $f", RESET); |
650 | next; | 656 | next; |
651 | } | 657 | } |
652 | if ($f eq $f2) { | 658 | if ($f eq $f2) { |
653 | print BOLD, BLUE, ">> no longer scheduled to go to $moveLater\n", RESET if $moveLater; | 659 | &say(BOLD, BLUE, ">> no longer scheduled to go to $moveLater", RESET) |
660 | if $moveLater; | ||
654 | $moveLater = undef; | 661 | $moveLater = undef; |
655 | next; | 662 | next; |
656 | } | 663 | } |
657 | if ($r) { | 664 | if ($r) { |
658 | $moveLater = $f; | 665 | $moveLater = $f; |
659 | print BOLD, BLUE, ">> scheduled to move to $t\n", RESET; | 666 | &say(BOLD, BLUE, ">> scheduled to move to $t", RESET); |
660 | } else { | 667 | } else { |
661 | &moveFile($f); | 668 | &moveFile($f); |
662 | &next(0); | 669 | &next(0); |
@@ -664,9 +671,10 @@ X | |||
664 | next; | 671 | next; |
665 | } | 672 | } |
666 | if ( /^\.\s*$/ ) { | 673 | if ( /^\.\s*$/ ) { |
667 | print BOLD, BLUE, ">> no longer scheduled to go to $moveLater\n", RESET if $moveLater; | 674 | &say(BOLD, BLUE, ">> no longer scheduled to go to $moveLater", RESET) if $moveLater; |
668 | print BOLD, BLUE, ">> no longer scheduled for removal\n", RESET if $deleteLater; | 675 | &say(BOLD, BLUE, ">> no longer scheduled for removal", RESET) if $deleteLater; |
669 | $trashLater = $moveLater = $deleteLater = undef; | 676 | &say(BOLD, BLUE, ">> no longer scheduled to quit", RESET) if $quitLater; |
677 | $quitLater = $trashLater = $moveLater = $deleteLater = undef; | ||
670 | next; | 678 | next; |
671 | } | 679 | } |
672 | #} O | 680 | #} O |
@@ -710,10 +718,7 @@ X | |||
710 | # &gin("seek $1 $2"); | 718 | # &gin("seek $1 $2"); |
711 | # } | 719 | # } |
712 | 720 | ||
713 | if (/^q(q|quit)\b/ or /QQ?/) { | 721 | &scheduledQuit, next if /^q(q|quit)\b/ or /QQ?/; |
714 | print BOLD, GREEN, ">> scheduled to quit after this track\n", RESET; | ||
715 | $quitLater++, next; | ||
716 | } | ||
717 | /^(q|quit)\b/ and &save($CS-1), &exit(0); | 722 | /^(q|quit)\b/ and &save($CS-1), &exit(0); |
718 | /^(x|exit)\b/ and &exit(0); | 723 | /^(x|exit)\b/ and &exit(0); |
719 | /^(w|write)\b/ and &save($CS-1), next; | 724 | /^(w|write)\b/ and &save($CS-1), next; |
@@ -735,6 +740,11 @@ X | |||
735 | &gin($_) if $_; | 740 | &gin($_) if $_; |
736 | } | 741 | } |
737 | 742 | ||
743 | sub scheduledQuit { | ||
744 | &say(BOLD, BLUE, ">> scheduled to quit after this track", RESET); | ||
745 | $quitLater++; | ||
746 | } | ||
747 | |||
738 | sub moveFile { | 748 | sub moveFile { |
739 | my $f = shift; | 749 | my $f = shift; |
740 | my $d = $f; | 750 | my $d = $f; |
@@ -745,15 +755,15 @@ sub moveFile { | |||
745 | # return; | 755 | # return; |
746 | # } | 756 | # } |
747 | unless (rename ($CurrentFile, $f)) { | 757 | unless (rename ($CurrentFile, $f)) { |
748 | print BOLD, RED, ">> could not move file to $d\n", RESET; | 758 | &say(BOLD, RED, ">> could not move file to $d", RESET); |
749 | return; | 759 | return; |
750 | } | 760 | } |
751 | my $asd = $CurrentFile .".asd"; | 761 | my $asd = $CurrentFile .".asd"; |
752 | if (-s $asd and not rename ($asd, $f .".asd")) { | 762 | if (-s $asd and not rename ($asd, $f .".asd")) { |
753 | print BOLD, RED, ">> could not move asd file to $d\n", RESET; | 763 | &say(BOLD, RED, ">> could not move asd file to $d", RESET); |
754 | return; | 764 | return; |
755 | } | 765 | } |
756 | print BOLD, BLUE, ">> moved to $f\n", RESET; | 766 | &say(BOLD, BLUE, ">> moved to $f", RESET); |
757 | } | 767 | } |
758 | 768 | ||
759 | sub sleep { | 769 | sub sleep { |
@@ -766,7 +776,7 @@ sub sleep { | |||
766 | else { | 776 | else { |
767 | $t = 0.1; | 777 | $t = 0.1; |
768 | } | 778 | } |
769 | print "[sleeping $t secs]\n" unless $opt_q or $t < 1; | 779 | &say("[sleeping $t secs]") unless $opt_q or $t < 1; |
770 | select (undef,undef,undef,$t); | 780 | select (undef,undef,undef,$t); |
771 | return $t; | 781 | return $t; |
772 | } | 782 | } |
@@ -857,14 +867,14 @@ sub duration { | |||
857 | $t = $1 ? $1*60+$3 : $3; | 867 | $t = $1 ? $1*60+$3 : $3; |
858 | } | 868 | } |
859 | $DUR = $t; | 869 | $DUR = $t; |
860 | print YELLOW, "[duration is $t secs]\n", RESET unless $opt_q; | 870 | &say(YELLOW, "[duration is $t secs]", RESET) unless $opt_q; |
861 | return 1; | 871 | return 1; |
862 | } | 872 | } |
863 | 873 | ||
864 | sub jump { | 874 | sub jump { |
865 | my $t = shift; | 875 | my $t = shift; |
866 | unless ($DUR) { | 876 | unless ($DUR) { |
867 | print STDERR "[you must specify the song duration first]\n"; | 877 | &say("[you must specify the song duration first]"); |
868 | return 1; | 878 | return 1; |
869 | } | 879 | } |
870 | if ( $t =~ /(\d*)(:|')(\S*)/ ) { | 880 | if ( $t =~ /(\d*)(:|')(\S*)/ ) { |
@@ -1056,6 +1066,12 @@ sub stringtail { | |||
1056 | my $w = shift || $TWIDTH; | 1066 | my $w = shift || $TWIDTH; |
1057 | return length($s)>=$w ? "...".substr($s,-$w+4) : $s; | 1067 | return length($s)>=$w ? "...".substr($s,-$w+4) : $s; |
1058 | } | 1068 | } |
1069 | sub say { | ||
1070 | my $tx = join('', @_); | ||
1071 | # this counts more space for color codes than visible on screen FIXME | ||
1072 | my $len = length $tx; | ||
1073 | print "\r", $tx, ' ' x ($TWIDTH-1-$len), "\n"; | ||
1074 | } | ||
1059 | 1075 | ||
1060 | sub ginxpect { | 1076 | sub ginxpect { |
1061 | local($match) = @_; | 1077 | local($match) = @_; |
@@ -1321,7 +1337,7 @@ sub trash { | |||
1321 | printf HATE "%10d %5s %3s\t%s\r\n", | 1337 | printf HATE "%10d %5s %3s\t%s\r\n", |
1322 | $CurrentSize, $I{duration}, $I{bitrate}, $CurrentFile; | 1338 | $CurrentSize, $I{duration}, $I{bitrate}, $CurrentFile; |
1323 | close HATE; | 1339 | close HATE; |
1324 | print RED, ">> marked as trash\n", RESET; | 1340 | &say(RED, ">> marked as trash", RESET); |
1325 | } else { | 1341 | } else { |
1326 | print BOLD, RED, "*** Failed to write to ", HATEINDEX, ":\n", RESET, $out; | 1342 | print BOLD, RED, "*** Failed to write to ", HATEINDEX, ":\n", RESET, $out; |
1327 | } | 1343 | } |
@@ -1479,7 +1495,8 @@ __END__ | |||
1479 | =head1 SYNOPSIS | 1495 | =head1 SYNOPSIS |
1480 | 1496 | ||
1481 | psycamp [<flags>] [-b <uniform>] [-n <nick>] [-s <sort-algorithm>] | 1497 | psycamp [<flags>] [-b <uniform>] [-n <nick>] [-s <sort-algorithm>] |
1482 | [-M <UNI>] [-S <screen>] [-A <text>] [<media-files|directories>] | 1498 | [-M <UNI>] [-S <screen>] [-A <text>] [-t <minutes>] |
1499 | [<media-files|directories>] | ||
1483 | 1500 | ||
1484 | [-A]nnounce a message between each track using 'espeak' | 1501 | [-A]nnounce a message between each track using 'espeak' |
1485 | [-b]ind PSYC uniform and accept commands from both PSYC and stdin | 1502 | [-b]ind PSYC uniform and accept commands from both PSYC and stdin |
@@ -1487,6 +1504,7 @@ __END__ | |||
1487 | [-n]ickname to use for monitoring, otherwise a default will be used | 1504 | [-n]ickname to use for monitoring, otherwise a default will be used |
1488 | [-s]ort playlist according to one of the algorithms explained below | 1505 | [-s]ort playlist according to one of the algorithms explained below |
1489 | [-S]creen number to display videos on (default: 0) | 1506 | [-S]creen number to display videos on (default: 0) |
1507 | [-t]imer in minutes, when to schedule a quit after start | ||
1490 | 1508 | ||
1491 | Flags: | 1509 | Flags: |
1492 | [-H] shows an explanation what this tool is good for, try it! | 1510 | [-H] shows an explanation what this tool is good for, try it! |