Commit 4fbe45ce authored by Joakim Nylén's avatar Joakim Nylén

Changes

parent e82d69a8
......@@ -614,6 +614,55 @@ sub LookupCountry {
}
sub LookupLeague {
my $self = shift;
my ( $type, $org ) = @_;
return ( undef, undef ) if ( not defined($org) ) or ( $org !~ /\S/ );
$org =~ s/^\s+//;
$org =~ s/\s+$//;
# I should be using locales, but I don't dare turn them on.
$org = lc($org);
$org =~ tr/ÅÄÖ/åäö/;
# The field has room for 50 characters. Unicode may occupy
# several bytes with one character.
# Treat all leagues with the same X character prefix
# as equal.
$org = substr( $org, 0, 44 );
$self->LoadLeagues()
if not exists( $self->{leagues} );
if ( not exists( $self->{leagues}->{"$type++$org"} ) ) {
# MySQL considers some characters as equal, e.g. e and é.
# Trying to insert both anime and animé will give an error-message
# from MySql. Therefore, I try to lookup the new entry before adding
# it to see if MySQL thinks it already exists. I should probably
# normalize the strings before inserting them instead...
my $data =
$self->{sa}->Lookup( "trans_leagues", { type => $type, original => $org } );
if ( defined($data) ) {
$self->{leagues}->{ $type . "++" . $org } =
[ $data->{real_name}, $data->{game} ];
}
else {
$self->AddLeague( $type, $org );
}
}
if ( defined( $self->{leagues}->{"$type++$org"} ) ) {
return @{ ( $self->{leagues}->{"$type++$org"} ) };
}
else {
return ( undef, undef );
}
}
=item Reset
Reset the datastore-object to its initial state. This method can be called
......@@ -737,6 +786,41 @@ sub AddCountry {
$self->{countries}->{"$type++$org"} = [ undef, undef ];
}
sub LoadLeagues {
my $self = shift;
my $d = {};
my $sth = $self->{sa}->Iterate( 'trans_leagues', {} );
if ( not defined($sth) ) {
$self->{leagues} = {};
w "No leagues found in database.";
return;
}
while ( my $data = $sth->fetchrow_hashref() ) {
$d->{ $data->{type} . "++" . $data->{original} } =
[ $data->{real_name}, $data->{game} ];
}
$sth->finish();
$self->{leagues} = $d;
}
sub AddLeague {
my $self = shift;
my ( $type, $org ) = @_;
$self->{sa}->Add(
'trans_leagues',
{
type => $type,
original => $org
}
);
$self->{leagues}->{"$type++$org"} = [ undef, undef ];
}
=item sa
Returns the SQLAbstraction object to give direct access to the database.
......
......@@ -584,42 +584,42 @@ sub WriteEntry
$d->{video}->{quality} = $entry->{quality};
}
if( $entry->{directors} =~ /\S/ )
if( defined($entry->{directors}) and $entry->{directors} =~ /\S/ )
{
$d->{credits}->{director} = [split( ";", $entry->{directors})];
}
if( $entry->{actors} =~ /\S/ )
if( deefined($entry->{actors}) and $entry->{actors} =~ /\S/ )
{
$d->{credits}->{actor} = [split( ";", $entry->{actors})];
}
if( $entry->{writers} =~ /\S/ )
if( defined($entry->{writers}) and $entry->{writers} =~ /\S/ )
{
$d->{credits}->{writer} = [split( ";", $entry->{writers})];
}
if( $entry->{adapters} =~ /\S/ )
if( defined($entry->{adapters}) and $entry->{adapters} =~ /\S/ )
{
$d->{credits}->{adapter} = [split( ";", $entry->{adapters})];
}
if( $entry->{producers} =~ /\S/ )
if( defined($entry->{producers}) and $entry->{producers} =~ /\S/ )
{
$d->{credits}->{producer} = [split( ";", $entry->{producers})];
}
if( $entry->{presenters} =~ /\S/ )
if( defined($entry->{presenters}) and $entry->{presenters} =~ /\S/ )
{
$d->{credits}->{presenter} = [split( ";", $entry->{presenters})];
}
if( $entry->{commentators} =~ /\S/ )
if( defined($entry->{commentators}) and $entry->{commentators} =~ /\S/ )
{
$d->{credits}->{commentator} = [split( ";", $entry->{commentators})];
}
if( $entry->{guests} =~ /\S/ )
if( defined($entry->{guests}) and $entry->{guests} =~ /\S/ )
{
$d->{credits}->{guest} = [split( ";", $entry->{guests})];
}
......
......@@ -215,7 +215,7 @@ sub _check_status {
};
if ( $ok and $code and $message ) {
carp sprintf( 'TMDB API Error (%s): %s', $code, $message );
carp sprintf( 'TMDB API Error (%s): %s', $code, $message ) unless $code eq 34;
# 34 = Not Found (return 1 to not retry)
if($code eq "34" or $code eq 34) {
......@@ -226,7 +226,7 @@ sub _check_status {
if($code eq "25" or $code eq 25) {
# Sleep for x amount of seconds
# Travis: "We increased the rate limit to 40 requests every 10 seconds too, so there's a little bump."
carp("TMDB API RATE LIMIT: Sleeping for 10 seconds..");
#carp("TMDB API RATE LIMIT: Sleeping for 10 seconds..");
}
}
} ## end if ( $response->{content...})
......
......@@ -193,8 +193,10 @@ sub getConf {
sub _download {
my ($self, $fmt, $url, @parm) = @_;
my $url2= $url;
# Make URL
$url = sprintf($fmt, $url, @parm);
$url = sprintf($fmt, $url2, @parm);
#$url =~ s/\$/%24/g;
$url =~ s/#/%23/g;
......
......@@ -13,7 +13,7 @@ package UTF8DBI; use base 'DBI';
sub _utf8_ {
if (ref $_ eq 'ARRAY') {_utf8_() foreach @$_ }
elsif (ref $_ eq 'HASH' ) {_utf8_() foreach values %$_ }
else {
else {
Encode::_utf8_on($_);
$_ = '⁂malformed-UTF8‼' #die "Malformed utf8 string in database"
if (Encode::is_utf8($_) && ! Encode::is_utf8($_, 1));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment