Browse Source

add the option to configure the priorities

themage
theMage 5 years ago
parent
commit
faafa4ee6b
3 changed files with 73 additions and 5 deletions
  1. 8 0
      cinepantufas.cfg
  2. 62 0
      lib/CinePantufas/Priority.pm
  3. 3 5
      lib/CinePantufas/Source/EZTV.pm

+ 8 - 0
cinepantufas.cfg

@ -8,3 +8,11 @@ api_url = http://127.0.0.1:9091/transmission/rpc/
8 8
[move]
9 9
basedir = ~/media/tvshows
10 10
11
[priorities]
12
HDTV  = 1
13
LOL   = 1
14
720p  = -2
15
x264  = 1
16
mkv   = -2
17
mp4   = 1
18
avi   = 1

+ 62 - 0
lib/CinePantufas/Priority.pm

@ -0,0 +1,62 @@
1
package CinePantufas::Priority;
2
3
use base qw(Exporter);
4
5
use CinePantufas::Setup;
6
7
our @EXPORT_OK = qw(
8
  priority
9
);
10
11
# using the defaults means getting the lower resolutions
12
# but way smaller files - faster to download
13
my %defaults   = (
14
  HDTV    => 1,
15
  LOL     => 1,
16
  '720p'  => -2,
17
  x264    => 1,
18
  mkv     => -1,
19
  mp4     => 1,
20
  avi     => 1,
21
);
22
my %priorities = (
23
);
24
my $priore;
25
26
sub priority {
27
  my $fname = shift;
28
29
  unless (keys %priorities) {
30
    load_priorities();
31
  }
32
33
  return 0 unless keys %priorities;
34
  unless ($priore) {
35
    $priore = join '|', keys %priorities;
36
    $priore = qr{($priore)}i;
37
  }
38
39
  my @priobits = $fname =~ m{$priore}g;
40
  my $priority = 0;
41
  $priority += $priorities{ $_ } || 0
42
    for @priobits;
43
44
  print STDERR "PRIO: $fname => $priority\n";
45
  return $priority;
46
}
47
48
sub load_priorities {
49
  unless (keys %priorities) {
50
    %priorities = CinePantufas::Setup->config('priorities');
51
52
    unless (keys %priorities) {
53
      %priorities = %defaults;
54
    }
55
  }
56
57
  return unless defined wantarray;
58
  return wantarray ? %priorities : \%priorities;
59
}
60
61
1;
62

+ 3 - 5
lib/CinePantufas/Source/EZTV.pm

@ -4,6 +4,7 @@ use strict;
4 4
use warnings;
5 5
6 6
use CinePantufas::Core;
7
use CinePantufas::Priority qw(priority);
7 8
8 9
use HTTP::Tiny;
9 10
@ -80,11 +81,8 @@ sub get_episode_list {
80 81
    $_ = "http:$_" for grep { substr($_,0,1) eq '/' } values %links;
81 82
  
82 83
    my $episode=($ses+0).'x'.sprintf('%02d', $epi);
83
    my @priobits  = $name =~ m{$prio}gi;
84
    my $rowprio = 0;
85
    for my $bit (@priobits) {
86
      $rowprio += $prio{$bit} || 0;
87
    }
84
    my $rowprio = priority($name);
85
    
88 86
    if (!$episodes{$episode} or $rowprio > $episodes{$episode}->{prio} ) {
89 87
      $episodes{$episode} = {
90 88
          filename  => $name,