#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2012 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------

package RPS::Import::GrooveShark::v3;

use strict;

use lib '/app/tools/common/lib';
use Common::Assert;

use lib '/app/tool/common/lib';
use Common::Country;

use lib '/app/tools/rps/lib';
use RPS::Import::ServiceMap;
use base 'RPS::Import::Importer';

sub _fieldMap {
    {
        labelName     => 'C',
        artistName    => 'D',
        upc           => 'G',
        albumName     => 'E',
        isrc          => 'H',
        trackName     => 'F',
        units         => 'J',
        price         => 'K',
        countryCode   => 'I',
        currencyCode  => 'L',
    }
}

sub _headerIdentifier { ( labelName => 'label' ) }

sub mediaType   { RPS::DB::Item::MediaType::kMediaTypeAudio }

sub formatType  { RPS::File::Sale::FORMAT_STREAM }

sub productType { RPS::File::Sale::TYPE_TRACK }

sub _preProcess {
    my $self = shift;
    my %args = @_;

    Log->info( "Starting _preProcess" );
    $self->SUPER::_preProcess(%args);

    my $fileName = $args{file}->OrigFileName();
    Log->info("original filename " . $fileName);

    if ($fileName =~ /(\d{4})_?(Q\d)/i)
    {
        $self->{_dateBegin} = join("-", $1, $2);
    }
}

sub _getDateBegin {
    my $self = shift;
    $self->fail( "SB Unable to determine date from file name" ) unless( $self->{_dateBegin} );
    return $self->{_dateBegin}
}

###
1;# Play nicely.
###
