HighInBC

VLC sorter

Jun 13th, 2022 (edited)
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.18 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use IO::Socket::UNIX;
  4. use IO::Select;
  5. use URI::Encode;
  6.  
  7. $|++;
  8.  
  9. my $encoder = URI::Encode->new({encode_reserved => 0});
  10.  
  11. my $client = IO::Socket::UNIX->new(
  12.   Type => SOCK_STREAM(),
  13.   Peer => "$ENV{HOME}/vlc.sock",
  14. ) || die $@;
  15.    
  16. my $s = IO::Select->new();
  17. $s->add(\*STDIN);
  18. $s->add($client);
  19.  
  20. my $target = ''; # target path here
  21.  
  22. my $target_file;
  23. while( my @sock = $s->can_read() ) {
  24.   my $sock = $sock[0];
  25.   if( $sock == $client ) {
  26.     $sock->flush();
  27.     my $line = $sock->getline();
  28.     print $sock ("\n");
  29.  
  30.     next unless( $line =~ m/(file.*?)\s/ );
  31.     my $uri = $1;
  32.     my $path = $encoder->decode( $uri );
  33.     $path =~ s|file://||;
  34.     $target_file = $path;
  35.  
  36.     print "\nCurrently working on: $target_file\n:";
  37.   } else {
  38.     my $command = $sock->getline();
  39.     chomp $command;
  40.  
  41.     next unless( $command );
  42.  
  43.     print "\nGot from keyboard: $command\n";
  44.     print "\tTarget: $target_file\n";
  45.    
  46.     my $target_path = "$target$command/";
  47.    
  48.     system( 'mkdir', '-p', $target_path ) unless( -d $target_path );
  49.     system( 'mv', $target_file, $target_path );
  50.  
  51.     print "\tMoved to: $target_path\n\n";
  52.   }
  53. }
  54.  
Add Comment
Please, Sign In to add comment