Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- : # *-*-perl-*-*
- eval 'exec perl -w -S $0 ${1+"$@"}'
- if 0; # if running under some shell
- ## TODO
- ## open STDERR so it doesn't barf mplayer crap to the console
- use Data::Dumper;
- #use POSIX ":sys_wait_h";
- $rootdir = '~/Videos';
- sub find_next {
- my %movie = {};
- @movies = `find $rootdir -type f`;
- $movie = 0;
- while(!$movie){
- $movie = $movies[int(rand(@movies))];
- chomp $movie;
- @identify_info = `mplayer -vo null -nosound -frames 0 -identify '$movie'`;
- @id_length = grep /ID_LENGTH/, @identify_info;
- if(@id_length && $id_length[0] =~ /ID_LENGTH=(\d+)/){
- printf("MOVIE WITH LENGTH FOUND! $movie is $1s long\n");
- $movie{'filename'} = $movie;
- #$movie{'length'} = int($1);
- $movie{'endpos'} = rand(20)+rand(20)+20;
- $movie{'ss'} = rand($1-$movie{'endpos'});
- }else{
- $movie = 0;
- }
- }
- return %movie;
- }
- while(true){
- %next = find_next;
- print Dumper(%next);
- do {
- $kid = waitpid -1, WNOHANG;
- }while ($kid > 0);
- if($pid = fork){
- }else{
- `mplayer -nosound -fs -ss $next{'ss'} -endpos $next{'endpos'} "$next{'filename'}"`;
- exit;
- }
- }
Add Comment
Please, Sign In to add comment