From 0feded2e51b5d012d4525dd3bc3d330dd3ed67c5 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sun, 30 Nov 2014 01:03:32 +0200 Subject: [PATCH 1/1] Initial commit --- Changes | 4 ++ MANIFEST | 9 ++++ Makefile.PL | 28 ++++++++++ README | 29 +++++++++++ lib/Music/Tag/Coveralia.pm | 102 +++++++++++++++++++++++++++++++++++++ t/Music-Tag-Coveralia.t | 22 ++++++++ t/empty.flac | Bin 0 -> 505 bytes t/perlcritic.t | 10 ++++ t/perlcriticrc | 29 +++++++++++ 9 files changed, 233 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/Music/Tag/Coveralia.pm create mode 100644 t/Music-Tag-Coveralia.t create mode 100644 t/empty.flac create mode 100644 t/perlcritic.t create mode 100644 t/perlcriticrc diff --git a/Changes b/Changes new file mode 100644 index 0000000..e905e7a --- /dev/null +++ b/Changes @@ -0,0 +1,4 @@ +Revision history for Perl extension Music::Tag::Coveralia. + +0.000_001 2014-10-30T01:02+02:00 + - Initial release diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..97d6da8 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,9 @@ +Changes +Makefile.PL +MANIFEST +README +t/Music-Tag-Coveralia.t +t/empty.flac +t/perlcritic.t +t/perlcriticrc +lib/Music/Tag/Coveralia.pm diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..e26f950 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,28 @@ +use 5.014000; +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'Music::Tag::Coveralia', + VERSION_FROM => 'lib/Music/Tag/Coveralia.pm', + ABSTRACT_FROM => 'lib/Music/Tag/Coveralia.pm', + AUTHOR => 'Marius Gavrilescu ', + MIN_PERL_VERSION => '5.14.0', + LICENSE => 'perl', + BUILD_REQUIRES => { + qw/Test::RequiresInternet 0/, + }, + SIGN => 1, + PREREQ_PM => { + qw/Music::Tag 0 + Music::Tag::Generic 0 + LWP::Simple 0 + WWW::Search 0 + WWW::Search::Coveralia 0/, + }, + META_ADD => { + dynamic_config => 0, + resources => { + repository => 'http://git.ieval.ro/?p=music-tag-coveralia.git', + }, + } +); diff --git a/README b/README new file mode 100644 index 0000000..f56e504 --- /dev/null +++ b/README @@ -0,0 +1,29 @@ +Music-Tag-Coveralia version 0.000_001 +===================================== + +INSTALLATION + +To install this module type the following: + + perl Makefile.PL + make + make test + make install + +DEPENDENCIES + +This module requires these other modules and libraries: + +* Music::Tag +* WWW::Search +* WWW::Search::Coveralia + +COPYRIGHT AND LICENCE + +Copyright (C) 2014 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.20.1 or, +at your option, any later version of Perl 5 you may have available. + + diff --git a/lib/Music/Tag/Coveralia.pm b/lib/Music/Tag/Coveralia.pm new file mode 100644 index 0000000..6a23335 --- /dev/null +++ b/lib/Music/Tag/Coveralia.pm @@ -0,0 +1,102 @@ +package Music::Tag::Coveralia; + +use 5.014000; +use strict; +use warnings; +use parent qw/Music::Tag::Generic/; + +our $VERSION = '0.000_001'; + +use LWP::Simple qw/get/; +use WWW::Search; + +sub required_values { qw/album/ } +sub set_values { qw/picture/ } + +sub get_tag { + my ($self) = @_; + + my $album = $self->info->get_data('album'); + my $ws = WWW::Search->new('Coveralia::Albums'); + $self->status(1, "Searching coveralia for the album $album"); + $ws->native_query(WWW::Search::escape_query($album)); + while (my $res = $ws->next_result) { + $self->status(1, 'Found album ' . $res->title . ' by ' . $res->artist); + next if $self->info->has_data('artist') && $self->info->get_data('artist') ne $res->artist; + $self->status(0, 'Selected album ' . $res->title . ' by ' . $res->artist); + if ($res->cover('frontal')) { + $self->info->set_data(picture => {_Data => get $res->cover('frontal')}); + $self->tagchange('picture'); + } + last + } + + return $self->info +} + +1; +__END__ + +=encoding utf-8 + +=head1 NAME + +Music::Tag::Coveralia - Get cover art from coveralia.com + +=head1 SYNOPSIS + + use Music::Tag; + my $mt = Music::Tag->new($filename); + $mt->add_plugin('Coveralia'); + $mt->get_tag; + +=head1 DESCRIPTION + +This plugin gets cover art from L, based on album and (optionally) artist. + +=head1 REQUIRED DATA VALUES + +=over + +=item album + +Used as the search term. + +=back + +=head1 USED DATA VALUES + +=over + +=item artist + +If present, the first album found from this artist is chosen. Otherwise the first album found is chosen. + +=back + +=head1 SET DATA VALUES + +=over + +=item picture + +=back + +=head1 SEE ALSO + +L, L, L + +=head1 AUTHOR + +Marius Gavrilescu, Emarius@ieval.roE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2014 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.20.1 or, +at your option, any later version of Perl 5 you may have available. + + +=cut diff --git a/t/Music-Tag-Coveralia.t b/t/Music-Tag-Coveralia.t new file mode 100644 index 0000000..38c5efc --- /dev/null +++ b/t/Music-Tag-Coveralia.t @@ -0,0 +1,22 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use Test::RequiresInternet qw/www.coveralia.com 80/; +use Test::More tests => 3; +use Music::Tag traditional => 1; +BEGIN { use_ok('Music::Tag::Coveralia') }; + +sub test { + my ($artist, $album, $expect) = @_; + my $mt = Music::Tag->new('t/empty.flac', {$ENV{TEST_VERBOSE} ? (verbose => 1) : (quiet => 1)}); + $mt->artist($artist); + $mt->album($album); + $mt->add_plugin('Coveralia'); + $mt->get_tag; + my $exists = $expect ? 'exists' : 'does not exist'; + is $mt->has_data('picture'), $expect, "$artist - $album $exists" +} + +test 'Metallica', 'Ride The Lightning', 1; +test 'Metal', 'Ride The Lightning', 0; diff --git a/t/empty.flac b/t/empty.flac new file mode 100644 index 0000000000000000000000000000000000000000..fcac9d9dadbb7657dfa21c2f31b1365119102b60 GIT binary patch literal 505 zcmVKF2SgMjZDyK|7m44NdNeG z7ytrG+Drfv01N;W00saQ00ICIwQXY-E;e12n%nPDxh z3MiGNNzqe?m#Dt>Q3|w6-5tbBU#htxMRIy}ie-qh2@$Ue=US2}EQ&}%OK)UqX{eBr zkxI5}Scx@>GS;=G(^iy{X^JGMnOBs*?NK6-h^+lTsc9iZD(TnNKIN4)BC1fCMDsM> z;Xx=%Q%N^g)6yuEQp(na#wshzAtaJw;$&E&L|0lyScxSeQpCk6HB|~ODOjrJlIDs3 z@Bj_}`)RkFBJ4m1*K(yQs-&vAs--HWQtGNyq@_ygt4ftsOQ}_Is;NmLNg|3=Qj(;S zk|>oaRHZ2@wM&$gl1PY&B1s}dktCu?Qc9GiDN0g`N|cnjQq``cq@s~Tks?x+EhQvX zDN2$^l#)p$B&8`zQq@XIQb{C9NhFd=RZ6R?yZ^eb*Ii1fbty?wl#(ebRZ^0vB`HLu vN|ch4l_gZQREb3*L_|djNRcF>RVt}+lBE>2B$T8{Dyo$(QmU0osQ_m~81B!+ literal 0 HcmV?d00001 diff --git a/t/perlcritic.t b/t/perlcritic.t new file mode 100644 index 0000000..51bad9d --- /dev/null +++ b/t/perlcritic.t @@ -0,0 +1,10 @@ +#!/usr/bin/perl +use v5.14; +use warnings; + +use Test::More; + +BEGIN { plan skip_all => '$ENV{RELEASE_TESTING} is false' unless $ENV{RELEASE_TESTING} } +use Test::Perl::Critic -profile => 't/perlcriticrc'; + +all_critic_ok diff --git a/t/perlcriticrc b/t/perlcriticrc new file mode 100644 index 0000000..5973bef --- /dev/null +++ b/t/perlcriticrc @@ -0,0 +1,29 @@ +severity = 1 + +[-CodeLayout::RequireTidyCode] +[-ControlStructures::ProhibitPostfixControls] +[-ControlStructures::ProhibitUnlessBlocks] +[-Documentation::PodSpelling] +[-Documentation::RequirePodLinksIncludeText] +[-InputOutput::RequireBracedFileHandleWithPrint] +[-RegularExpressions::ProhibitEnumeratedClasses] +[-RegularExpressions::RequireLineBoundaryMatching] +[-Subroutines::RequireFinalReturn] +[-ValuesAndExpressions::ProhibitConstantPragma] +[-ValuesAndExpressions::ProhibitEmptyQuotes] +[-ValuesAndExpressions::ProhibitMagicNumbers] +[-ValuesAndExpressions::ProhibitNoisyQuotes] +[-Variables::ProhibitLocalVars] +[-Variables::ProhibitPackageVars] +[-Variables::ProhibitPunctuationVars] + +[RegularExpressions::RequireExtendedFormatting] +minimum_regex_length_to_complain_about = 20 + +[Documentation::RequirePodSections] +lib_sections = NAME | SYNOPSIS | DESCRIPTION | AUTHOR | COPYRIGHT AND LICENSE +script_sections = NAME | SYNOPSIS | DESCRIPTION | AUTHOR | COPYRIGHT AND LICENSE + +[Subroutines::RequireArgUnpacking] +short_subroutine_statements = 5 +allow_subscripts = 1 -- 2.30.2