Skip to content

Commit

Permalink
Copy 7.6/branches/lms to 7.7/trunk. Yuck, we need to switch to git ASAP
Browse files Browse the repository at this point in the history
git-svn-id: file:///home/awy/mirror/slim/7.7/trunk/server@32887 62299810-d8cb-41fd-93b7-d32162e5a4a4
  • Loading branch information
Andy Grundman committed Jul 26, 2011
1 parent 5f40c78 commit da0a8ab
Show file tree
Hide file tree
Showing 501 changed files with 21,435 additions and 2,572 deletions.
155 changes: 155 additions & 0 deletions CPAN/Media/Scan.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package Media::Scan;

use strict;
use base qw(Exporter);

use Media::Scan::Audio;
use Media::Scan::Image;
use Media::Scan::Error;
use Media::Scan::Progress;
use Media::Scan::Video;

# Log levels
use constant MS_LOG_ERR => 1;
use constant MS_LOG_WARN => 2;
use constant MS_LOG_INFO => 3;
use constant MS_LOG_DEBUG => 4;
use constant MS_LOG_MEMORY => 9;

# Flags
use constant MS_USE_EXTENSION => 1;
use constant MS_FULL_SCAN => 1 << 1;
use constant MS_RESCAN => 1 << 2;
use constant MS_INCLUDE_DELETED => 1 << 3;
use constant MS_WATCH_CHANGES => 1 << 4;
use constant MS_CLEARDB => 1 << 5;

our $VERSION = '0.01';

our @EXPORT = qw(
MS_LOG_ERR MS_LOG_WARN MS_LOG_INFO MS_LOG_DEBUG MS_LOG_MEMORY
MS_USE_EXTENSION MS_FULL_SCAN MS_RESCAN MS_INCLUDE_DELETED
MS_WATCH_CHANGES MS_CLEARDB
);

require XSLoader;
XSLoader::load('Media::Scan', $VERSION);

=head2 new( \@paths, \%options )
Create a new Media::Scan instance and begin scanning.
paths may be a single scalar path, or an array reference with multiple paths.
options include:
=over 4
=item loglevel (default: MS_LOG_ERR)
One of the following levels:
MS_LOG_ERR
MS_LOG_WARN
MS_LOG_INFO
MS_LOG_DEBUG
MS_LOG_MEMORY
=item async (default: 0)
If set to 1, all scanning is performed in a background thread, and the call to new() will
return immediately. Make sure to keep a reference to the Media::Scan object, or
the scan will be aborted at DESTROY-time.
=item cachedir (default: current dir)
An optional path for libmediascan to store some cache files.
=item flags (default: MS_USE_EXTENSION | MS_FULL_SCAN)
An OR'ed list of flags, the possible flags are:
MS_USE_EXTENSION - Use a file's extension to determine how to scan it.
MS_FULL_SCAN - Perform a full scan on every file.
MS_RESCAN - Only scan files that are new or have changed since the last scan.
MS_INCLUDE_DELETED - The result callback will be called for files that have been deleted
since the last scan.
MS_WATCH_CHANGES - Continue watching for changes after the scan has completed.
MS_CLEARDB - Wipe the internal libmediascan database before scanning.
=item ignore (default: none)
An array reference of file extensions that should be skipped. You may also specify 3 special types:
AUDIO - Ignore all audio files.
IMAGE - Ignore all image files.
VIDEO - Ignore all video files.
=item thumbnails (default: none)
An arrayref of hashes with one or more thumbnail specifications. Thumbnails are created during the
scanning process and are available within the result callback.
The format of a thumbnail spec is:
{ format => 'AUTO', # or JPEG or PNG
width => 100,
height => 100,
keep_aspect => 1,
bgcolor => 0xffffff,
quality => 90,
}
Most values are optional, however at least width or height must be specified.
=item on_result
A callback that will be called for each scanned file. The function will be passed
a L<Media::Scan::Audio>, L<Media::Scan::Video>, or L<Media::Scan::Image> depending on the
file type. This callback is required.
=item on_error
An callback that will be called when a scanning error occurs. It is passed a
L<Media::Scan::Error>.
=item on_progress
An optional callback that will be passed a L<Media::Scan::Progress> at regular intervals
during scanning.
=item on_finish
An optional callback that is called when scanning has finished. Nothing is currently passed
to this callback, eventually a scanning summary and overall stats might be included here.
=cut

sub new {
my ( $class, $paths, $opts ) = @_;

if ( ref $paths ne 'ARRAY' ) {
$paths = [ $paths ];
}

$opts->{loglevel} ||= MS_LOG_ERR;
$opts->{async} ||= 0;
$opts->{flags} ||= MS_USE_EXTENSION | MS_FULL_SCAN;
$opts->{paths} = $paths;
$opts->{ignore} ||= [];
$opts->{thumbnails} ||= [];

if ( ref $opts->{ignore} ne 'ARRAY' ) {
die "ignore must be an array reference";
}

my $self = bless $opts, $class;

$self->xs_new();

$self->xs_scan();

return $self;
}

1;
8 changes: 8 additions & 0 deletions CPAN/Media/Scan/Audio.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package Media::Scan::Audio;

use strict;
use base qw(Media::Scan::Result);

# Implementation is in xs/Audio.xs and xs/Result.xs

1;
18 changes: 18 additions & 0 deletions CPAN/Media/Scan/Error.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package Media::Scan::Error;

use strict;

# Implementation is in xs/Error.xs

sub as_hash {
my $self = shift;

return {
error_code => $self->error_code,
averror => $self->averror,
path => $self->path,
error_string => $self->error_string,
};
}

1;
19 changes: 19 additions & 0 deletions CPAN/Media/Scan/Image.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Media::Scan::Image;

use strict;
use base qw(Media::Scan::Result);

# Implementation is in xs/Image.xs and xs/Result.xs

sub as_hash {
my $self = shift;

return {
%{ $self->SUPER::as_hash() },
codec => $self->codec,
width => $self->width,
height => $self->height,
};
}

1;
20 changes: 20 additions & 0 deletions CPAN/Media/Scan/Progress.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Media::Scan::Progress;

use strict;

# Implementation is in xs/Progress.xs

sub as_hash {
my $self = shift;

return {
phase => $self->phase,
cur_item => $self->cur_item,
total => $self->total,
done => $self->done,
eta => $self->eta,
rate => $self->rate,
};
}

1;
24 changes: 24 additions & 0 deletions CPAN/Media/Scan/Result.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Media::Scan::Result;

use strict;

# Implementation is in xs/Result.xs

sub as_hash {
my $self = shift;

return {
type => $self->type,
path => $self->path,
mime_type => $self->mime_type,
dlna_profile => $self->dlna_profile,
size => $self->size,
mtime => $self->mtime,
bitrate => $self->bitrate,
duration_ms => $self->duration_ms,
hash => $self->hash,
thumbnails => $self->thumbnails,
};
}

1;
20 changes: 20 additions & 0 deletions CPAN/Media/Scan/Video.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Media::Scan::Video;

use strict;
use base qw(Media::Scan::Result);

# Implementation is in xs/Video.xs and xs/Result.xs

sub as_hash {
my $self = shift;

return {
%{ $self->SUPER::as_hash() },
codec => $self->codec,
width => $self->width,
height => $self->height,
fps => $self->fps,
};
}

1;
Loading

0 comments on commit da0a8ab

Please sign in to comment.