X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/04fed8e4657d28df3ca947ea34c2a5d8f9ccc02f..61d7dd11d4a450a64f2817ee4db0ec7fa5880b42:/bin/old/addName.pl?ds=inline diff --git a/bin/old/addName.pl b/bin/old/addName.pl new file mode 100755 index 0000000..c5a8069 --- /dev/null +++ b/bin/old/addName.pl @@ -0,0 +1,59 @@ +#! /usr/bin/perl + +use warnings; +use strict; +# getopts module +use Getopt::Std; +# getstore madule +use LWP::Simple; +# Curent Working Directory module +use Cwd; + +# eguides URL +my $url = 'http://epguides.com'; + +# get options +our($opt_n); +getopts('n') or die; # sets opt_n to true if -n is given + #+or dies when options are unknown + +my $cwd = getcwd(); +my $path = 'tmp'; + +print $cwd . "\n"; + +$cwd =~ /.*\/(.*) (?:\[.*\])*\/Season (\d+)/; +print $1 . " " . $2 . "\n"; +my $file = $1; + + +getstore( "$url/$file", $path); + +open FILE, $path or die $!; +my @lines = ; +close FILE; +unlink($path); + + +my @old_file_names = <*>; + +foreach my $old_file_name (@old_file_names) { +# print $old_file_name . "\n"; + if ($old_file_name =~ /0?(?\d+).*?0?(?\d+)/) { +# print $+{episode} . "\n"; + my $episode = length($+{episode}) == 1 ? '0' . $+{episode} : $+{episode}; + my $pattern = '(0?'.$+{season}.')-([0 ]?'.$+{episode}.').*>(.*) *<\/a>'; + foreach my $line (@lines) { + if ($line =~ /$pattern/) { + my $new_file_name = $1 . "x" . $episode . " " .$3 . ".avi"; +# print "pattern -> " . $pattern . "\n"; + if ($opt_n) { + print $old_file_name . " -> " . $new_file_name . "\n"; + } else { + rename($old_file_name, $new_file_name); + } + last; + } + } + } +}