use Method::Signatures::Simple;
use FindBin;
use HTML::Zoom;
+use HTML::Zoom::FilterBuilder::Template;
+use List::Util qw(first);
{
package App::IdiotBox::Announcement;
+ sub id { shift->{id} }
sub made_at { shift->{made_at} }
sub bucket { shift->{bucket} }
sub video_count { shift->{video_count} }
sub author { shift->{author} }
sub details { shift->{details} }
sub bucket { shift->{bucket} }
+ sub file_name {
+ (my $s = join(' ', @{+shift}{qw(author name)})) =~ s/ /-/g;
+ $s;
+ }
+ sub url_path {
+ join('/', $_[0]->bucket->slug, $_[0]->slug);
+ }
}
default_config(
template_dir => 'share/html',
store => 'SQLite',
db_file => 'var/lib/idiotbox.db',
+ base_url => 'http://localhost:3000/',
+ base_dir => do { use FindBin; $FindBin::Bin },
);
sub BUILD {
my $obj = $_;
sub {
$_->select('.bucket-name')->replace_content($obj->bucket->name)
+ ->select('.made-at')->replace_content($obj->made_at)
->select('.bucket-link')->set_attribute({
name => 'href', value => $obj->bucket->slug.'/'
})
}
method show_video ($video) {
+ my $video_file = first {
+ -e join('/', $self->config->{base_dir}, $_)
+ } map {
+ join('/', $video->bucket->slug, $video->slug, $video->file_name.".$_")
+ } qw(flv m4v);
$self->html_response(video => sub {
+ my $video_url =
+ $self->base_url
+ .$video_file;
+
$_->select('.video-name')->replace_content($video->name)
->select('.author-name')->replace_content($video->author)
->select('.bucket-link')->set_attribute(
)
->select('.bucket-name')->replace_content($video->bucket->name)
->select('.video-details')->replace_content($video->details)
+ ->select('script')->template_text_raw({ video_url => $video_url });
});
}
})->apply($selectors);
}
+method base_url {
+ $self->{base_url} ||= do {
+ (my $u = $self->config->{base_url}) =~ s/\/$//;
+ "${u}/";
+ }
+}
+
+method _run_cli {
+ unless (@ARGV == 1 && $ARGV[0] eq 'import') {
+ return $self->SUPER::_run_cli(@_);
+ }
+ $self->cli_import;
+}
+
+method _cli_usage {
+ "To import data into your idiotbox install, chdir into a directory\n".
+ "containing video files and run:\n".
+ "\n".
+ " $0 import\n".
+ "\n".
+ $self->SUPER::_cli_usage(@_);
+}
+
+method cli_import {
+ require App::IdiotBox::Importer;
+ App::IdiotBox::Importer->run($self);
+}
+
1;