App-DrivePlayer

 view release on metacpan or  search on metacpan

lib/App/DrivePlayer/Scanner.pm  view on Meta::CPAN

package App::DrivePlayer::Scanner;

use App::DrivePlayer::Setup;
use Encode qw( decode_utf8 is_utf8 );

my $FOLDER_MIME  = 'application/vnd.google-apps.folder';
my $DRIVE_FIELDS = 'files(id,name,mimeType,size,modifiedTime,parents,videoMediaMetadata)';

# Google::RestApi returns HTTP bodies as raw UTF-8 byte strings (no utf8
# flag). Passing those directly to DBIx::Class with sqlite_unicode=1 causes
# double-encoding: each byte is re-encoded as if it were Latin-1. Decode
# once at the boundary so the rest of the code sees proper Unicode.
sub _u8 {
    my ($s) = @_;
    return $s unless defined $s && length $s && !is_utf8($s);
    my $d = eval { decode_utf8($s, Encode::FB_CROAK) };
    return $@ ? $s : $d;
}

Readonly my $LARGE_DELETION_THRESHOLD => 10;

lib/App/DrivePlayer/Schema.pm  view on Meta::CPAN

__PACKAGE__->load_namespaces();

# Connect to a SQLite database at $path, configure pragmas, and deploy
# the schema if the tables do not yet exist.
sub connect_and_deploy {
    my ($class, $path) = @_;

    my $schema = $class->connect(
        "dbi:SQLite:dbname=$path", '', '',
        {
            sqlite_unicode => 1,
            on_connect_do  => [
                'PRAGMA journal_mode=WAL',
                'PRAGMA foreign_keys=ON',
            ],
        },
    );

    # Deploy only when the database is new (tracks table absent)
    my $dbh    = $schema->storage->dbh;
    my @tables = $dbh->tables(undef, undef, 'tracks', 'TABLE');



( run in 0.728 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )