package App::IdiotBox;
+use App::IdiotBox::Common qw(@SupportedFormats);
use Web::Simple __PACKAGE__;
use FindBin;
use HTML::Zoom;
-e join('/', $self->config->{base_dir}, $_)
} map {
join('/', $video->bucket->slug, $video->slug, $video->file_name.".$_")
- } qw(flv m4v);
+ } @SupportedFormats;
$self->html_response(video => sub {
my $video_url =
$self->base_url
use strict;
use warnings FATAL => 'all';
+use App::IdiotBox::Common qw(@SupportedFormats);
use Cwd;
use IO::All;
use ExtUtils::MakeMaker qw(prompt);
use File::Spec::Functions qw(catfile catdir);
use POSIX qw(strftime);
+my $supported_formats_re = join('|', @SupportedFormats);
+
sub log_info (&) { print $_[0]->(), "\n"; }
sub run {
my ($class, $dir) = @_;
my %videos;
foreach my $file (io($dir)->all_files) {
- $file->filename =~ /^([^\.]+)\.([^\.]+)$/ or next;
+ $file->filename =~ /^([^\.]+)\.($supported_formats_re)$/ or next;
push(@{$videos{$1}||=[]}, $2);
}
\%videos;
--- /dev/null
+use strict;
+use warnings FATAL => 'all';
+use autodie;
+
+use Test::More;
+
+use Cwd qw(getcwd);
+use File::Temp qw(tempdir);
+
+# Chdir to test directory for laziness
+my $original_dir = getcwd;
+END {
+ chdir $original_dir;
+}
+
+my $temp_dir = tempdir(CLEANUP => 1);
+chdir($temp_dir);
+
+use App::IdiotBox::Importer;
+
+my $method = 'video_files_from_dir';
+
+# No videos
+my $videos = App::IdiotBox::Importer->$method($temp_dir);
+is_deeply($videos, {}, 'No files reported from empty directory');
+
+# Unknown extensions
+open(undef, '>', 'fake.mp3');
+open(undef, '>', 'fake2.aac');
+
+$videos = App::IdiotBox::Importer->$method($temp_dir);
+is_deeply($videos, {}, 'No files reported from empty directory');
+
+# Known file types
+open(undef, '>', 'good.m4v');
+open(undef, '>', 'good2.flv');
+
+my $expect = {
+ 'good' => [ 'm4v' ],
+ 'good2' => [ 'flv' ],
+};
+
+$videos = App::IdiotBox::Importer->$method($temp_dir);
+is_deeply($videos, $expect, 'Known filetypes detected');
+
+# Grouping by file name without extension
+open(undef, '>', 'good.flv');
+
+unshift @{ $expect->{good} }, 'flv';
+
+$videos = App::IdiotBox::Importer->$method($temp_dir);
+is_deeply($videos, $expect, 'Known filetypes detected');
+
+done_testing;