[mb-commits] branch, mbs-3856-revert-barcode-search, created. MBS-3856: Add ./admin/RemoveBarcodeCoverArtUrls.pl.

MusicBrainz Git Server <[email protected]>
Newsgroups gmane.comp.audio.musicbrainz.cvs
Message-ID <E1Tg2i3-0005bX-RI@wiley>
The branch, mbs-3856-revert-barcode-search has been created
        at  97377244a61dc3d6136e45bcf4c95ce18b61b5d2 (commit)

- Log -----------------------------------------------------------------
commit 97377244a61dc3d6136e45bcf4c95ce18b61b5d2
Author: Johannes Weißl <[email protected]>
Date:   Wed Dec 5 01:02:02 2012 +0100

    MBS-3856: Add ./admin/RemoveBarcodeCoverArtUrls.pl.
    
    This script removes all cover art URLs from releases that were fetched
    using barcode.

diff --git a/admin/RemoveBarcodeCoverArtUrls.pl b/admin/RemoveBarcodeCoverArtUrls.pl
new file mode 100755
index 0000000..f610e5f
--- /dev/null
+++ b/admin/RemoveBarcodeCoverArtUrls.pl
@@ -0,0 +1,11 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+use DBDefs;
+
+use MooseX::Runnable::Run;
+run_application 'MusicBrainz::Script::RemoveBarcodeCoverArt', @ARGV;
diff --git a/lib/MusicBrainz/Script/RemoveBarcodeCoverArt.pm b/lib/MusicBrainz/Script/RemoveBarcodeCoverArt.pm
new file mode 100644
index 0000000..1341658
--- /dev/null
+++ b/lib/MusicBrainz/Script/RemoveBarcodeCoverArt.pm
@@ -0,0 +1,105 @@
+package MusicBrainz::Script::RemoveBarcodeCoverArt;
+use Moose;
+
+use DBDefs;
+use DateTime::Duration;
+use MusicBrainz::Server::Context;
+use MusicBrainz::Server::Log qw( log_debug log_notice );
+use MusicBrainz::Server::Data::Utils qw( placeholders query_to_list );
+
+with 'MooseX::Runnable';
+with 'MooseX::Getopt';
+with 'MusicBrainz::Script::Role::Context';
+
+has 'max_run_time' => (
+    isa      => 'DateTime::Duration',
+    is       => 'ro',
+    required => 1,
+    traits   => [ 'NoGetopt' ],
+    default  => sub { DateTime::Duration->new( minutes => 10 ) }
+);
+
+sub find_releases
+{
+    my ($self) = @_;
+
+    my @url_types = $self->handled_types;
+
+    my $query = '
+        SELECT DISTINCT ON (release.id)
+            release.id AS r_id
+        FROM release
+        LEFT JOIN release_coverart ON release.id = release_coverart.id
+        LEFT JOIN l_release_url l ON ( l.entity0 = release.id )
+        LEFT JOIN link ON ( link.id = l.link )
+        LEFT JOIN link_type ON (
+          link_type.id = link.link_type AND
+          link_type.name IN (' . placeholders(@url_types) . ')
+        )
+        LEFT JOIN url ON ( url.id = l.entity1 )
+        WHERE link_type.name IS NULL AND release.barcode IS NOT NULL
+        AND release_coverart.cover_art_url IS NOT NULL
+        ORDER BY release.id';
+
+    return query_to_list($self->c->sql, sub {
+        my $row = shift;
+        return sub {
+            my $release = $self->c->model('Release')->_new_from_row($row, 'r_');
+            $release->cover_art(
+                MusicBrainz::Server::CoverArt->new()
+            );
+            return $release;
+        }
+    }, $query, @url_types);
+}
+
+sub run
+{
+    my $self = shift;
+
+    my @releases = find_releases($self->c->model('CoverArt'));
+
+    my $completed = 0;
+    my $total = @releases;
+    my $started_at = DateTime->now;
+
+    my %seen;
+
+    my ($seen, $removed);
+
+    while (DateTime::Duration->compare(DateTime->now() - $started_at, $self->max_run_time) == -1 &&
+               (my $release = shift @releases))
+    {
+        $release = $release->();
+        next if $seen{$release->id};
+
+        $seen++;
+
+        $self->sql->begin;
+        $self->c->model('CoverArt')->cache_cover_art($release);
+        $self->sql->commit;
+
+        log_debug { sprintf "Cover art removed for %d", $release->id };
+        $removed++;
+
+        $seen{$release->id} = 1;
+        if ($completed++ % 10 == 0) {
+            printf STDERR "%d/%d\r", $completed, $total;
+        }
+    }
+    $self->sql->finish;
+
+    log_notice {
+        sprintf "Examined %d (%.2f%%) releases, removed %d cover art urls.",
+                $seen,
+                ($seen / $total) * 100,
+                $removed
+        };
+
+    return 0;
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;

commit 1f10fee78e1f33beb693e560da8b6cc30d8c629e
Author: Johannes Weißl <[email protected]>
Date:   Sat Jun 23 12:46:06 2012 +0200

    MBS-3856: Revert MBS-1052 "Amazon should lookup cover art by barcode too"
    
    This partly reverts 609f1cb and ea96414.

diff --git a/lib/MusicBrainz/Server/CoverArt/BarcodeSearch.pm b/lib/MusicBrainz/Server/CoverArt/BarcodeSearch.pm
deleted file mode 100644
index b97a067..0000000
--- a/lib/MusicBrainz/Server/CoverArt/BarcodeSearch.pm
+++ /dev/null
@@ -1,7 +0,0 @@
-package MusicBrainz::Server::CoverArt::BarcodeSearch;
-use Moose::Role;
-use namespace::autoclean;
-
-requires 'search_by_barcode';
-
-1;
diff --git a/lib/MusicBrainz/Server/CoverArt/Provider/WebService/Amazon.pm b/lib/MusicBrainz/Server/CoverArt/Provider/WebService/Amazon.pm
index 9678357..9d4be92 100644
--- a/lib/MusicBrainz/Server/CoverArt/Provider/WebService/Amazon.pm
+++ b/lib/MusicBrainz/Server/CoverArt/Provider/WebService/Amazon.pm
@@ -12,7 +12,6 @@ use aliased 'MusicBrainz::Server::CoverArt::Amazon' => 'CoverArt';
 use MusicBrainz::Server::Log qw( log_error );
 
 extends 'MusicBrainz::Server::CoverArt::Provider';
-with 'MusicBrainz::Server::CoverArt::BarcodeSearch';
 
 has '+link_type_name' => (
     default => 'amazon asin',
@@ -90,23 +89,6 @@ sub lookup_cover_art
     return $cover_art;
 }
 
-sub search_by_barcode
-{
-    my ($self, $release) = @_;
-
-    return unless $release->barcode and $release->barcode != 0;
-
-    my $url = "http://ecs.amazonaws.com/onca/xml?" .
-                  "Service=AWSECommerceService&" .
-                  "Operation=ItemLookup&" .
-                  "ResponseGroup=Images&" .
-                  "IdType=" . $release->barcode->type . "&" .
-                  "SearchIndex=Music&" .
-                  "ItemId=" . $release->barcode;
-
-    return $self->_lookup_coverart($url);
-}
-
 sub _lookup_coverart {
     my ($self, $url) = @_;
 
diff --git a/lib/MusicBrainz/Server/Data/CoverArt.pm b/lib/MusicBrainz/Server/Data/CoverArt.pm
index 65a8c2e..34b249b 100644
--- a/lib/MusicBrainz/Server/Data/CoverArt.pm
+++ b/lib/MusicBrainz/Server/Data/CoverArt.pm
@@ -151,13 +151,6 @@ sub load
             $release->cover_art($cover_art);
             last;
         }
-
-        unless ($release->has_cover_art) {
-            my $cover_art = $self->parse_from_release($release)
-                or next;
-
-            $release->cover_art($cover_art);
-        }
     }
 }
 
@@ -168,10 +161,10 @@ sub find_outdated_releases
     my @url_types = $self->handled_types;
 
     my $query = '
-    SELECT r_id, r_barcode, url, link_type, last_updated AS c_last_updated
+    SELECT r_id, url, link_type, last_updated AS c_last_updated
     FROM (
         SELECT DISTINCT ON (release.id)
-            release.id AS r_id, release.barcode AS r_barcode,
+            release.id AS r_id,
             url.url, link_type.name AS link_type,
             release_coverart.last_updated,
             CASE '.
@@ -197,14 +190,10 @@ sub find_outdated_releases
             SELECT id FROM release_coverart
             WHERE
                last_updated IS NULL OR NOW() - last_updated > ?
-        ) AND (
-            link_type.name IS NOT NULL OR
-            release.barcode IS NOT NULL
-        )
+        ) AND link_type.name IS NOT NULL
         ORDER BY release.id,
                  _sort_order DESC NULLS LAST,
-                 l.last_updated DESC,
-                 release.barcode NULLS LAST
+                 l.last_updated DESC
     ) s
     ORDER BY last_updated ASC';
 
@@ -220,15 +209,16 @@ sub find_outdated_releases
                 )
             );
 
-            if ($row->{link_type}) {
-                $release->add_relationship(
-                    Relationship->new(
-                        entity0 => $release,
-                        entity1 => $self->c->model('URL')->_new_from_row($row),
-                        link => Link->new(
-                            type => LinkType->new( name => $row->{link_type} )
-                        )))
-            }
+            $release->add_relationship(
+                Relationship->new(
+                    entity0 => $release,
+                    entity1 => $self->c->model('URL')->_new_from_row($row),
+                    link => Link->new(
+                        type => LinkType->new( name => $row->{link_type} )
+                    )
+                )
+            );
+
             return $release;
         }
     }, $query, @url_types, $pg_date_formatter->format_duration($since));
@@ -246,8 +236,6 @@ sub cache_cover_art
         );
     }
 
-    $cover_art ||= $self->parse_from_release($release);
-
     my $cover_update = {
         last_updated => DateTime->now,
         cover_art_url  => $cover_art ? $cover_art->image_uri : undef
@@ -278,21 +266,6 @@ sub parse_from_type_url
     return $cover_art;
 }
 
-sub parse_from_release
-{
-    my ($self, $release) = @_;
-    return unless $release->barcode;
-
-    for my $provider (@{ $self->providers }) {
-        next unless $provider->does('MusicBrainz::Server::CoverArt::BarcodeSearch');
-
-        my $cover_art = $provider->search_by_barcode($release)
-            or next;
-
-        return $cover_art;
-    }
-}
-
 sub url_updated {
     my ($self, $url_id) = @_;
     my @release_ids = @{
diff --git a/t/lib/t/MusicBrainz/Server/Data/CoverArt.pm b/t/lib/t/MusicBrainz/Server/Data/CoverArt.pm
index 9bc0f5b..886aa19 100644
--- a/t/lib/t/MusicBrainz/Server/Data/CoverArt.pm
+++ b/t/lib/t/MusicBrainz/Server/Data/CoverArt.pm
@@ -75,19 +75,6 @@ test 'Handles Amazon ASINs for downloads' => sub {
 
 };
 
-test 'Searching Amazon by barcode' => sub {
-    plan skip_all => 'Testing Amazon barcode searches requires the AWS_PUBLIC and AWS_PRIVATE configuration variables to be set'
-        unless DBDefs->AWS_PUBLIC() && DBDefs->AWS_PRIVATE();
-
-    my $test = shift;
-
-    my $release = Release->new( name => 'Symmetry', barcode => '5060157037002' );
-
-    $test->c->model('CoverArt')->load($release);
-    ok($release->has_cover_art);
-    ok($test->ua->get($release->cover_art->image_uri)->is_success);
-};
-
 test 'Check cover art provider regular expression matching' => sub {
     my $test = shift;
     my $c = $test->c;

-----------------------------------------------------------------------


hooks/post-receive
-- 
mb_server

_______________________________________________
MusicBrainz-commits mailing list
[email protected]
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-commits
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.