Guest User

Untitled

a guest
Feb 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. : # *-*-perl-*-*
  2. eval 'exec perl -w -S $0 ${1+"$@"}'
  3. if 0; # if running under some shell
  4.  
  5. ## TODO
  6. ## open STDERR so it doesn't barf mplayer crap to the console
  7.  
  8. use Data::Dumper;
  9. #use POSIX ":sys_wait_h";
  10.  
  11. $rootdir = '~/Videos';
  12.  
  13. sub find_next {
  14. my %movie = {};
  15. @movies = `find $rootdir -type f`;
  16. $movie = 0;
  17. while(!$movie){
  18. $movie = $movies[int(rand(@movies))];
  19.  
  20. chomp $movie;
  21. @identify_info = `mplayer -vo null -nosound -frames 0 -identify '$movie'`;
  22.  
  23.  
  24. @id_length = grep /ID_LENGTH/, @identify_info;
  25. if(@id_length && $id_length[0] =~ /ID_LENGTH=(\d+)/){
  26. printf("MOVIE WITH LENGTH FOUND! $movie is $1s long\n");
  27. $movie{'filename'} = $movie;
  28. #$movie{'length'} = int($1);
  29. $movie{'endpos'} = rand(20)+rand(20)+20;
  30. $movie{'ss'} = rand($1-$movie{'endpos'});
  31. }else{
  32. $movie = 0;
  33. }
  34. }
  35. return %movie;
  36. }
  37.  
  38. while(true){
  39. %next = find_next;
  40.  
  41. print Dumper(%next);
  42.  
  43. do {
  44. $kid = waitpid -1, WNOHANG;
  45. }while ($kid > 0);
  46.  
  47. if($pid = fork){
  48.  
  49. }else{
  50. `mplayer -nosound -fs -ss $next{'ss'} -endpos $next{'endpos'} "$next{'filename'}"`;
  51. exit;
  52. }
  53. }
Add Comment
Please, Sign In to add comment