dotfiles

My dotfiles, nothing really interesting to see ...
git clone https://git.onna.be/dotfiles.git
Log | Files | Refs | README

rarbg.pl (2669B)


      1 #!/usr/bin/env perl
      2 
      3 use v5.24;
      4 use strict;
      5 use warnings;
      6 use lib "$ENV{HOME}/src/perl5/lib/perl5";
      7 use Rarbg::torrentapi;
      8 use Getopt::Long;
      9 no warnings 'experimental';
     10 
     11 sub usage {
     12     say
     13       "Usage: $0 [--list] [--search <string>] [--categories <movies|tv>] [--limit <n>]";
     14     say "\t--list\t\t\tlists last added torrents sorted by seeds.";
     15     say
     16       "\t--search <string>\tsearches for <string> and returns sorted by seeds";
     17     say
     18       "\t--category [movies|tv|music|xxxx]\tuses those categories (defaults to movies)";
     19     say "\t--limit [25|50|100]\tShows 'n' results (defaults to 25)";
     20     exit 1;
     21 }
     22 
     23 my $tapi    = Rarbg::torrentapi->new();
     24 my $counter = 0;
     25 my $search  = "";
     26 my $list;
     27 my $result;
     28 my $raw_category = '';
     29 my $category;
     30 my $limit = 25;
     31 
     32 GetOptions(
     33     "search=s"   => \$search,
     34     "list"       => \$list,
     35     "category=s" => \$raw_category,
     36     "limit=i"    => \$limit
     37 ) or usage();
     38 
     39 given ($raw_category) {
     40     when ( $_ eq 'movies' or $_ eq 'tv' ) {
     41         $category = $raw_category;
     42     }
     43     when ( $_ eq 'music' ) {
     44         $category = '2;23;24;25;26';
     45     }
     46     when ( $_ eq 'xxx' ) {
     47         $category = '2;4';
     48     }
     49     default {
     50         $category = 'movies';
     51         $raw_category = 'movies';
     52     }
     53 }
     54 
     55 if ($search) {
     56     $result = $tapi->search(
     57         {   sort          => 'seeders',
     58             limit         => $limit,
     59             category      => $category,
     60             search_string => $search
     61         }
     62     );
     63 }
     64 elsif ($list) {
     65     $result = $tapi->list(
     66         {   sort     => 'seeders',
     67             limit    => $limit,
     68             category => $category
     69         }
     70     );
     71 }
     72 else {
     73     usage();
     74 }
     75 
     76 if ( ref($result) eq 'ARRAY' ) {
     77     foreach my $t ( @{$result} ) {
     78         printf(
     79             "%d -> %s (%.2f GB # %d seeds)\n",
     80             $counter, $t->title, $t->size / 1073741824,
     81             $t->seeders
     82         );
     83         $counter++;
     84     }
     85 }
     86 elsif ( ref($result) eq 'Rarbg::torrentapi::Error' ) {
     87     die "[*] We got an error: $result->{error}";
     88 }
     89 else {
     90     die "[*] Unexpected Error";
     91 }
     92 
     93 print "Which one? (Ctrl+C to quit) ";
     94 my $selection = <STDIN>;
     95 chomp $selection;
     96 
     97 if ( $selection =~ m/\d{1,2} ?/ ) {
     98     my @selections = split( / /, $selection );
     99     foreach my $s (@selections) {
    100         say "[*] You selected: " . $result->[$s]->title;
    101         say "  [-] sending magnet to transmission:\n"
    102           . $result->[$s]->download;
    103         my $magnet = $result->[$s]->download;
    104         say "  [-] will use tag $raw_category";
    105         `transmission-remote pippin.h.e1e0.net --authenv -a "$magnet" -w /var/lib/transmission-daemon/downloads/$raw_category`;
    106     }
    107 }
    108 else {
    109     die "selection is not a number!";
    110 }