App-Plex-Archiver

 view release on metacpan or  search on metacpan

bin/plex-archiver  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;
use v5.10;
use Getopt::Long qw( :config no_ignore_case bundling );
use Pod::Usage;
use File::Path qw( make_path );
use File::Spec qw( catfile );
use File::HomeDir;
use File::Find;
use TMDB;
use Data::Dumper;
use App::Plex::Archiver qw( title_from_filename copy_file get_tmbd_api_key get_tmdb_info );


use Readonly;
use IO::Prompter;

Readonly my %MEDIA_EXT => map { $_ => 1 } qw( mp4 avi mkv mov );


sub ask_yes_or_no { prompt(-yn, @_); }  ## no critic (Subroutines::RequireArgUnpacking)
sub get_input     { prompt((shift // ""), -prefill => (shift // "")); }










#------------------------------------------------------------------------------
# MAIN
#------------------------------------------------------------------------------

#----------------------------
# Command line options
#----------------------------
my $source_dir;
my $destination_dir;
my $help    = 0;
my $man     = 0;
my $debug   = 0;
my $move    = 0;
my $dry_run = 0;
my $api_key_filename = "";

GetOptions(
    'source-dir|s=s'    => \$source_dir,
    'destination-d|d=s' => \$destination_dir,
    'help|h|?'          => \$help,
    'move|M+'           => \$move,
    'man|m'             => \$man,
    'debug|D+'          => \$debug,
    'dry-run|n+'        => \$dry_run,
    'api-key|a=s'
) or pod2usage(2);

print("Debug level is '$debug'\n") if ($debug);

pod2usage(1) if $help;
pod2usage(-exitval => 0, -verbose => 2) if $man;

#----------------------------
# Make sure directories exist
#----------------------------

unless ($source_dir && $destination_dir) {
    print("Error: Both --source-dir and --destination-dir are required.\n\n");
    pod2usage(1);
}

unless (-d "$source_dir") {
  print("Error: '$source_dir' must be an existing directory.\n\n");
  pod2usage(1);
}

unless (-d "$destination_dir") {
  my $create_dest = ask_yes_or_no("Destination directory '$destination_dir' does not exist. Do you wish to create it? ");
  if ($create_dest) {
    printf("Creating desitnation directory '%s'...", $destination_dir);



( run in 0.873 second using v1.01-cache-2.11-cpan-6aa56a78535 )